load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
authorDan
Sun, 21 Dec 2008 16:41:03 -0500
changeset 779 609e35845ec3
parent 778 57ce13805b6f
child 780 f65e35566b63
load_component() now accepts an array, and most JS components are loaded all in one request now. Totally modular baby. And failsafe too.
includes/clientside/jsres.php
includes/clientside/static/acl.js
includes/clientside/static/ajax.js
includes/clientside/static/autofill.js
includes/clientside/static/comments.js
includes/clientside/static/editor.js
includes/clientside/static/enano-lib-basic.js
includes/clientside/static/functions.js
includes/clientside/static/login.js
includes/clientside/static/messagebox.js
includes/clientside/static/rank-manager.js
includes/clientside/static/sliders.js
includes/clientside/static/tinymce-init.js
includes/clientside/static/userpage.js
--- a/includes/clientside/jsres.php	Sun Dec 21 16:28:00 2008 -0500
+++ b/includes/clientside/jsres.php	Sun Dec 21 16:41:03 2008 -0500
@@ -185,16 +185,38 @@
 {
   // requested a single file
   $js_file =& $_GET['f'];
-  if ( !preg_match('/^[a-z0-9_-]+\.js$/i', $js_file) )
+  if ( strstr($js_file, ',') )
   {
-    header('HTTP/1.1 404 Not Found');
-    exit('Not found');
+    $filelist = explode(',', $js_file);
+    unset($js_file);
+    $everything = '';
+    foreach ( $filelist as $js_file )
+    {
+      if ( !preg_match('/^[a-z0-9_-]+\.js$/i', $js_file) )
+      {
+        header('HTTP/1.1 404 Not Found');
+        exit('Not found');
+      }
+      
+      $apex = filemtime("includes/clientside/static/$js_file");
+      
+      $file_contents = file_get_contents("includes/clientside/static/$js_file");
+      $everything .= jsres_cache_check($js_file, $file_contents) . ' loaded_components[\'' . $js_file . '\'] = true;';
+    }
   }
-  
-  $apex = filemtime("includes/clientside/static/$js_file");
-  
-  $file_contents = file_get_contents("includes/clientside/static/$js_file");
-  $everything = jsres_cache_check($js_file, $file_contents);
+  else
+  {
+    if ( !preg_match('/^[a-z0-9_-]+\.js$/i', $js_file) )
+    {
+      header('HTTP/1.1 404 Not Found');
+      exit('Not found');
+    }
+    
+    $apex = filemtime("includes/clientside/static/$js_file");
+    
+    $file_contents = file_get_contents("includes/clientside/static/$js_file");
+    $everything = jsres_cache_check($js_file, $file_contents) . ' loaded_components[\'' . $js_file . '\'] = true;';
+  }
 }
 else
 {
@@ -294,7 +316,7 @@
     {
       if ( $cache_file['md5'] === $file_md5 )
       {
-        header("X-Cache-Status: cache HIT, hash $file_md5");
+        @header("X-Cache-Status: cache HIT, hash $file_md5");
         $loaded_cache = true;
         $file_contents = $cache_file['src'];
       }
@@ -316,16 +338,16 @@
         ));
       fwrite($handle, $payload);
       fclose($handle);
-      header("X-Cache-Status: cache MISS, new generated");
+      @header("X-Cache-Status: cache MISS, new generated");
     }
     else
     {
-      header("X-Cache-Status: cache MISS, not generated");
+      @header("X-Cache-Status: cache MISS, not generated");
     }
   }
   else if ( !$loaded_cache )
   {
-    header("X-Cache-Status: cache MISS, not generated");
+    @header("X-Cache-Status: cache MISS, not generated");
   }
   
   return $file_contents;
--- a/includes/clientside/static/acl.js	Sun Dec 21 16:28:00 2008 -0500
+++ b/includes/clientside/static/acl.js	Sun Dec 21 16:41:03 2008 -0500
@@ -9,11 +9,7 @@
   if(IE)
     return true;
   
-  load_component('l10n');
-  load_component('messagebox');
-  load_component('fadefilter');
-  load_component('template-compiler');
-  load_component('autofill');
+  load_component(['l10n', 'messagebox', 'fadefilter', 'template-compiler', 'autofill', 'jquery', 'jquery-ui']);
   
   if(!page_id || !namespace)
   {
@@ -58,11 +54,7 @@
 
 function ajaxOpenDirectACLRule(rule_id)
 {
-  load_component('l10n');
-  load_component('messagebox');
-  load_component('fadefilter');
-  load_component('template-compiler');
-  load_component('autofill');
+  load_component(['l10n', 'messagebox', 'fadefilter', 'template-compiler', 'autofill']);
   
   var params = {
     target_id: rule_id,
--- a/includes/clientside/static/ajax.js	Sun Dec 21 16:28:00 2008 -0500
+++ b/includes/clientside/static/ajax.js	Sun Dec 21 16:41:03 2008 -0500
@@ -78,8 +78,7 @@
     return true;
   
   // updated - 1.1.4 to use miniPrompt
-  load_component('l10n');
-  load_component('messagebox');
+  load_component(['l10n', 'messagebox', 'flyin', 'fadefilter']);
   miniPrompt(ajaxRenameConstructDialog);
 }
 
@@ -221,10 +220,7 @@
   // IE <6 pseudo-compatibility
   if ( KILL_SWITCH )
     return true;
-  load_component('l10n');
-  load_component('messagebox');
-  load_component('jquery');
-  load_component('jquery-ui');
+  load_component(['l10n', 'messagebox', 'jquery', 'jquery-ui', 'fadefilter', 'flyin']);
   
   // stage 1: prompt for reason and confirmation
   miniPrompt(function(parent)
@@ -409,8 +405,7 @@
 
 window.ajaxDelVote = function()
 {
-  load_component('l10n');
-  load_component('messagebox');
+  load_component(['l10n', 'messagebox', 'flyin', 'fadefilter']);
   
   // IE <6 pseudo-compatibility
   if ( KILL_SWITCH )
@@ -450,8 +445,7 @@
 
 window.ajaxResetDelVotes = function()
 {
-  load_component('l10n');
-  load_component('messagebox');
+  load_component(['l10n', 'messagebox', 'flyin', 'fadefilter']);
   
   // IE <6 pseudo-compatibility
   if ( KILL_SWITCH )
@@ -619,8 +613,7 @@
   if ( KILL_SWITCH )
     return true;
   
-  load_component('l10n');
-  load_component('messagebox');
+  load_component(['l10n', 'messagebox', 'flyin', 'fadefilter']);
   
   miniPromptMessage({
       title: $lang.get('ajax_clearlogs_confirm_title'),
@@ -745,8 +738,7 @@
   // IE <6 pseudo-compatibility
   if ( KILL_SWITCH )
     return true;
-  load_component('l10n');
-  load_component('messagebox');
+  load_component(['l10n', 'messagebox', 'flyin', 'fadefilter']);
   
   var inner_html = '';
   inner_html += '<p><label>' + $lang.get('ajax_changestyle_lbl_theme') + ' ';
@@ -1213,7 +1205,7 @@
 
 window.aboutKeepAlive = function()
 {
-  load_component('messagebox');
+  load_component(['messagebox', 'flyin', 'fadefilter']);
   new MessageBox(MB_OK|MB_ICONINFORMATION, $lang.get('user_keepalive_info_title'), $lang.get('user_keepalive_info_body'));
 }
 
--- a/includes/clientside/static/autofill.js	Sun Dec 21 16:28:00 2008 -0500
+++ b/includes/clientside/static/autofill.js	Sun Dec 21 16:41:03 2008 -0500
@@ -128,9 +128,7 @@
 
 addOnloadHook(function()
   {
-    load_component('l10n');
-    load_component('jquery');
-    load_component('jquery-ui');
+    load_component(['l10n', 'jquery', 'jquery-ui']);
     
     if ( !window.jQuery )
     {
--- a/includes/clientside/static/comments.js	Sun Dec 21 16:28:00 2008 -0500
+++ b/includes/clientside/static/comments.js	Sun Dec 21 16:41:03 2008 -0500
@@ -5,11 +5,7 @@
 
 window.ajaxComments = function(parms)
 {
-  load_component('l10n');
-  load_component('paginate');
-  load_component('template-compiler');
-  load_component('toolbar');
-  load_component('flyin');
+  load_component(['l10n', 'paginate', 'template-compiler', 'toolbar', 'flyin']);
   setAjaxLoading();
   var pid = strToPageID(title);
   if(!parms)
@@ -358,15 +354,13 @@
   }
   if ( subj == '' )
   {
-    load_component('messagebox');
-    load_component('fadefilter');
+    load_component(['messagebox', 'fadefilter']);
     new MessageBox(MB_OK|MB_ICONSTOP, 'Input validation failed', 'Please enter a subject for your comment.');
     return false;
   }
   if ( text == '' )
   {
-    load_component('messagebox');
-    load_component('fadefilter');
+    load_component(['messagebox', 'fadefilter']);
     new MessageBox(MB_OK|MB_ICONSTOP, 'Input validation failed', 'Please enter some text for the body of your comment .');
     return false;
   }
--- a/includes/clientside/static/editor.js	Sun Dec 21 16:28:00 2008 -0500
+++ b/includes/clientside/static/editor.js	Sun Dec 21 16:41:03 2008 -0500
@@ -12,9 +12,7 @@
     return true;
   if ( editor_open )
     return true;
-  load_component('l10n');
-  load_component('template-compiler');
-  load_component('messagebox');
+  load_component(['l10n', 'template-compiler', 'messagebox']);
   selectButtonMinor('edit');
   selectButtonMajor('article');
   setAjaxLoading();
--- a/includes/clientside/static/enano-lib-basic.js	Sun Dec 21 16:28:00 2008 -0500
+++ b/includes/clientside/static/enano-lib-basic.js	Sun Dec 21 16:41:03 2008 -0500
@@ -216,24 +216,65 @@
 var _load_component_running = false;
 function load_component(file)
 {
+  var multiple = false;
+  if ( typeof(file) == 'object' )
+  {
+    if ( ENANO_JSRES_COMPRESSED )
+    {
+      multiple = true;
+      for ( var i = 0; i < file.length; i++ )
+      {
+        file[i] = (file[i].replace(/\.js$/, '')) + '.js';
+        if ( loaded_components[file[i]] )
+        {
+          file[i] = false;
+        }
+      }
+      var file2 = [];
+      for ( var i = 0; i < file.length; i++ )
+      {
+        if ( file[i] )
+          file2.push(file[i]);
+      }
+      file = file2;
+      delete(file2);
+      if ( file.length < 1 )
+      {
+        return true;
+      }
+      var file_flat = implode(',', file);
+    }
+    else
+    {
+      for ( var i = 0; i < file.length; i++ )
+      {
+        load_component(file[i]);
+      }
+      return true;
+    }
+  }
   _load_component_running = true;
-  file = file.replace(/\.js$/, '');
+  if ( !multiple )
+  {
+    file = file.replace(/\.js$/, '');
   
-  if ( loaded_components[file + '.js'] )
-  {
-    // already loaded
-    return true;
+    if ( loaded_components[file + '.js'] )
+    {
+      // already loaded
+      return true;
+    }
   }
   
-  console.info('Loading component %s via AJAX', file);
+  console.info('Loading component %s via AJAX', ( multiple ? file_flat : file ));
   
-  load_show_win(file);
+  load_show_win(( multiple ? file_flat : file ));
   
   // get an XHR instance
   var ajax = ajaxMakeXHR();
   
-  file = file + '.js';
-  var uri = ( ENANO_JSRES_COMPRESSED ) ? scriptPath + '/includes/clientside/jsres.php?f=' + file : scriptPath + '/includes/clientside/static/' + file;
+  if ( !multiple )
+    file = file + '.js';
+  var uri = ( ENANO_JSRES_COMPRESSED ) ? scriptPath + '/includes/clientside/jsres.php?f=' + (multiple ? file_flat : file ) : scriptPath + '/includes/clientside/static/' + file;
   try
   {
     ajax.open('GET', uri, false);
@@ -267,7 +308,10 @@
     throw('load_component(): XHR for component ' + file + ' failed');
   }
   
-  loaded_components[file] = true;
+  if ( !multiple )
+  {
+    loaded_components[file] = true;
+  }
   _load_component_running = false;
   return true;
 }
@@ -280,7 +324,7 @@
     document.getElementById('_js_load_component').innerHTML = img + msg_loading_component.replace('%component%', file);
     return;
   }
-  file = file.replace(/\.js$/, '');
+  file = file.replace(/\.js$/, '').replace(/\.js,/g, ', ');
   var ld = document.createElement('div');
   ld.style.padding = '10px';
   ld.style.height = '12px';
--- a/includes/clientside/static/functions.js	Sun Dec 21 16:28:00 2008 -0500
+++ b/includes/clientside/static/functions.js	Sun Dec 21 16:41:03 2008 -0500
@@ -153,12 +153,7 @@
 
 function handle_invalid_json(response, customerror)
 {
-  load_component('messagebox');
-  load_component('jquery');
-  load_component('jquery-ui');
-  load_component('fadefilter');
-  load_component('flyin');
-  load_component('l10n');
+  load_component(['messagebox', 'jquery', 'jquery-ui', 'fadefilter', 'flyin', 'l10n']);
   
   darken(aclDisableTransitionFX, 70, 'invalidjsondarkener');
   
--- a/includes/clientside/static/login.js	Sun Dec 21 16:28:00 2008 -0500
+++ b/includes/clientside/static/login.js	Sun Dec 21 16:41:03 2008 -0500
@@ -98,12 +98,7 @@
 
 window.ajaxLoginInit = function(call_on_finish, user_level)
 {
-  load_component('messagebox');
-  load_component('flyin');
-  load_component('jquery');
-  load_component('jquery-ui');
-  load_component('l10n');
-  load_component('crypto');
+  load_component(['messagebox', 'flyin', 'jquery', 'jquery-ui', 'l10n', 'crypto']);
   
   logindata = {};
   
@@ -1055,8 +1050,7 @@
 
 window.ajaxInitLogout = function()
 {
-  load_component('messagebox');
-  load_component('l10n');
+  load_component(['messagebox', 'l10n', 'flyin', 'fadefilter']);
   var mb = new MessageBox(MB_YESNO|MB_ICONQUESTION, $lang.get('user_logout_confirm_title'), $lang.get('user_logout_confirm_body'));
   mb.onclick['Yes'] = function()
     {
--- a/includes/clientside/static/messagebox.js	Sun Dec 21 16:28:00 2008 -0500
+++ b/includes/clientside/static/messagebox.js	Sun Dec 21 16:41:03 2008 -0500
@@ -324,9 +324,7 @@
 {
   if ( !aclDisableTransitionFX )
   {
-    load_component('flyin');
-    load_component('jquery');
-    load_component('jquery-ui');
+    load_component(['flyin', 'jquery', 'jquery-ui', 'fadefilter']);
   }
   var darkener = darken(aclDisableTransitionFX, 40, 'miniprompt_darkener');
   
--- a/includes/clientside/static/rank-manager.js	Sun Dec 21 16:28:00 2008 -0500
+++ b/includes/clientside/static/rank-manager.js	Sun Dec 21 16:41:03 2008 -0500
@@ -681,8 +681,7 @@
 {
   var whitey = whiteOutElement(editor.wrapperdiv);
   
-  load_component('jquery');
-  load_component('jquery-ui');
+  load_component(['jquery', 'jquery-ui']);
   
   var json_packet = {
     mode: 'delete_rank',
--- a/includes/clientside/static/sliders.js	Sun Dec 21 16:28:00 2008 -0500
+++ b/includes/clientside/static/sliders.js	Sun Dec 21 16:41:03 2008 -0500
@@ -70,8 +70,7 @@
       continue;
     toggler.onclick = function()
     {
-      load_component('jquery');
-      load_component('jquery-ui');
+      load_component(['jquery', 'jquery-ui']);
       
       var mydiv = this.parentNode.nextSibling;
       while ( mydiv.tagName != 'DIV' )
--- a/includes/clientside/static/tinymce-init.js	Sun Dec 21 16:28:00 2008 -0500
+++ b/includes/clientside/static/tinymce-init.js	Sun Dec 21 16:41:03 2008 -0500
@@ -61,7 +61,7 @@
 
 if ( !KILL_SWITCH && !DISABLE_MCE )
 {
-  var uri = scriptPath + '/includes/clientside/tinymce/tiny_mce_gzip.js';
+  var uri = scriptPath + '/includes/clientside/tinymce/tiny_mce_gzip.js?3211';
   var sc = document.createElement('script');
   sc.src = uri;
   sc.type = 'text/javascript';
--- a/includes/clientside/static/userpage.js	Sun Dec 21 16:28:00 2008 -0500
+++ b/includes/clientside/static/userpage.js	Sun Dec 21 16:41:03 2008 -0500
@@ -106,8 +106,7 @@
   {
     // DISABLED: see "nofade = true;" above.
     // do this in a slightly fancier fashion
-    load_component('jquery');
-    load_component('jquery-ui');
+    load_component(['jquery', 'jquery-ui']);
     $('#tab:' + current_block).hide("blind", {}, 500, function()
     {
       $('#tab:' + block).show("blind", {}, 500);