Fixed a series of infinite loops with preloading components and placeholders
authorDan
Wed, 08 Jul 2009 22:27:24 -0400
changeset 1046 cfc6c30c5e2d
parent 1045 ce069a06906c
child 1047 d996bb6d6e74
Fixed a series of infinite loops with preloading components and placeholders
includes/clientside/jsres.php
includes/clientside/static/admin-menu.js
includes/clientside/static/autofill.js
includes/clientside/static/enano-lib-basic.js
includes/template.php
--- a/includes/clientside/jsres.php	Wed Jul 08 18:53:45 2009 -0400
+++ b/includes/clientside/jsres.php	Wed Jul 08 22:27:24 2009 -0400
@@ -40,12 +40,7 @@
 $local_start = microtime_float();
 
 // Disable for IE, it causes problems.
-if ( ( strstr(@$_SERVER['HTTP_USER_AGENT'], 'MSIE') || defined('ENANO_JS_DEBUG') ) && !isset($_GET['early']) )
-{
-  header('HTTP/1.1 302 Redirect');
-  header('Location: static/enano-lib-basic.js');
-  exit();
-}
+$disable_compress = ( strstr(@$_SERVER['HTTP_USER_AGENT'], 'MSIE') || defined('ENANO_JS_DEBUG') ) && !isset($_GET['early']);
 
 // Setup Enano
 
@@ -135,10 +130,12 @@
 // note - obfuscated for optimization purposes. The exact same code except properly indented is in enano-lib-basic.
 if ( isset($_GET['early']) )
 {
-  header('ETag: enanocms-lib-early-r2');
+  header('ETag: enanocms-lib-early-r3');
   header('Expires: Wed, 1 Jan 2020 00:00:00 GMT');
   
   echo <<<JSEOF
+window.loaded_components = window.loaded_components || {};
+window.onload_complete = false;
 var onload_hooks = new Array();function addOnloadHook(func){if ( typeof ( func ) == 'function' ){if ( typeof(onload_hooks.push) == 'function' ){onload_hooks.push(func);}else{onload_hooks[onload_hooks.length] = func;};};}
 JSEOF;
   
@@ -198,8 +195,9 @@
       $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; if ( onload_complete ) { runOnloadHooks(); onload_hooks = []; };';
+      $everything .= jsres_cache_check($js_file, $file_contents) . ' loaded_components[\'' . $js_file . '\'] = true;';
     }
+    $everything .= 'if ( onload_complete ) { console.debug("running hooks from jsres"); runOnloadHooks(); onload_hooks = []; };';
   }
   else
   {
@@ -212,7 +210,7 @@
     $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; if ( onload_complete ) { runOnloadHooks(); onload_hooks = []; };';
+    $everything = jsres_cache_check($js_file, $file_contents) . ' loaded_components[\'' . $js_file . '\'] = true; if ( onload_complete ) { console.debug("running hooks from jsres"); runOnloadHooks(); onload_hooks = []; };';
   }
 }
 else
@@ -292,6 +290,10 @@
 function jsres_cache_check($js_file, $file_contents)
 {
   global $full_compress_safe, $compress_unsafe;
+  global $disable_compress;
+  
+  if ( $disable_compress )
+    return $file_contents;
   
   $file_md5 = md5($file_contents);
   
--- a/includes/clientside/static/admin-menu.js	Wed Jul 08 18:53:45 2009 -0400
+++ b/includes/clientside/static/admin-menu.js	Wed Jul 08 22:27:24 2009 -0400
@@ -22,9 +22,9 @@
  * licenses/tigra-menu.html document in the Enano distribution.
  */
 
-if ( typeof(readCookie) == 'function' )
+if ( /admin_menu_state=/.test(document.cookie) )
 {
-  var ck = readCookie('admin_menu_state');
+  var ck = (String(document.cookie).match(/admin_menu_state=([0-9]+)/))[1];
   if(ck)
   {
     ck = parseInt(ck);
--- a/includes/clientside/static/autofill.js	Wed Jul 08 18:53:45 2009 -0400
+++ b/includes/clientside/static/autofill.js	Wed Jul 08 22:27:24 2009 -0400
@@ -60,30 +60,6 @@
   }
 }
 
-window.autofill_onload = function()
-{
-  if ( this.loaded )
-  {
-    return true;
-  }
-  
-  var inputs = document.getElementsByClassName('input', 'autofill');
-  
-  if ( inputs.length > 0 )
-  {
-    // we have at least one input that needs to be made an autofill element.
-    // is spry data loaded?
-    load_component('l10n');
-  }
-  
-  this.loaded = true;
-  
-  for ( var i = 0; i < inputs.length; i++ )
-  {
-    autofill_init_element(inputs[i]);
-  }
-}
-
 window.autofill_init_element = function(element, params)
 {
   if ( element.af_initted )
@@ -126,6 +102,32 @@
   autofill_init_element(el, {});
 }
 
+// note: init, then onload (the latter is called automatically)
+
+window.autofill_onload = function()
+{
+  if ( this.loaded )
+  {
+    return true;
+  }
+  
+  var inputs = document.getElementsByClassName('input', 'autofill');
+  
+  if ( inputs.length > 0 )
+  {
+    // we have at least one input that needs to be made an autofill element.
+    // is spry data loaded?
+    load_component('l10n');
+  }
+  
+  this.loaded = true;
+  
+  for ( var i = 0; i < inputs.length; i++ )
+  {
+    autofill_init_element(inputs[i]);
+  }
+}
+
 window.autofill_init = function()
 {
   load_component(['l10n', 'jquery', 'jquery-ui']);
--- a/includes/clientside/static/enano-lib-basic.js	Wed Jul 08 18:53:45 2009 -0400
+++ b/includes/clientside/static/enano-lib-basic.js	Wed Jul 08 22:27:24 2009 -0400
@@ -592,7 +592,6 @@
   unselectAllButtonsMinor: 'toolbar.js',
   darken: 'fadefilter.js',
   enlighten: 'fadefilter.js',
-  autofill_onload: 'autofill.js',
   password_score: 'pwstrength.js',
   password_score_field: 'pwstrength.js',
   ajaxEditTheme: 'theme-manager.js',
@@ -601,7 +600,7 @@
   ajaxInitRankEdit: 'rank-manager.js',
   ajaxInitRankCreate: 'rank-manager.js',
   autofill_init_element: 'autofill.js',
-  autofill_onload: 'autofill.js',
+  autofill_init: 'autofill.js',
   paginator_goto: 'paginate.js'
 };
 
@@ -627,15 +626,16 @@
 {
   var file = placeholder_list[i];
   placeholder_instances[i] = new Placeholder(i, file);
-  window[i] = placeholder_instances[i].go;
+  window[i] = window[i] || placeholder_instances[i].go;
 }
 
-$lang = {
+$lang = window.$lang || {
   get: function(a, b)
   {
     load_component('l10n');
     return $lang.get(a, b);
-  }
+  },
+  placeholder: true
 }
 
 //*/
--- a/includes/template.php	Wed Jul 08 18:53:45 2009 -0400
+++ b/includes/template.php	Wed Jul 08 22:27:24 2009 -0400
@@ -607,23 +607,7 @@
       <!-- Only load a basic set of functions for now. Let the rest of the API load when the page is finished. -->
       <script type="text/javascript" src="$cdnpath/includes/clientside/jsres.php?early"></script>
 JSEOF;
-      }
-      $js_foot = <<<JSEOF
-    <!-- jsres.php is a wrapper script that compresses and caches single JS files to minimize requests -->
-    <script type="text/javascript" src="$cdnpath/includes/clientside/jsres.php"></script>
-    <script type="text/javascript">//<![CDATA[
-      // This initializes the Javascript runtime when the DOM is ready - not when the page is
-      // done loading, because enano-lib-basic still has to load some 15 other script files
-      // check for the init function - this is a KHTML fix
-      // This doesn't seem to work properly in IE in 1.1.x - there are some problems with
-      // tinyMCE and l10n.
-      if ( typeof ( enano_init ) == 'function' && !IE )
-      {
-        enano_init();
-        window.onload = function(e) {  };
-      }
-    //]]></script>
-JSEOF;
+      $js_foot = '';
       
       if ( !empty($this->js_preload) )
       {
@@ -640,7 +624,27 @@
         }
         $scripts = implode(',', $this->js_preload);
         $js_foot .= "\n    <script type=\"text/javascript\" src=\"" . cdnPath . "/includes/clientside/jsres.php?f=$scripts\"></script>";
+        
+      }
+      
+      $js_foot .= <<<JSEOF
+    <!-- jsres.php is a wrapper script that compresses and caches single JS files to minimize requests -->
+    <script type="text/javascript" src="$cdnpath/includes/clientside/jsres.php"></script>
+    <script type="text/javascript">//<![CDATA[
+      // This initializes the Javascript runtime when the DOM is ready - not when the page is
+      // done loading, because enano-lib-basic still has to load some 15 other script files
+      // check for the init function - this is a KHTML fix
+      // This doesn't seem to work properly in IE in 1.1.x - there are some problems with
+      // tinyMCE and l10n.
+      if ( typeof ( enano_init ) == 'function' && !IE )
+      {
+        enano_init();
+        window.onload = function(e) {  };
+      }
+    //]]></script>
+JSEOF;
     }
+  
     
     $this->assign_bool(array(
         'fixed_menus' => false,