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:
crschmidt
2007-06-29 15:31:09 +00:00
parent 6aea8da115
commit f1c61fd0d6
+47 -32
View File
@@ -2,56 +2,69 @@
* See http://svn.openlayers.org/trunk/openlayers/repository-license.txt * See http://svn.openlayers.org/trunk/openlayers/repository-license.txt
* for the full text of the license. */ * 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 /// 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" * @type String
: "OpenLayers.js" ); * @returns Path to this script
* @private
OpenLayers._getScriptLocation = function () { */
_getScriptLocation: function () {
var scriptLocation = ""; var scriptLocation = "";
var SCRIPT_NAME = OpenLayers._scriptName; var scriptName = OpenLayers._scriptName;
var scripts = document.getElementsByTagName('script'); var scripts = document.getElementsByTagName('script');
for (var i = 0; i < scripts.length; i++) { for (var i = 0; i < scripts.length; i++) {
var src = scripts[i].getAttribute('src'); var src = scripts[i].getAttribute('src');
if (src) { if (src) {
var index = src.lastIndexOf(SCRIPT_NAME); var index = src.lastIndexOf(scriptName);
// is it found, at the end of the URL? // is it found, at the end of the URL?
if ((index > -1) && (index + SCRIPT_NAME.length == src.length)) { if ((index > -1) && (index + scriptName.length == src.length)) {
scriptLocation = src.slice(0, -SCRIPT_NAME.length); scriptLocation = src.slice(0, -scriptName.length);
break; break;
} }
} }
} }
return scriptLocation; return scriptLocation;
} }
};
/* /**
`_OPENLAYERS_SFL_` is a flag indicating this file is being included * OpenLayers.singleFile is a flag indicating this file is being included
in a Single File Library build of the OpenLayers Library. * in a Single File Library build of the OpenLayers Library.
*
When we are *not* part of a SFL build we dynamically include the * When we are *not* part of a SFL build we dynamically include the
OpenLayers library code. * OpenLayers library code.
*
When we *are* part of a SFL build we do not dynamically include the * 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. * 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.
*/ */
(function() { if(!singleFile) {
var jsfiles=new Array( var jsfiles = new Array(
"OpenLayers/BaseTypes.js", "OpenLayers/BaseTypes.js",
"OpenLayers/Util.js", "OpenLayers/Util.js",
"OpenLayers/Console.js", "OpenLayers/Console.js",
@@ -150,6 +163,8 @@ if (typeof(_OPENLAYERS_SFL_) == "undefined") {
"OpenLayers/Control/EditingToolbar.js" "OpenLayers/Control/EditingToolbar.js"
); // etc. ); // etc.
var allScriptTags = ""; var allScriptTags = "";
var host = OpenLayers._getScriptLocation() + "lib/"; var host = OpenLayers._getScriptLocation() + "lib/";
@@ -167,6 +182,6 @@ if (typeof(_OPENLAYERS_SFL_) == "undefined") {
} }
} }
if (allScriptTags) document.write(allScriptTags); if (allScriptTags) document.write(allScriptTags);
})(); }
} })();
OpenLayers.VERSION_NUMBER="$Revision$"; OpenLayers.VERSION_NUMBER="$Revision$";