[open-ils-commits] r18965 - branches/rel_2_0/Open-ILS/web/js/dojo/openils (miker)

svn at svn.open-ils.org svn at svn.open-ils.org
Fri Dec 10 11:03:51 EST 2010


Author: miker
Date: 2010-12-10 11:03:49 -0500 (Fri, 10 Dec 2010)
New Revision: 18965

Modified:
   branches/rel_2_0/Open-ILS/web/js/dojo/openils/Util.js
Log:
Provide a mechanism to load any random JS file via dojo.require()-ish syntax.

Why would we want to do such a thing, you might ask?

Well, the short answer is that Firefox hates pages that have more than one script block (inline is worse than tag) that contains pre-onLoad XHR. So, this allows us to pull the actual loading of JS from the same domain as the page into an inline block. This allows us to eliminate the WSOD on FF by pulling all (dangerous) JS into a single, final inline block, after which we don't care if the DOMContentLoaded event fires -- that's when it should fire, structurally -- but in FF it may fire for a different reason (bug) than it should (fell of the end of the page in the rendering engine).



Modified: branches/rel_2_0/Open-ILS/web/js/dojo/openils/Util.js
===================================================================
--- branches/rel_2_0/Open-ILS/web/js/dojo/openils/Util.js	2010-12-10 16:02:41 UTC (rev 18964)
+++ branches/rel_2_0/Open-ILS/web/js/dojo/openils/Util.js	2010-12-10 16:03:49 UTC (rev 18965)
@@ -376,7 +376,30 @@
         dojo.forEach(patterns, function(pat) { _hilightNode(node, pat); });
     };
 
+    openils.Util._legacyModulePaths = {};
+    /*****
+     * Take the URL of a JS file and magically turn it into something that
+     * dojo.require can load by registering a module path for it ... and load it.
+     *****/
+    openils.Util.requireLegacy = function(url) {
+        var bURL = url.replace(/\/[^\/]+$/,'');
+        var file = url.replace(/^.*\/([^\/]+)$/,'$1');
+        var libname = url.replace(/^.*?\/(.+)\/[^\/]+$/,'$1').replace(/[^a-z]/ig,'_');
+        var modname = libname + '.' + file.replace(/\.js$/,'');
 
+        if (!openils.Util._legacyModulePaths[libname]) {
+            dojo.registerModulePath(libname,bURL);
+            openils.Util._legacyModulePaths[libname] = {};
+        }
+
+        if (!openils.Util._legacyModulePaths[libname][modname]) {
+            dojo.require(modname, true);
+            openils.Util._legacyModulePaths[libname][modname] = true;
+        }
+
+        return openils.Util._legacyModulePaths[libname][modname];
+    };
+
     /**
      * Takes a chunk of HTML, inserts it into a new window, prints the window, 
      * then closes the windw.  To provide ample printer queueing time, automatically



More information about the open-ils-commits mailing list