[OpenLayers-Commits] r10862 - in trunk/openlayers: lib lib/OpenLayers tests

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Wed Oct 27 06:26:05 EDT 2010


Author: erilem
Date: 2010-10-27 03:26:05 -0700 (Wed, 27 Oct 2010)
New Revision: 10862

Added:
   trunk/openlayers/tests/OpenLayers4.html
Modified:
   trunk/openlayers/lib/OpenLayers.js
   trunk/openlayers/lib/OpenLayers/SingleFile.js
   trunk/openlayers/tests/list-tests.html
Log:
do not assume that the browser won't add new script tags to the DOM before it's done with the evaluation of OpenLayers.js, r=fredj,ahocevar (closes #2873)

Modified: trunk/openlayers/lib/OpenLayers/SingleFile.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/SingleFile.js	2010-10-27 10:12:01 UTC (rev 10861)
+++ trunk/openlayers/lib/OpenLayers/SingleFile.js	2010-10-27 10:26:05 UTC (rev 10862)
@@ -25,9 +25,19 @@
      * {String} Path to this script
      */
     _getScriptLocation: (function() {
-        var s = document.getElementsByTagName('script');
-        var m = s[s.length-1].getAttribute("src").match(/(^|(.*?\/))(OpenLayers\.js)(\?|$)/);
-        var l = m ? m[1] : "";
+        var r = new RegExp("(^|(.*?\\/))(OpenLayers\.js)(\\?|$)"),
+            s = document.getElementsByTagName('script'),
+            src, m, l = "";
+        for(var i=0, len=s.length; i<len; i++) {
+            src = s[i].getAttribute('src');
+            if(src) {
+                var m = src.match(r);
+                if(m) {
+                    l = m[1];
+                    break;
+                }
+            }
+        }
         return (function() { return l; });
     })()
 };

Modified: trunk/openlayers/lib/OpenLayers.js
===================================================================
--- trunk/openlayers/lib/OpenLayers.js	2010-10-27 10:12:01 UTC (rev 10861)
+++ trunk/openlayers/lib/OpenLayers.js	2010-10-27 10:26:05 UTC (rev 10862)
@@ -44,10 +44,19 @@
          * {String} Path to this script
          */
         _getScriptLocation: (function() {
-            var r = new RegExp("(^|(.*?\\/))(" + scriptName + ")(\\?|$)");
-            var s = document.getElementsByTagName('script');
-            var m = s[s.length-1].getAttribute("src").match(r);
-            var l = m ? m[1] : "";
+            var r = new RegExp("(^|(.*?\\/))(" + scriptName + ")(\\?|$)"),
+                s = document.getElementsByTagName('script'),
+                src, m, l = "";
+            for(var i=0, len=s.length; i<len; i++) {
+                src = s[i].getAttribute('src');
+                if(src) {
+                    var m = src.match(r);
+                    if(m) {
+                        l = m[1];
+                        break;
+                    }
+                }
+            }
             return (function() { return l; });
         })()
     };

Added: trunk/openlayers/tests/OpenLayers4.html
===================================================================
--- trunk/openlayers/tests/OpenLayers4.html	                        (rev 0)
+++ trunk/openlayers/tests/OpenLayers4.html	2010-10-27 10:26:05 UTC (rev 10862)
@@ -0,0 +1,18 @@
+<html>
+<head>
+    <script type="text/javascript">
+	OpenLayers = {singleFile: true}; // just to make the test run faster
+        document.write('<scr'+'ipt src="../lib/OpenLayers.js"></scr'+'ipt>');
+        document.write('<scr'+'ipt src="bogus/foo-/OpenLayers.js"></scr'+'ipt>');
+    </script>
+    <script type="text/javascript">
+        function test_OpenLayers(t) {
+            t.plan(1);
+            t.eq(OpenLayers._getScriptLocation(), "../lib/",
+                 "Script location correctly detected, and not fooled by other scripts.");
+        }
+    </script>
+</head>
+<body>
+</body>
+</html>

Modified: trunk/openlayers/tests/list-tests.html
===================================================================
--- trunk/openlayers/tests/list-tests.html	2010-10-27 10:12:01 UTC (rev 10861)
+++ trunk/openlayers/tests/list-tests.html	2010-10-27 10:26:05 UTC (rev 10862)
@@ -159,6 +159,7 @@
     <li>OpenLayers1.html</li>
     <li>OpenLayers2.html</li>
     <li>OpenLayers3.html</li>
+    <li>OpenLayers4.html</li>
     <li>Popup.html</li>
     <li>Popup/Anchored.html</li>
     <li>Popup/AnchoredBubble.html</li>



More information about the Commits mailing list