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:
Tim Schaub
2009-03-18 15:57:41 +00:00
parent 6708f691e2
commit eb03ccc02d
2 changed files with 23 additions and 24 deletions

View File

@@ -37,28 +37,22 @@
* {String} Path to this script
*/
_getScriptLocation: function () {
var scriptLocation = "";
var scriptName = OpenLayers._scriptName;
var scriptLocation = "";
var isOL = new RegExp("(^|(.*?\\/))(" + OpenLayers._scriptName + ")(\\?|$)");
var scripts = document.getElementsByTagName('script');
for (var i=0, len=scripts.length; i<len; i++) {
var src = scripts[i].getAttribute('src');
if (src) {
var index = src.lastIndexOf(scriptName);
// set path length for src up to a query string
var pathLength = src.lastIndexOf('?');
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);
var match = src.match(isOL);
if(match) {
scriptLocation = match[1];
break;
}
}
}
return scriptLocation;
}
}
};
/**
* OpenLayers.singleFile is a flag indicating this file is being included