# HG changeset patch # User Dan # Date 1245110998 14400 # Node ID 5a282dbf8fad7c47b1a8369eeb82d82f88e76f06 # Parent 5990ac411f34148b0ab7d347e64a98bf8c2839e8 Added support for preloading javascript libs ($template->preload_js()). Updated admin theme and Tigra Tree Menu to support this + JS_{HEADER,FOOTER} variables. diff -r 5990ac411f34 -r 5a282dbf8fad includes/clientside/static/admin-menu.js --- a/includes/clientside/static/admin-menu.js Fri Jun 05 22:09:42 2009 -0400 +++ b/includes/clientside/static/admin-menu.js Mon Jun 15 20:09:58 2009 -0400 @@ -40,7 +40,7 @@ var ck = 0; } -function tree (a_items, a_template) { +function tree (a_items, a_template, s_target) { this.a_tpl = a_template; this.a_config = a_items; @@ -77,8 +77,12 @@ this.n_id = trees.length; trees[this.n_id] = this; - for (var i = 0; i < this.a_children.length; i++) { - document.write(this.a_children[i].init()); + for (var i = 0; i < this.a_children.length; i++) + { + if ( s_target ) + document.getElementById(s_target).innerHTML += this.a_children[i].init(); + else + document.write(this.a_children[i].init()); this.a_children[i].open(false, true); } } diff -r 5990ac411f34 -r 5a282dbf8fad includes/clientside/static/enano-lib-basic.js --- a/includes/clientside/static/enano-lib-basic.js Fri Jun 05 22:09:42 2009 -0400 +++ b/includes/clientside/static/enano-lib-basic.js Mon Jun 15 20:09:58 2009 -0400 @@ -210,6 +210,7 @@ _f(e); } } + onload_hooks = null; } var enano_hooks = {}; diff -r 5990ac411f34 -r 5a282dbf8fad includes/template.php --- a/includes/template.php Fri Jun 05 22:09:42 2009 -0400 +++ b/includes/template.php Mon Jun 15 20:09:58 2009 -0400 @@ -21,6 +21,7 @@ var $elements = false; var $page_id = false; var $namespace = false; + var $js_preload = array(); /** * Page action conditions @@ -438,6 +439,30 @@ } /** + * Queue a Javascript file to be loaded with the page instead of on demand. + * @param mixed Javascript file string or array thereof, extensions are optional + * @example + + $template->preload_js(array('jquery', 'jquery-ui')); + $template->preload_js('admin-menu.js'); + + * @return null + */ + + function preload_js($filemixed) + { + if ( is_string($filemixed) ) + $files = array($filemixed); + else if ( is_array($filemixed) ) + $files = $filemixed; + else + // :-/ + return null; + + $this->js_preload = array_values(array_merge($this->js_preload, $files)); + } + + /** * Global, only-called-once init. Goes to all themes. */ @@ -516,8 +541,40 @@ if ( getConfig('cdn_path') ) { // we're on a CDN, point to static includes - // probably should have a way to compress stuff like this before uploading to CDN + // CLI javascript compression script: includes/clientside/jscompress.php $js_head = ''; + + if ( !empty($this->js_preload) ) + { + $loadlines = array(); + + // make unique + foreach ( $this->js_preload as &$script ) + { + $script = preg_replace('/\.js$/', '', $script) . '.js'; + } + $this->js_preload = array_unique($this->js_preload); + + foreach ( $this->js_preload as $script ) + { + $js_head .= "\n "; + // special case for l10n: also load strings + if ( $script == 'l10n.js' ) + { + global $lang; + $js_head .= "\n "; + } + $loadlines[] = "loaded_components['$script'] = true;"; + } + + // tell the system that this stuff is already loaded + $loadlines = implode("\n ", $loadlines); + $js_head .= "\n "; + } + $js_foot = << // This initializes the Javascript runtime when the DOM is ready - not when the page is @@ -536,11 +593,14 @@ else { $cdnpath = cdnPath; + $js_head = ''; + // point to jsres compressor - $js_head = << JSEOF; + } $js_foot = << @@ -557,6 +617,22 @@ } //]]> JSEOF; + + if ( !empty($this->js_preload) ) + { + foreach ( $this->js_preload as &$script ) + { + $script = preg_replace('/\.js$/', '', $script) . '.js'; + } + $this->js_preload = array_unique($this->js_preload); + if ( in_array('l10n.js', $this->js_preload) ) + { + // special case for l10n: also load strings + global $lang; + $js_foot .= "\n "; + } + $scripts = implode(',', $this->js_preload); + $js_foot .= "\n "; } $this->assign_bool(array( diff -r 5990ac411f34 -r 5a282dbf8fad plugins/SpecialAdmin.php --- a/plugins/SpecialAdmin.php Fri Jun 05 22:09:42 2009 -0400 +++ b/plugins/SpecialAdmin.php Mon Jun 15 20:09:58 2009 -0400 @@ -2051,20 +2051,26 @@ { global $db, $session, $paths, $template, $plugins; // Common objects global $lang; + global $output; - if($session->auth_level < USER_LEVEL_ADMIN) { + if ( $session->auth_level < USER_LEVEL_ADMIN ) + { redirect(makeUrlNS('Special', 'Login/'.$paths->page, 'level='.USER_LEVEL_ADMIN), 'Not authorized', 'You need an authorization level of '.USER_LEVEL_ADMIN.' to use this page, your auth level is: ' . $session->auth_level, 0); exit; } else { $template->set_theme('admin', 'default'); - $template->add_header(''); + $template->preload_js('fat'); + $template->preload_js('ajax'); + $template->preload_js('l10n'); + $template->preload_js('jquery'); + $template->preload_js('jquery-ui'); + $template->preload_js('autofill'); + $template->preload_js('admin-menu'); - if( !isset( $_GET['noheaders'] ) ) - { - $template->header(); - } + $output->header(); + echo $lang->get('adm_page_tagline'); ?>
-
- +
@@ -2265,10 +2266,7 @@
footer(); + $output->footer(); } } diff -r 5990ac411f34 -r 5a282dbf8fad themes/admin/footer.tpl --- a/themes/admin/footer.tpl Fri Jun 05 22:09:42 2009 -0400 +++ b/themes/admin/footer.tpl Mon Jun 15 20:09:58 2009 -0400 @@ -38,6 +38,7 @@ + {JS_FOOTER} diff -r 5990ac411f34 -r 5a282dbf8fad themes/admin/header.tpl --- a/themes/admin/header.tpl Fri Jun 05 22:09:42 2009 -0400 +++ b/themes/admin/header.tpl Mon Jun 15 20:09:58 2009 -0400 @@ -9,7 +9,7 @@ {JS_DYNAMIC_VARS} - + {JS_HEADER} {ADDITIONAL_HEADERS}