Provide a mechanism to load any random JS file via dojo.require()-ish syntax.
authormiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 10 Dec 2010 16:02:41 +0000 (16:02 +0000)
committermiker <miker@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 10 Dec 2010 16:02:41 +0000 (16:02 +0000)
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).

git-svn-id: svn://svn.open-ils.org/ILS/trunk@18964 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/web/js/dojo/openils/Util.js

index 729fa16..ace522e 100644 (file)
@@ -391,6 +391,29 @@ if(!dojo._hasResource["openils.Util"]) {
         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,