source: sandbox/opengeo/geoexplorer/lib/GeoExt.js @ 258

Last change on this file since 258 was 258, checked in by tschaub, 9 years ago

logging sandbox modifications

File size: 3.5 KB
Line 
1/* Copyright (C) 2008-2009 The Open Source Geospatial Foundation ¹
2 * Published under the BSD license.
3 * See http://geoext.org/svn/geoext/core/trunk/license.txt for the full text
4 * of the license.
5 *
6 * ¹ pending approval */
7
8/*
9 * The code in this file is based on code taken from OpenLayers.
10 *
11 * Copyright (c) 2006-2007 MetaCarta, Inc., published under the Clear BSD
12 * license.  See http://svn.openlayers.org/trunk/openlayers/license.txt for the
13 * full text of the license.
14 */
15 
16(function() {
17
18    /**
19     * Check to see if GeoExt.singleFile is true. It is true if the
20     * GeoExt/SingleFile.js is included before this one, as it is
21     * the case in single file builds.
22     */
23    var singleFile = (typeof GeoExt == "object" && GeoExt.singleFile);
24
25    /**
26     * The relative path of this script.
27     */
28    var scriptName = singleFile ? "GeoExt.js" : "lib/GeoExt.js";
29
30    /**
31     * Function returning the path of this script.
32     */
33    var getScriptLocation = function() {
34        var scriptLocation = "";
35        var scripts = document.getElementsByTagName('script');
36        for(var i=0, len=scripts.length; i<len; i++) {
37            var src = scripts[i].getAttribute('src');
38            if(src) {
39                var index = src.lastIndexOf(scriptName);
40                // set path length for src up to a query string
41                var pathLength = src.lastIndexOf('?');
42                if(pathLength < 0) {
43                    pathLength = src.length;
44                }
45                // is it found, at the end of the URL?
46                if((index > -1) && (index + scriptName.length == pathLength)) {
47                    scriptLocation = src.slice(0, pathLength - scriptName.length);
48                    break;
49                }
50            }
51        }
52        return scriptLocation;
53    };
54
55    /**
56     * If GeoExt.singleFile is false then the JavaScript files in the jsfiles
57     * array are autoloaded.
58     */
59    if(!singleFile) {
60        var jsfiles = new Array(
61            "GeoExt/data/FeatureReader.js",
62            "GeoExt/data/FeatureStoreMediator.js",
63            "GeoExt/data/LayerStore.js",
64            "GeoExt/data/LayerRecord.js",
65            "GeoExt/data/LayerStoreMediator.js",
66            "GeoExt/data/ProtocolProxy.js",
67            "GeoExt/data/WMSCapabilitiesReader.js",
68            "GeoExt/data/WMSCapabilitiesStore.js",
69            "GeoExt/widgets/MapPanel.js",
70            "GeoExt/widgets/tree/TristateCheckboxNode.js",
71            "GeoExt/widgets/tree/TristateCheckboxNodeUI.js",
72            "GeoExt/widgets/tree/LayerNode.js",
73            "GeoExt/widgets/tree/LayerContainer.js"
74        );
75
76        var agent = navigator.userAgent;
77        var docWrite = (agent.match("MSIE") || agent.match("Safari"));
78        if(docWrite) {
79            var allScriptTags = new Array(jsfiles.length);
80        }
81        var host = getScriptLocation() + "lib/";   
82        for (var i=0, len=jsfiles.length; i<len; i++) {
83            if (docWrite) {
84                allScriptTags[i] = "<script src='" + host + jsfiles[i] +
85                                   "'></script>";
86            } else {
87                var s = document.createElement("script");
88                s.src = host + jsfiles[i];
89                var h = document.getElementsByTagName("head").length ?
90                           document.getElementsByTagName("head")[0] :
91                           document.body;
92                h.appendChild(s);
93            }
94        }
95        if (docWrite) {
96            document.write(allScriptTags.join(""));
97        }
98    }
99})();
Note: See TracBrowser for help on using the repository browser.