ソースを参照

Guessing location of require.min.js and loading it dynamically

Herbert Vojčík 10 年 前
コミット
8964958551
1 ファイル変更22 行追加11 行削除
  1. 22 11
      index.html

+ 22 - 11
index.html

@@ -10,20 +10,31 @@
     <div id="helper">Loading Helios...</div>
 
     <div id="includes">
-      <script type='text/javascript' src='../requirejs/require.min.js'></script>
       <script type='text/javascript'>
         var base = decodeURIComponent(window.location.search.slice(1));
-        if (base) require.config({baseUrl: base});
-        require(["require", "config"], function (require) {
-          require(["helios/set"], function (smalltalk) {
-            window.onbeforeunload = function() {
-              return 'Do you want to close Amber? All uncommitted changes will be lost.';
-            };
+        var script = document.createElement("script");
+        script.src = base + "/config.js";
+        document.getElementsByTagName("head")[0].appendChild(script);
+        var __interval = setInterval(function () {
+          if (typeof require !== "undefined") {
+            clearInterval(__interval);
+            require.baseUrl = base;
+            var amberPath = base + "/" + require.paths.amber;
+            require.callback = function () {
+              require(["helios/set"], function (smalltalk) {
+                window.onbeforeunload = function() {
+                  return 'Do you want to close Amber? All uncommitted changes will be lost.';
+                };
 
-            smalltalk.initialize({'transport.defaultAmdNamespace': "amber_core"});
-            smalltalk.globals.HLManager._setup();
-          });
-        });
+                smalltalk.initialize({'transport.defaultAmdNamespace': "amber_core"});
+                smalltalk.globals.HLManager._setup();
+              });
+            };
+            script = document.createElement("script");
+            script.src = amberPath + "/requirejs/require.min.js";
+            document.getElementsByTagName("head")[0].appendChild(script);
+          }
+        }, 200);
       </script>
     </div>
   </body>