root/core/trunk/lib/GeoExt.js

Revision 238, 3.2 kB (checked in by ahocevar, 1 year ago)

Added MapPanel, LayerRecord and LayerStore with examples and tests; also contains license.txt file. Big thanks to sbenthall and tcoulter for their original input, to elemoine for the good discussion today about the LayerStoreMixin and his patience despite my angryness, to tschaub for the constructive comments, and finally to everyone who participated in the discussions on the mailing list about what we want this component to be. r=elemoine,tschaub (closes #4)

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/widgets/MapPanel.js"
68         );
69
70         var agent = navigator.userAgent;
71         var docWrite = (agent.match("MSIE") || agent.match("Safari"));
72         if(docWrite) {
73             var allScriptTags = new Array(jsfiles.length);
74         }
75         var host = getScriptLocation() + "lib/";   
76         for (var i=0, len=jsfiles.length; i<len; i++) {
77             if (docWrite) {
78                 allScriptTags[i] = "<script src='" + host + jsfiles[i] +
79                                    "'></script>";
80             } else {
81                 var s = document.createElement("script");
82                 s.src = host + jsfiles[i];
83                 var h = document.getElementsByTagName("head").length ?
84                            document.getElementsByTagName("head")[0] :
85                            document.body;
86                 h.appendChild(s);
87             }
88         }
89         if (docWrite) {
90             document.write(allScriptTags.join(""));
91         }
92     }
93 })();
Note: See TracBrowser for help on using the browser.