Applying a reworked version of #768. The benefits of this are largely
maintenance related: this cleans up a global flag (_OPENLAYERS_SFL_), replacing it with something in the OpenLayers namespace, and adds documentation/comments to the code here that weren't before. Approved by El Chairman Uz. git-svn-id: http://svn.openlayers.org/trunk/openlayers@3543 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
+47
-32
@@ -2,56 +2,69 @@
|
||||
* See http://svn.openlayers.org/trunk/openlayers/repository-license.txt
|
||||
* for the full text of the license. */
|
||||
|
||||
/* @requires OpenLayers/BaseTypes.js
|
||||
/*
|
||||
* @requires OpenLayers/BaseTypes.js
|
||||
*/
|
||||
|
||||
////
|
||||
/// This blob sucks in all the files in uncompressed form for ease of use
|
||||
///
|
||||
(function() {
|
||||
/**
|
||||
* Before creating the OpenLayers namespace, check to see if
|
||||
* OpenLayers.singleFile is true. This occurs if the
|
||||
* OpenLayers/SingleFile.js script is included before this one - as is the
|
||||
* case with single file builds.
|
||||
*/
|
||||
var singleFile = (typeof OpenLayers == "object" && OpenLayers.singleFile);
|
||||
/**
|
||||
* The OpenLayers object provides a namespace for all things OpenLayers
|
||||
* @type Object
|
||||
*/
|
||||
OpenLayers = {
|
||||
|
||||
OpenLayers = new Object();
|
||||
/**
|
||||
* @type String
|
||||
* @private
|
||||
*/
|
||||
_scriptName: (!singleFile) ? "lib/OpenLayers.js" : "OpenLayers.js",
|
||||
|
||||
OpenLayers._scriptName = (
|
||||
typeof(_OPENLAYERS_SFL_) == "undefined" ? "lib/OpenLayers.js"
|
||||
: "OpenLayers.js" );
|
||||
|
||||
OpenLayers._getScriptLocation = function () {
|
||||
/**
|
||||
* @type String
|
||||
* @returns Path to this script
|
||||
* @private
|
||||
*/
|
||||
_getScriptLocation: function () {
|
||||
var scriptLocation = "";
|
||||
var SCRIPT_NAME = OpenLayers._scriptName;
|
||||
var scriptName = OpenLayers._scriptName;
|
||||
|
||||
var scripts = document.getElementsByTagName('script');
|
||||
for (var i = 0; i < scripts.length; i++) {
|
||||
var src = scripts[i].getAttribute('src');
|
||||
if (src) {
|
||||
var index = src.lastIndexOf(SCRIPT_NAME);
|
||||
var index = src.lastIndexOf(scriptName);
|
||||
// is it found, at the end of the URL?
|
||||
if ((index > -1) && (index + SCRIPT_NAME.length == src.length)) {
|
||||
scriptLocation = src.slice(0, -SCRIPT_NAME.length);
|
||||
if ((index > -1) && (index + scriptName.length == src.length)) {
|
||||
scriptLocation = src.slice(0, -scriptName.length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return scriptLocation;
|
||||
}
|
||||
|
||||
/*
|
||||
`_OPENLAYERS_SFL_` is a flag indicating this file is being included
|
||||
in a Single File Library build of the OpenLayers Library.
|
||||
|
||||
When we are *not* part of a SFL build we dynamically include the
|
||||
OpenLayers library code.
|
||||
|
||||
When we *are* part of a SFL build we do not dynamically include the
|
||||
OpenLayers library code as it will be appended at the end of this file.
|
||||
*/
|
||||
if (typeof(_OPENLAYERS_SFL_) == "undefined") {
|
||||
/*
|
||||
The original code appeared to use a try/catch block
|
||||
to avoid polluting the global namespace,
|
||||
we now use a anonymous function to achieve the same result.
|
||||
}
|
||||
};
|
||||
/**
|
||||
* OpenLayers.singleFile is a flag indicating this file is being included
|
||||
* in a Single File Library build of the OpenLayers Library.
|
||||
*
|
||||
* When we are *not* part of a SFL build we dynamically include the
|
||||
* OpenLayers library code.
|
||||
*
|
||||
* When we *are* part of a SFL build we do not dynamically include the
|
||||
* OpenLayers library code as it will be appended at the end of this file.
|
||||
*/
|
||||
(function() {
|
||||
var jsfiles=new Array(
|
||||
if(!singleFile) {
|
||||
var jsfiles = new Array(
|
||||
"OpenLayers/BaseTypes.js",
|
||||
"OpenLayers/Util.js",
|
||||
"OpenLayers/Console.js",
|
||||
@@ -150,6 +163,8 @@ if (typeof(_OPENLAYERS_SFL_) == "undefined") {
|
||||
"OpenLayers/Control/EditingToolbar.js"
|
||||
); // etc.
|
||||
|
||||
|
||||
|
||||
var allScriptTags = "";
|
||||
var host = OpenLayers._getScriptLocation() + "lib/";
|
||||
|
||||
@@ -167,6 +182,6 @@ if (typeof(_OPENLAYERS_SFL_) == "undefined") {
|
||||
}
|
||||
}
|
||||
if (allScriptTags) document.write(allScriptTags);
|
||||
})();
|
||||
}
|
||||
}
|
||||
})();
|
||||
OpenLayers.VERSION_NUMBER="$Revision$";
|
||||
|
||||
Reference in New Issue
Block a user