Modifying the loader script to check more carefully for the location of OpenLayers.js - allowing folks to have scripts called things like foo-OpenLayers.js. r=crschmidt (closes #1888)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@9086 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
+6
-12
@@ -37,28 +37,22 @@
|
|||||||
* {String} Path to this script
|
* {String} Path to this script
|
||||||
*/
|
*/
|
||||||
_getScriptLocation: function () {
|
_getScriptLocation: function () {
|
||||||
var scriptLocation = "";
|
var scriptLocation = "";
|
||||||
var scriptName = OpenLayers._scriptName;
|
var isOL = new RegExp("(^|(.*?\\/))(" + OpenLayers._scriptName + ")(\\?|$)");
|
||||||
|
|
||||||
var scripts = document.getElementsByTagName('script');
|
var scripts = document.getElementsByTagName('script');
|
||||||
for (var i=0, len=scripts.length; i<len; i++) {
|
for (var i=0, len=scripts.length; i<len; i++) {
|
||||||
var src = scripts[i].getAttribute('src');
|
var src = scripts[i].getAttribute('src');
|
||||||
if (src) {
|
if (src) {
|
||||||
var index = src.lastIndexOf(scriptName);
|
var match = src.match(isOL);
|
||||||
// set path length for src up to a query string
|
if(match) {
|
||||||
var pathLength = src.lastIndexOf('?');
|
scriptLocation = match[1];
|
||||||
if (pathLength < 0) {
|
|
||||||
pathLength = src.length;
|
|
||||||
}
|
|
||||||
// is it found, at the end of the URL?
|
|
||||||
if ((index > -1) && (index + scriptName.length == pathLength)) {
|
|
||||||
scriptLocation = src.slice(0, pathLength - scriptName.length);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return scriptLocation;
|
return scriptLocation;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* OpenLayers.singleFile is a flag indicating this file is being included
|
* OpenLayers.singleFile is a flag indicating this file is being included
|
||||||
|
|||||||
+17
-12
@@ -1,19 +1,24 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<script id="script" src="../lib/OpenLayers.js"></script>
|
<script src="bogus/1/OpenLayers.js-foo"></script>
|
||||||
<script type="text/javascript">
|
<script src="bogus/2/foo-OpenLayers.js"></script>
|
||||||
function test_OpenLayers(t) {
|
<script id="script" src="../lib/OpenLayers.js"></script>
|
||||||
t.plan(2);
|
<script type="text/javascript">
|
||||||
|
function test_OpenLayers(t) {
|
||||||
var script = document.getElementById("script");
|
t.plan(3);
|
||||||
|
|
||||||
t.eq(OpenLayers._getScriptLocation(), "../", "Script location correctly detected.");
|
var script = document.getElementById("script");
|
||||||
|
|
||||||
script.setAttribute("src", "../lib/OpenLayers.js?foo");
|
|
||||||
t.eq(OpenLayers._getScriptLocation(), "../", "Script location with search string correctly detected.");
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
t.eq(OpenLayers._getScriptLocation(), "../", "Script location correctly detected.");
|
||||||
|
script.setAttribute("src", "../lib/OpenLayers.js?foo");
|
||||||
|
t.eq(OpenLayers._getScriptLocation(), "../", "Script location with search string correctly detected.");
|
||||||
|
|
||||||
|
// now pretend we're using a built script
|
||||||
|
OpenLayers._scriptName = "OpenLayers.js";
|
||||||
|
t.eq(OpenLayers._getScriptLocation(), "../lib/", "not fooled by bogus paths");
|
||||||
|
|
||||||
|
}
|
||||||
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user