Browse Source

amber.js tries to find itself also by id not just as last <script>

When loaded all scripts asynchronously, the
'last <script> tag' trick is unable to find the right one,
so amber.js does not see its path and possible data-libs.

In case of async loading, giving the <script> well-known id
'amber-path-mapper' allows it to find itself.
Herbert Vojčík 10 years ago
parent
commit
c972313136
1 changed files with 5 additions and 2 deletions
  1. 5 2
      support/amber.js

+ 5 - 2
support/amber.js

@@ -15,8 +15,11 @@
 var require;
 
 require = function (require) {
-    var scripts = document.getElementsByTagName("script");
-    var me = scripts[scripts.length - 1];
+    var me = document.getElementById("amber-path-mapper");
+    if (!me || me.tagName.toLowerCase() !== "script") {
+        var scripts = document.getElementsByTagName("script");
+        me = scripts[scripts.length - 1];
+    }
     var src = me.src;
     // strip the last two elements from the URL
     // e.g. http://app.com/amber/support/amber.js -> http://app.com/amber