[fusion-commits] r1382 - in trunk: lib widgets

svn_fusion at osgeo.org svn_fusion at osgeo.org
Wed Apr 23 10:29:41 EDT 2008


Author: madair
Date: 2008-04-23 10:29:40 -0400 (Wed, 23 Apr 2008)
New Revision: 1382

Added:
   trunk/lib/EventMgr.js
Modified:
   trunk/lib/ApplicationDefinition.js
   trunk/lib/fusion.js
   trunk/widgets/PanOnClick.js
   trunk/widgets/PanQuery.js
   trunk/widgets/SelectRadiusValue.js
Log:
re #5: changes to allow existing apps to work properly 
and prep for a single file build (copied OL bootstrapping method)

Modified: trunk/lib/ApplicationDefinition.js
===================================================================
--- trunk/lib/ApplicationDefinition.js	2008-04-21 20:02:54 UTC (rev 1381)
+++ trunk/lib/ApplicationDefinition.js	2008-04-23 14:29:40 UTC (rev 1382)
@@ -23,14 +23,6 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
-OpenLayers.Util.extend(Fusion, Fusion.Lib.EventMgr);
-//Fusion.Lib.EventMgr.initialize.apply(Fusion, []);
-
-Fusion.Event.FUSION_INITIALIZED = Fusion.Event.lastEventId++;
-Fusion.Event.FUSION_ERROR = Fusion.Event.lastEventId++;
-Fusion.registerEventID(Fusion.Event.FUSION_INITIALIZED);
-Fusion.registerEventID(Fusion.Event.FUSION_ERROR);
-
 /****************************************************************************
  * Class: Fusion.Lib.ApplicationDefinition
  *

Added: trunk/lib/EventMgr.js
===================================================================
--- trunk/lib/EventMgr.js	                        (rev 0)
+++ trunk/lib/EventMgr.js	2008-04-23 14:29:40 UTC (rev 1382)
@@ -0,0 +1,127 @@
+/**
+ * Class: Fusion.Lib.EventMgr
+ *
+ * an internal class for managing generic events.  Classes that wish to
+ * publish and trigger events that other objects can listen for need to
+ * inherit from Fusion.Lib.EventMgr.
+ *
+ * To publish an event, call registerEventID with some unique numeric or
+ * string value.  Other objects can then call registerForEvent with the
+ * eventID and a function to call when the event is triggered.
+ *
+ * To trigger an event, call triggerEvent with the eventID and any additional
+ * arguments that should be passed to listeners.
+ */
+Fusion.Lib.EventMgr = OpenLayers.Class({
+    /* an array of eventIDs and associated listener functions */
+    events : null,
+    
+    initialize: function() { if (!this.events) {this.events = []; }},
+
+    /**
+     * Method: destroy
+     *
+     */
+    destroy: function() {
+       this.events = []; 
+    },
+    
+    /**
+     * register an event ID so that others can use it.  This should really
+     * only be called by 'this' object.
+     *
+     * @param eventID the event ID to register
+     */
+    registerEventID : function( eventID ) {
+        if (!this.events) {this.events = []; }
+        if (!eventID) {
+            Fusion.reportError(new Fusion.Error(Fusion.Error.WARNING, 
+                          OpenLayers.i18n('regsiterEventError')));
+        }
+        var ev = new String(eventID);
+        if (!this.events[eventID]) {
+            this.events[eventID] = [];
+        }
+    },
+
+    /**
+     * register for receiving a callback when an event happens. If you
+     * want the callback to be a method on an instance of some object, 
+     * use the OpenLayers.Function.bind() function as in:
+     *
+     * otherObj.registerForEvent(SOME_EVENT, OpenLayers.Function.bind(this.callback,this));
+     *
+     * @param eventID the event ID to register for
+     * @param f the function to call when the event happens.  
+     */
+    registerForEvent : function(eventID, f) {
+        var ev = new String(eventID);
+        this.events[eventID].push(f);
+    },
+
+    /**
+     * deregister a callback function when you no longer want to
+     * recieve it.  Note that if you used bind() when registering,
+     * you need to pass EXACTLY THE SAME FUNCTION when
+     * deregistering.  Typically, this means you need to assign the
+     * result of bind() to an instance variable and pass that instance
+     * variable to both registerForEvent and deregisterForEvent.
+     *
+     * For instance:
+     *
+     * this.callbackFn = OpenLayers.Function.bind(this.callback, this);
+     * otherObj.registerForEvent(SOME_EVENT, this.callbackFn);
+     * otherObj.deregisterForEvent(SOME_EVENT, this.callbackFn);
+     *
+     * @param eventID the event ID to deregister
+     * @param f the function that used when registering.
+     */
+    deregisterForEvent : function( eventID, f ) {
+        var ev = new String(eventID);
+        var bResult = false;
+        if (!this.events[eventID]){
+            return false;
+        }
+
+        for (var i=0;i<this.events[eventID].length;i++) {
+            if (this.events[eventID][i]== f) {
+                this.events[eventID].splice(i,1);
+                bResult = true;
+            }
+        }
+        return bResult;
+    },       
+
+    /**
+     * trigger an event and call all registered listener functions.
+     * This is intended to be called by 'this'.  The eventID param
+     * is mandatory.  Any additional arguments will be passed to the
+     * listener function.
+     *
+     * @param eventID the event ID to trigger
+     */
+    triggerEvent : function( eventID ) {
+        var ev = new String(eventID);
+        if (!this.events || !this.events[eventID]) {
+            return false;
+        }
+
+        for (var i=0; i<this.events[eventID].length; i++) {
+            this.events[eventID][i].apply(null, arguments);
+        }
+        return true;
+    }
+});
+        
+//window.Fusion = OpenLayers.Class(Fusion.Lib.EventMgr, Fusion.prototype);
+//OpenLayers.Util.extend(Fusion, Fusion.Lib.EventMgr.prototype);
+Fusion.events = [];
+Fusion.registerEventID = Fusion.Lib.EventMgr.prototype.registerEventID;
+Fusion.registerForEvent = Fusion.Lib.EventMgr.prototype.registerForEvent;
+Fusion.triggerEvent = Fusion.Lib.EventMgr.prototype.triggerEvent;
+
+Fusion.Event.FUSION_INITIALIZED = Fusion.Event.lastEventId++;
+Fusion.Event.FUSION_ERROR = Fusion.Event.lastEventId++;
+Fusion.registerEventID(Fusion.Event.FUSION_INITIALIZED);
+Fusion.registerEventID(Fusion.Event.FUSION_ERROR);
+        

Modified: trunk/lib/fusion.js
===================================================================
--- trunk/lib/fusion.js	2008-04-21 20:02:54 UTC (rev 1381)
+++ trunk/lib/fusion.js	2008-04-23 14:29:40 UTC (rev 1382)
@@ -29,102 +29,50 @@
 var Jx = {};
 
 /**
- * declare global namespace object for Fusion library to use
- */
-var Fusion = {};
-
-/* set to true if you want to use the compressed version of the core files,
- * currently this saves about 100kb and quite a few HTTP connections so it is
- * faster, but less convenient if you want to debug one of the core files
- */
-Fusion.useCompressed = false;
-
-if (Fusion.useCompressed) {
-    Fusion.coreScripts = ['lib/OpenLayers/OpenLayers.js',
-                        'jx/lib/jx_compressed.js',
-                        'lib/fusion-compressed.js',
-                        'lib/excanvas/excanvas-compressed.js'];
-} else {
-    Fusion.coreScripts = ['lib/OpenLayers/OpenLayers.js',
-                        'jx/lib/jx_combined.js',
-                        'lib/excanvas/excanvas-compressed.js',
-                        'lib/Error.js',
-                        'lib/ApplicationDefinition.js',
-                        'lib/MGBroker.js',
-                        'lib/Widget.js',
-                        'lib/ButtonBase.js',
-                        'lib/MenuBase.js',
-                        'lib/ButtonTool.js',
-                        'lib/CanvasTool.js',
-                        'lib/ClickTool.js',
-                        'lib/RectTool.js',
-                        'lib/Map.js',
-                        'lib/Search.js',
-                        'text/en/strings.json'];
-}
-
-/* bootstrap function that gets everything Fusion needs, loaded */
-Fusion.bootstrap = function() {
-    //determine the language to use and add resource bundles to be loaded to the core scripts
-    var locale = navigator.language ?
-                  navigator.language.substring(0,2):    //e.g. en-CA becomes just en                  
-                  navigator.userLanguage.substring(0,2);//only use the prefix part for now, 
-    var s=window.location.search.toLowerCase();
-    var idx = s.indexOf('locale=');
-    if (idx>0) {
-      locale = s.substring(idx+7,idx+9);
-    }
-    if ( locale!='en' ) {
-      Fusion.coreScripts.push('lib/OpenLayers/Lang/'+locale+'.js');
-      Fusion.coreScripts.push('text/'+locale+'/strings.json');
-    }
-    window._FusionLocale = locale;
-
-    var aScripts = document.getElementsByTagName('SCRIPT');
-    var gszFusionURL = '';
-    for (var i=0; i<aScripts.length; i++) {
-        var s = aScripts[i].src;
-        var n = s.indexOf('lib/fusion.js');
-        if (n != -1) {
-            gszFusionURL = s.substring(0,n);
-            FusionScriptObject = aScripts[i];
-            /* import the compressed version of jx and its CSS */
-            Jx.baseURL = gszFusionURL + 'jx/';
-            Jx.COMBINED_CSS = true;
-            for (var j=0; j<Fusion.coreScripts.length; j++) {
-                document.write('<script type="text/javascript" src="'+gszFusionURL+Fusion.coreScripts[j]+'"></script>');
-            }
-            break;
-        }
-    }
-};
-
-Fusion.bootstrap();
-
-/**
  * reverse inheritance logic to allow for delayed loading of dependencies.
  * Under normal circumstances, Object.extend from Prototype would be used,
  * but in Fusion, widget code is loaded before base class code and the
  * extend function won't work until all the base class code is available.
+ * DEPRECATED
  */
 Object.inheritFrom = function(destination, source, args) {
-    for (property in source) {
+    var parent;
+    if(typeof source == "function") {
+        // get the prototype of the superclass
+        parent = source.prototype;
+    } else {
+        // in this case we're extending with the prototype
+        parent = source;
+    }
+    for (property in parent) {
         if (typeof destination[property] == 'undefined') {
-            destination[property] = source[property];
+            destination[property] = parent[property];
         }
     }
-    source.initialize.apply(destination, args);
+    parent.initialize.apply(destination, args);
 };
 
-/* now we can safely replace the global fusion object */
-/***************************************************************************
-* Class: Fusion
-* 
-* The main global object for Fusion applications.
-***************************************************************************/
+(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 Fusion == "object" && Fusion.singleFile);
+    
+    /* set to true if you want to use the compressed version of the core files,
+     * currently this saves about 100kb and quite a few HTTP connections so it is
+     * faster, but less convenient if you want to debug one of the core files
+     */
+    var useCompressed = false;
 
-Fusion = {
-
+    /**
+     * Namespace: Fusion
+     * declare global namespace object for Fusion library to use
+     */
+    window.Fusion = {
+        
 /***************************************************************************
 * Class: Fusion.Tools
 * 
@@ -633,6 +581,11 @@
         if (!options.contentType) {
           options.contentType = 'application/x-www-form-urlencoded';
         }
+        if (options.parameters && typeof options.parameters == 'string') {
+          if (options.parameters.indexOf('?') < 0) {
+              options.parameters = '?' + options.parameters;
+          }
+        }
         new OpenLayers.Ajax.Request( url, options);
     },
     
@@ -954,7 +907,7 @@
     addWidgetStyleSheet: function(url) {
         var lnk = document.createElement('link');
         var hd = document.getElementsByTagName('HEAD')[0];
-        hd.insertBefore(lnk, FusionScriptObject);
+        hd.insertBefore(lnk, Fusion._scriptObject);
         lnk.type = 'text/css';
         lnk.rel='stylesheet';
         lnk.href = Fusion.getFusionURL()+url;
@@ -984,121 +937,114 @@
         } else {
             return '';
         }
-    }
-};
-
-/**
- * Class: Fusion.Lib.EventMgr
- *
- * an internal class for managing generic events.  Classes that wish to
- * publish and trigger events that other objects can listen for need to
- * inherit from Fusion.Lib.EventMgr.
- *
- * To publish an event, call registerEventID with some unique numeric or
- * string value.  Other objects can then call registerForEvent with the
- * eventID and a function to call when the event is triggered.
- *
- * To trigger an event, call triggerEvent with the eventID and any additional
- * arguments that should be passed to listeners.
- */
-//Fusion.Lib.EventMgr = Class.create();
-Fusion.Lib.EventMgr = {
-    /* an array of eventIDs and associated listener functions */
-    events : null,
+    },
     
-    //initialize: function() { if (!this.events) {this.events = []; }},
+            /**
+         * Property: _scriptName
+         * {String} Relative path of this script.
+         */
+        _scriptName: (!singleFile) ? "lib/fusion.js" : "fusion.js",
 
-    /**
-     * Method: destroy
-     *
-     */
-    destroy: function() {
-       this.events = []; 
-    },
+        /**
+         * Function: _getScriptLocation
+         * Return the path to this script.
+         *
+         * Returns:
+         * {String} Path to this script
+         */
+        _getScriptLocation: function () {
+            var scriptLocation = "";
+            var scriptName = Fusion._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(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);
+                        Fusion._scriptObject = scripts[i];
+                        break;
+                    }
+                }
+            }
+            return scriptLocation;
+         }
+    };
+
+    var host = Fusion._getScriptLocation();    
+    Jx.baseURL = host + 'jx/';
+    Jx.COMBINED_CSS = true;
     
-    /**
-     * register an event ID so that others can use it.  This should really
-     * only be called by 'this' object.
-     *
-     * @param eventID the event ID to register
-     */
-    registerEventID : function( eventID ) {
-        if (!eventID) {
-            Fusion.reportError(new Fusion.Error(Fusion.Error.WARNING, 
-                          OpenLayers.i18n('regsiterEventError')));
+    //determine the language to use and add resource bundles to be loaded to the core scripts
+    var locale = navigator.language ?
+                  navigator.language.substring(0,2):    //e.g. en-CA becomes just en                  
+                  navigator.userLanguage.substring(0,2);//only use the prefix part for now, 
+    var s = window.location.search.toLowerCase();
+    var idx = s.indexOf('locale=');
+    if (idx>0) {
+      locale = s.substring(idx+7,idx+9);
+    }
+    window._FusionLocale = locale;
+    
+    if (!singleFile) {
+        if (useCompressed) {
+            var coreScripts = ['lib/OpenLayers/OpenLayers.js',
+                                'jx/lib/jx_compressed.js',
+                                'lib/fusion-compressed.js',
+                                'lib/excanvas/excanvas-compressed.js'];
+        } else {
+            var coreScripts = ['lib/OpenLayers/OpenLayers.js',
+                                'jx/lib/jx_combined.js',
+                                'lib/excanvas/excanvas-compressed.js',
+                                'lib/EventMgr.js',
+                                'lib/Error.js',
+                                'lib/ApplicationDefinition.js',
+                                'lib/MGBroker.js',
+                                'lib/Widget.js',
+                                'lib/ButtonBase.js',
+                                'lib/MenuBase.js',
+                                'lib/ButtonTool.js',
+                                'lib/CanvasTool.js',
+                                'lib/ClickTool.js',
+                                'lib/RectTool.js',
+                                'lib/Map.js',
+                                'lib/Search.js',
+                                'text/en/strings.json'];
         }
-        if (!this.events) {this.events = []; }
-        var ev = new String(eventID);
-        if (!this.events[eventID]) {
-            this.events[eventID] = [];
+        
+        if (locale != 'en') {
+            coreScripts.push('lib/OpenLayers/Lang/'+locale+'.js');
+            coreScripts.push('text/'+locale+'/strings.json');
         }
-    },
-
-    /**
-     * register for receiving a callback when an event happens. If you
-     * want the callback to be a method on an instance of some object, 
-     * use the OpenLayers.Function.bind() function as in:
-     *
-     * otherObj.registerForEvent(SOME_EVENT, OpenLayers.Function.bind(this.callback,this));
-     *
-     * @param eventID the event ID to register for
-     * @param f the function to call when the event happens.  
-     */
-    registerForEvent : function(eventID, f) {
-        var ev = new String(eventID);
-        this.events[eventID].push(f);
-    },
-
-    /**
-     * deregister a callback function when you no longer want to
-     * recieve it.  Note that if you used bind() when registering,
-     * you need to pass EXACTLY THE SAME FUNCTION when
-     * deregistering.  Typically, this means you need to assign the
-     * result of bind() to an instance variable and pass that instance
-     * variable to both registerForEvent and deregisterForEvent.
-     *
-     * For instance:
-     *
-     * this.callbackFn = OpenLayers.Function.bind(this.callback, this);
-     * otherObj.registerForEvent(SOME_EVENT, this.callbackFn);
-     * otherObj.deregisterForEvent(SOME_EVENT, this.callbackFn);
-     *
-     * @param eventID the event ID to deregister
-     * @param f the function that used when registering.
-     */
-    deregisterForEvent : function( eventID, f ) {
-        var ev = new String(eventID);
-        var bResult = false;
-        if (!this.events[eventID]){
-            return false;
+        
+        var agent = navigator.userAgent;
+        var docWrite = (agent.match("MSIE") || agent.match("Safari"));
+        if (docWrite) {
+            var allScriptTags = new Array(coreScripts.length);
         }
-
-        for (var i=0;i<this.events[eventID].length;i++) {
-            if (this.events[eventID][i]== f) {
-                this.events[eventID].splice(i,1);
-                bResult = true;
+        for (var i = 0; i < coreScripts.length; i++) {
+            if (docWrite) {
+                allScriptTags[i] = "<script src='" + host + coreScripts[i] +
+                                   "'></script>"; 
+            } else {
+                var s = document.createElement("script");
+                s.src = host + coreScripts[i];
+                var h = document.getElementsByTagName("head").length ? 
+                           document.getElementsByTagName("head")[0] : 
+                           document.body;
+                h.appendChild(s);
             }
         }
-        return bResult;
-    },       
-
-    /**
-     * trigger an event and call all registered listener functions.
-     * This is intended to be called by 'this'.  The eventID param
-     * is mandatory.  Any additional arguments will be passed to the
-     * listener function.
-     *
-     * @param eventID the event ID to trigger
-     */
-    triggerEvent : function( eventID ) {
-        var ev = new String(eventID);
-        if (!this.events || !this.events[eventID]) {
-            return false;
+        if (docWrite) {
+            document.write(allScriptTags.join(""));
         }
-
-        for (var i=0; i<this.events[eventID].length; i++) {
-            this.events[eventID][i].apply(null, arguments);
-        }
-        return true;
     }
-};
+})();
+

Modified: trunk/widgets/PanOnClick.js
===================================================================
--- trunk/widgets/PanOnClick.js	2008-04-21 20:02:54 UTC (rev 1381)
+++ trunk/widgets/PanOnClick.js	2008-04-23 14:29:40 UTC (rev 1382)
@@ -31,7 +31,7 @@
  * **********************************************************************/
 
 
-Fusion.Widget.Pan = OpenLayers.Class(Fusion.Widget, Fusion.Tool.ButtonBase, Fusion.Tool.ButtonBase,
+Fusion.Widget.PanOnClick = OpenLayers.Class(Fusion.Widget, Fusion.Tool.ButtonBase, 
 {
     fPercent: null,
     nDeltaX: null,

Modified: trunk/widgets/PanQuery.js
===================================================================
--- trunk/widgets/PanQuery.js	2008-04-21 20:02:54 UTC (rev 1381)
+++ trunk/widgets/PanQuery.js	2008-04-23 14:29:40 UTC (rev 1382)
@@ -31,9 +31,9 @@
  * 
  * **********************************************************************/
 
-Fusion.require('widgets/Pan.js');
+//Fusion.require('widgets/Pan.js');
 
-Fusion.Widget.PanQuery = OpenLayers.Class(Fusion.Widget, Fusion.Tool.ButtonBase, Fusion.Widget.Pan,
+Fusion.Widget.PanQuery = OpenLayers.Class(Fusion.Widget, Fusion.Tool.ButtonBase,
 {
     selectionType: 'INTERSECTS',
     nTolerance: 3,
@@ -43,7 +43,8 @@
 
         Fusion.Widget.prototype.initialize.apply(this, [widgetTag, true]);
         Fusion.Tool.ButtonBase.prototype.initialize.apply(this, []);
-        Fusion.Widget.Pan.prototype.initialize.apply(this, [widgetTag]);
+        //OpenLayers.Util.extend(this, Fusion.Widget.Pan.prototype);
+        //Fusion.Widget.Pan.prototype.initialize.apply(this, [widgetTag]);
 
         this.control = new OpenLayers.Control.DragPan();
         this.getMap().oMapOL.addControl(this.control);
@@ -107,6 +108,29 @@
         Event.stop(e);
     },    
     
+    /**
+     * called when the button is clicked by the Fusion.Tool.ButtonBase widget
+     */
+    activateTool : function() {
+        /*console.log('Pan.activateTool');*/
+        this.getMap().activateWidget(this);
+    },
+    
+    activate : function() {
+        this.control.activate();
+        this.getMap().setCursor(this.cursorNormal);
+        /*button*/
+        this._oButton.activateTool();
+    },
+    
+    deactivate: function() {
+        /*console.log('Pan.deactivate');*/
+        this.control.deactivate();
+        this.getMap().setCursor('auto');
+        /*icon button*/
+        this._oButton.deactivateTool();
+    },
+    
     setParameter : function(param, value) {
         if (param == "Tolerance" && value > 0) {
             this.nTolerance = value;

Modified: trunk/widgets/SelectRadiusValue.js
===================================================================
--- trunk/widgets/SelectRadiusValue.js	2008-04-21 20:02:54 UTC (rev 1381)
+++ trunk/widgets/SelectRadiusValue.js	2008-04-23 14:29:40 UTC (rev 1382)
@@ -48,8 +48,8 @@
         this.label = json.Label ? json.Label[0] : '';
         this.className = json.ClassName ? json.ClassName[0] : '';
         
-        this.getMap().registerForEvent(Fusion.Event.MAP_LOADED, this.mapLoaded.bind(this));
-        this.getMap().registerForEvent(Fusion.Event.MAP_EXTENTS_CHANGED, this.mapExtentsChanged.bind(this));
+        this.getMap().registerForEvent(Fusion.Event.MAP_LOADED, OpenLayers.Function.bind(this.mapLoaded, this));
+        this.getMap().registerForEvent(Fusion.Event.MAP_EXTENTS_CHANGED, OpenLayers.Function.bind(this.mapExtentsChanged, this));
     },
     
     draw: function() {
@@ -67,9 +67,6 @@
         /* put into page */
         this.domObj.appendChild(this.domLabel);
         Event.observe(this.input, 'blur', OpenLayers.Function.bind(this.onBlur, this));
-        this.getMap().registerForEvent(Fusion.Event.MAP_LOADED, OpenLayers.Function.bind(this.mapLoaded, this));
-        this.getMap().registerForEvent(Fusion.Event.MAP_EXTENTS_CHANGED, OpenLayers.Function.bind(this.mapExtentsChanged, this));
-        
     },
     
     mapLoaded: function() {



More information about the fusion-commits mailing list