Author: rbaxter85
Date: Wed Dec 26 14:26:54 2012
New Revision: 1425923

URL: http://svn.apache.org/viewvc?rev=1425923&view=rev
Log:
Committed for Bob O'Neil

Modified:
    shindig/trunk/features/pom.xml
    
shindig/trunk/features/src/main/javascript/features/core.util.onload/feature.xml
    
shindig/trunk/features/src/main/javascript/features/core.util.onload/onload.js

Modified: shindig/trunk/features/pom.xml
URL: 
http://svn.apache.org/viewvc/shindig/trunk/features/pom.xml?rev=1425923&r1=1425922&r2=1425923&view=diff
==============================================================================
--- shindig/trunk/features/pom.xml (original)
+++ shindig/trunk/features/pom.xml Wed Dec 26 14:26:54 2012
@@ -133,12 +133,12 @@
                 <source>core.util.base/base.js</source>
                 <source>core.util.dom/dom.js</source>
                 <source>core.util.event/event.js</source>
+                <source>core.log/log.js</source>
                 <source>core.util.onload/onload.js</source>
                 <source>core.util.string/string.js</source>
                 <source>core.util.urlparams/urlparams.js</source>
                 <source>core.util/util.js</source>
                 <source>core.prefs/prefs.js</source>
-                <source>core.log/log.js</source>
                 <source>core.io/io.js</source>
                 <source>container.util/constant.js</source>
                 <source>container.util/util.js</source>

Modified: 
shindig/trunk/features/src/main/javascript/features/core.util.onload/feature.xml
URL: 
http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/core.util.onload/feature.xml?rev=1425923&r1=1425922&r2=1425923&view=diff
==============================================================================
--- 
shindig/trunk/features/src/main/javascript/features/core.util.onload/feature.xml
 (original)
+++ 
shindig/trunk/features/src/main/javascript/features/core.util.onload/feature.xml
 Wed Dec 26 14:26:54 2012
@@ -19,6 +19,7 @@
 <feature>
   <name>core.util.onload</name>
   <dependency>globals</dependency>
+  <dependency>core.util.urlparams</dependency>
   <all>
     <script src="onload.js"/>
     <script src="taming.js" caja="1"/>

Modified: 
shindig/trunk/features/src/main/javascript/features/core.util.onload/onload.js
URL: 
http://svn.apache.org/viewvc/shindig/trunk/features/src/main/javascript/features/core.util.onload/onload.js?rev=1425923&r1=1425922&r2=1425923&view=diff
==============================================================================
--- 
shindig/trunk/features/src/main/javascript/features/core.util.onload/onload.js 
(original)
+++ 
shindig/trunk/features/src/main/javascript/features/core.util.onload/onload.js 
Wed Dec 26 14:26:54 2012
@@ -48,15 +48,62 @@ gadgets.util = gadgets.util || {};
       cb();
     };
 
-    for (var i = 0, j = onLoadHandlers.length; i < j; ++i) {
-      try {
-        onLoadHandlers[i]();
-      } catch (ex) {
-        gadgets.warn("Could not fire onloadhandler "+ex.message);
+    if (onLoadHandlers) {
+      for (var i = 0, j = onLoadHandlers.length; i < j; ++i) {
+        try {
+          onLoadHandlers[i]();
+        } catch (ex) {
+          gadgets.warn("Could not fire onloadhandler "+ ex.message);
+        }
       }
+      onLoadHandlers = undefined;  // No need to hold these references anymore.
     }
-    onLoadHandlers = undefined;  // No need to hold these references anymore.
   };
 
+  (function() {
+    // If a script is statically inserted into the dom, use events
+    // to call runOnLoadHandlers.
+    // Try to attach to DOMContentLoaded if using a modern browser.
+    gadgets.util.attachBrowserEvent(document,
+            "DOMContentLoaded",
+            gadgets.util.runOnLoadHandlers,
+            false);
+    // Always attach to window.onload as a fallback. We can safely ignore
+    // any repeated calls to runOnLoadHandlers.
+    var oldWindowOnload = window.onload;
+    window.onload = function() {
+      oldWindowOnload && oldWindowOnload();
+      gadgets.util.runOnLoadHandlers();
+    };
+    // If a script is dynamically inserted into the page, the DOMContentLoaded
+    // event will be fired before runOnLoadHandlers can be attached
+    // to the event. In this case, find the script that loads the core libary
+    // and attach runOnLoadHandlers to the script's onload event.
+    var libParam = "";
+    if (window && window.location && window.location.href) {
+      libParam = gadgets.util.getUrlParameters(window.location.href).libs;
+    }
+
+    var regex = /(?:js\/)([^&|\.]+)/g;
+    var match = regex.exec(libParam);
+
+    if (match) {
+      var url = decodeURIComponent(match[1]);
+      var scripts = document.getElementsByTagName("script") || [];
+      for (var i = 0; i < scripts.length; i++) {
+        var script = scripts[i];
+        var src = script.src;
+        if (src && url && src.indexOf(url) !== -1) {
+          // save a reference to the function that is already hooked up
+          // to the event
+          var oldonload = script.onload;
+          script.onload = function() {
+            oldonload && oldonload();
+            gadgets.util.runOnLoadHandlers();
+          };
+        }
+      }
+    }
+  })();
 })();
 


Reply via email to