OpenLayers OpenLayers

Changeset 1587

Show
Ignore:
Timestamp:
10/05/06 10:46:45 (2 years ago)
Author:
sderle
Message:

Moved Event to OpenLayers.Event.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sandbox/crschmidt/noprototype/build/license.txt

    r1424 r1587  
    1414*/ 
    1515 
    16 /*  Prototype JavaScript framework, version 1.4.0 
     16/* Contains portions of Prototype.js: 
     17 * 
     18 * Prototype JavaScript framework, version 1.4.0 
    1719 *  (c) 2005 Sam Stephenson <sam@conio.net> 
    1820 * 
  • sandbox/crschmidt/noprototype/lib/OpenLayers/Ajax.js

    r1586 r1587  
    109109 
    110110OpenLayers.Ajax = { 
     111  emptyFunction: function () {}, 
     112 
    111113  getTransport: function() { 
    112114    return OpenLayers.Util.Try( 
     
    217219    var requestHeaders = 
    218220      ['X-Requested-With', 'XMLHttpRequest', 
    219        'X-Prototype-Version', Prototype.Version]; 
     221       'X-Prototype-Version', 'OpenLayers']; 
    220222 
    221223    if (this.options.method == 'post') { 
     
    272274        (this.options['on' + this.transport.status] 
    273275         || this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')] 
    274          || Prototype.emptyFunction)(transport, json); 
     276         || OpenLayers.Ajax.emptyFunction)(transport, json); 
    275277      } catch (e) { 
    276278        this.dispatchException(e); 
     
    282284 
    283285    try { 
    284       (this.options['on' + event] || Prototype.emptyFunction)(transport, json); 
     286      (this.options['on' + event] || OpenLayers.Ajax.emptyFunction)(transport, json); 
    285287      OpenLayers.Ajax.Responders.dispatch('on' + event, this, transport, json); 
    286288    } catch (e) { 
     
    290292    /* Avoid memory leak in MSIE: clean up the oncomplete event handler */ 
    291293    if (event == 'Complete') 
    292       this.transport.onreadystatechange = Prototype.emptyFunction; 
     294      this.transport.onreadystatechange = OpenLayers.Ajax.emptyFunction; 
    293295  }, 
    294296 
    295297  dispatchException: function(exception) { 
    296     (this.options.onException || Prototype.emptyFunction)(this, exception); 
     298    (this.options.onException || OpenLayers.Ajax.emptyFunction)(this, exception); 
    297299    OpenLayers.Ajax.Responders.dispatch('onException', this, exception); 
    298300  } 
  • sandbox/crschmidt/noprototype/lib/OpenLayers/Control/KeyboardDefaults.js

    r1586 r1587  
    2626     */ 
    2727    draw: function() { 
    28         Event.observe(document,  
     28        OpenLayers.Event.observe(document,  
    2929                      'keypress',  
    3030                      this.defaultKeyDown.bind(this)); 
     
    3636    defaultKeyDown: function (evt) { 
    3737        switch(evt.keyCode) { 
    38             case Event.KEY_LEFT: 
     38            case OpenLayers.Event.KEY_LEFT: 
    3939                this.map.pan(-50, 0); 
    4040                break; 
    41             case Event.KEY_RIGHT:  
     41            case OpenLayers.Event.KEY_RIGHT:  
    4242                this.map.pan(50, 0); 
    4343                break; 
    44             case Event.KEY_UP: 
     44            case OpenLayers.Event.KEY_UP: 
    4545                this.map.pan(0, -50); 
    4646                break; 
    47             case Event.KEY_DOWN: 
     47            case OpenLayers.Event.KEY_DOWN: 
    4848                this.map.pan(0, 50); 
    4949                break; 
  • sandbox/crschmidt/noprototype/lib/OpenLayers/Control/LayerSwitcher.js

    r1586 r1587  
    130130                inputElem.layer = layer; 
    131131                inputElem.control = this; 
    132                 Event.observe(inputElem, "mouseup",  
     132                OpenLayers.Event.observe(inputElem, "mouseup",  
    133133                              this.onInputClick.bindAsEventListener(inputElem)); 
    134134                 
     
    137137                labelSpan.innerHTML = layer.name; 
    138138                labelSpan.style.verticalAlign = (baseLayer) ? "bottom" : "baseline"; 
    139                 Event.observe(labelSpan, "click",  
     139                OpenLayers.Event.observe(labelSpan, "click",  
    140140                              this.onInputClick.bindAsEventListener(inputElem)); 
    141141                // create line break 
     
    178178            this.control.updateMap(); 
    179179        } 
    180         Event.stop(e); 
     180        OpenLayers.Event.stop(e); 
    181181    }, 
    182182     
     
    230230 
    231231        if (e != null) { 
    232             Event.stop(e);                                             
     232            OpenLayers.Event.stop(e);                                             
    233233        } 
    234234    }, 
     
    247247 
    248248        if (e != null) { 
    249             Event.stop(e);                                             
     249            OpenLayers.Event.stop(e);                                             
    250250        } 
    251251    }, 
     
    285285        this.div.style.backgroundColor = "transparent"; 
    286286     
    287         Event.observe(this.div, "mouseup",  
     287        OpenLayers.Event.observe(this.div, "mouseup",  
    288288                      this.mouseUp.bindAsEventListener(this)); 
    289         Event.observe(this.div, "click", 
     289        OpenLayers.Event.observe(this.div, "click", 
    290290                      this.ignoreEvent); 
    291         Event.observe(this.div, "mousedown", 
     291        OpenLayers.Event.observe(this.div, "mousedown", 
    292292                      this.mouseDown.bindAsEventListener(this)); 
    293         Event.observe(this.div, "dblclick", this.ignoreEvent); 
     293        OpenLayers.Event.observe(this.div, "dblclick", this.ignoreEvent); 
    294294 
    295295 
     
    318318        this.baseLayersDiv = document.createElement("div"); 
    319319        this.baseLayersDiv.style.paddingLeft = "10px"; 
    320         /*Event.observe(this.baseLayersDiv, "click",  
     320        /*OpenLayers.Event.observe(this.baseLayersDiv, "click",  
    321321                      this.onLayerClick.bindAsEventListener(this)); 
    322322        */ 
     
    368368        this.maximizeDiv.style.left = ""; 
    369369        this.maximizeDiv.style.display = "none"; 
    370         Event.observe(this.maximizeDiv,  
     370        OpenLayers.Event.observe(this.maximizeDiv,  
    371371                      "click",  
    372372                      this.maximizeControl.bindAsEventListener(this)); 
     
    387387        this.minimizeDiv.style.left = ""; 
    388388        this.minimizeDiv.style.display = "none"; 
    389         Event.observe(this.minimizeDiv,  
     389        OpenLayers.Event.observe(this.minimizeDiv,  
    390390                      "click",  
    391391                      this.minimizeControl.bindAsEventListener(this)); 
     
    400400     */ 
    401401    ignoreEvent: function(evt) { 
    402         Event.stop(evt); 
     402        OpenLayers.Event.stop(evt); 
    403403    }, 
    404404 
  • sandbox/crschmidt/noprototype/lib/OpenLayers/Control/MouseDefaults.js

    r1586 r1587  
    2222 
    2323        //register mousewheel events specifically on the window and document 
    24         Event.observe(window, "DOMMouseScroll",  
     24        OpenLayers.Event.observe(window, "DOMMouseScroll",  
    2525                      this.onWheelEvent.bindAsEventListener(this)); 
    26         Event.observe(window, "mousewheel",  
     26        OpenLayers.Event.observe(window, "mousewheel",  
    2727                      this.onWheelEvent.bindAsEventListener(this)); 
    28         Event.observe(document, "mousewheel",  
     28        OpenLayers.Event.observe(document, "mousewheel",  
    2929                      this.onWheelEvent.bindAsEventListener(this)); 
    3030    }, 
     
    4848     */ 
    4949    defaultClick: function (evt) { 
    50         if (!Event.isLeftClick(evt)) return; 
     50        if (!OpenLayers.Event.isLeftClick(evt)) return; 
    5151        var notAfterDrag = !this.performedDrag; 
    5252        this.performedDrag = false; 
     
    6060        var newCenter = this.map.getLonLatFromViewPortPx( evt.xy );  
    6161        this.map.setCenter(newCenter, this.map.zoom + 1); 
    62         Event.stop(evt); 
     62        OpenLayers.Event.stop(evt); 
    6363        return false; 
    6464    }, 
     
    6868    */ 
    6969    defaultMouseDown: function (evt) { 
    70         if (!Event.isLeftClick(evt)) return; 
     70        if (!OpenLayers.Event.isLeftClick(evt)) return; 
    7171        this.mouseDragStart = evt.xy.clone(); 
    7272        this.performedDrag  = false; 
     
    8787        } 
    8888        document.onselectstart=function() { return false; } 
    89         Event.stop(evt); 
     89        OpenLayers.Event.stop(evt); 
    9090    }, 
    9191 
     
    125125    */ 
    126126    defaultMouseUp: function (evt) { 
    127         if (!Event.isLeftClick(evt)) return; 
     127        if (!OpenLayers.Event.isLeftClick(evt)) return; 
    128128        if (this.zoomBox) { 
    129129            this.zoomBoxEnd(evt);     
     
    218218        // first determine whether or not the wheeling was inside the map 
    219219        var inMap = false; 
    220         var elem = Event.element(e); 
     220        var elem = OpenLayers.Event.element(e); 
    221221        while(elem != null) { 
    222222            if (this.map && elem == this.map.div) { 
     
    250250             
    251251            //only wheel the map, not the window 
    252             Event.stop(e); 
     252            OpenLayers.Event.stop(e); 
    253253        } 
    254254    }, 
  • sandbox/crschmidt/noprototype/lib/OpenLayers/Control/MouseToolbar.js

    r1586 r1587  
    6969        btn.events.register("mousedown", this, this.buttonDown);  
    7070        btn.events.register("mouseup", this, this.buttonUp);  
    71         btn.events.register("dblclick", this, Event.stop); 
     71        btn.events.register("dblclick", this, OpenLayers.Event.stop); 
    7272        btn.action = id; 
    7373        btn.title = title; 
     
    8484     */ 
    8585    buttonDown: function(evt) { 
    86         if (!Event.isLeftClick(evt)) return; 
     86        if (!OpenLayers.Event.isLeftClick(evt)) return; 
    8787        this.buttonClicked = evt.element.action; 
    88         Event.stop(evt); 
     88        OpenLayers.Event.stop(evt); 
    8989    }, 
    9090 
     
    9393     */ 
    9494    buttonUp: function(evt) { 
    95         if (!Event.isLeftClick(evt)) return; 
     95        if (!OpenLayers.Event.isLeftClick(evt)) return; 
    9696        if (this.buttonClicked != null) { 
    9797            if (this.buttonClicked == evt.element.action) { 
    9898                this.switchModeTo(evt.element.action); 
    9999            } 
    100             Event.stop(evt); 
     100            OpenLayers.Event.stop(evt); 
    101101            this.buttonClicked = null; 
    102102        } 
     
    111111        var newCenter = this.map.getLonLatFromViewPortPx( evt.xy );  
    112112        this.map.setCenter(newCenter, this.map.zoom + 1); 
    113         Event.stop(evt); 
     113        OpenLayers.Event.stop(evt); 
    114114        return false; 
    115115    }, 
     
    119119    */ 
    120120    defaultMouseDown: function (evt) { 
    121         if (!Event.isLeftClick(evt)) return; 
     121        if (!OpenLayers.Event.isLeftClick(evt)) return; 
    122122        this.mouseDragStart = evt.xy.clone(); 
    123123        this.performedDrag = false; 
     
    195195        } 
    196196        document.onselectstart = function() { return false; }  
    197         Event.stop(evt); 
     197        OpenLayers.Event.stop(evt); 
    198198    }, 
    199199 
     
    270270    */ 
    271271    defaultMouseUp: function (evt) { 
    272         if (!Event.isLeftClick(evt)) return; 
     272        if (!OpenLayers.Event.isLeftClick(evt)) return; 
    273273        switch (this.mode) { 
    274274            case "zoombox": 
  • sandbox/crschmidt/noprototype/lib/OpenLayers/Control/PanZoom.js

    r1586 r1587  
    102102     */ 
    103103    doubleClick: function (evt) { 
    104         Event.stop(evt); 
     104        OpenLayers.Event.stop(evt); 
    105105        return false; 
    106106    }, 
     
    110110     */ 
    111111    buttonDown: function (evt) { 
    112         if (!Event.isLeftClick(evt)) return; 
     112        if (!OpenLayers.Event.isLeftClick(evt)) return; 
    113113 
    114114        switch (this.action) { 
     
    136136        } 
    137137 
    138         Event.stop(evt); 
     138        OpenLayers.Event.stop(evt); 
    139139    }, 
    140140 
  • sandbox/crschmidt/noprototype/lib/OpenLayers/Control/PanZoomBar.js

    r1586 r1587  
    148148     */ 
    149149    divClick: function (evt) { 
    150         if (!Event.isLeftClick(evt)) return; 
     150        if (!OpenLayers.Event.isLeftClick(evt)) return; 
    151151        var y = evt.xy.y; 
    152152        var top = OpenLayers.Util.pagePosition(evt.object)[1]; 
    153153        var levels = Math.floor((y - top)/this.zoomStopHeight); 
    154154        this.map.zoomTo((this.map.getNumZoomLevels() -1) -  levels); 
    155         Event.stop(evt); 
     155        OpenLayers.Event.stop(evt); 
    156156    }, 
    157157     
     
    161161     */ 
    162162    zoomBarDown:function(evt) { 
    163         if (!Event.isLeftClick(evt)) return; 
     163        if (!OpenLayers.Event.isLeftClick(evt)) return; 
    164164        this.map.events.register("mousemove", this, this.passEventToSlider); 
    165165        this.map.events.register("mouseup", this, this.passEventToSlider); 
     
    167167        this.zoomStart = evt.xy.clone(); 
    168168        this.div.style.cursor = "move"; 
    169         Event.stop(evt); 
     169        OpenLayers.Event.stop(evt); 
    170170    }, 
    171171     
     
    186186            } 
    187187            this.mouseDragStart = evt.xy.clone(); 
    188             Event.stop(evt); 
     188            OpenLayers.Event.stop(evt); 
    189189        } 
    190190    }, 
     
    196196     */ 
    197197    zoomBarUp:function(evt) { 
    198         if (!Event.isLeftClick(evt)) return; 
     198        if (!OpenLayers.Event.isLeftClick(evt)) return; 
    199199        if (this.zoomStart) { 
    200200            this.div.style.cursor="default"; 
     
    205205            this.moveZoomBar(); 
    206206            this.mouseDragStart = null; 
    207             Event.stop(evt); 
     207            OpenLayers.Event.stop(evt); 
    208208        } 
    209209    }, 
  • sandbox/crschmidt/noprototype/lib/OpenLayers/Events.js

    r1574 r1587  
    22 * See http://svn.openlayers.org/trunk/openlayers/license.txt for the full 
    33 * text of the license. */ 
     4 
     5OpenLayers.Event = { 
     6  KEY_BACKSPACE: 8, 
     7  KEY_TAB:       9, 
     8  KEY_RETURN:   13, 
     9  KEY_ESC:      27, 
     10  KEY_LEFT:     37, 
     11  KEY_UP:       38, 
     12  KEY_RIGHT:    39, 
     13  KEY_DOWN:     40, 
     14  KEY_DELETE:   46, 
     15 
     16  element: function(event) { 
     17    return event.target || event.srcElement; 
     18  }, 
     19 
     20  isLeftClick: function(event) { 
     21    return (((event.which) && (event.which == 1)) || 
     22            ((event.button) && (event.button == 1))); 
     23  }, 
     24 
     25  pointerX: function(event) { 
     26    return event.pageX || (event.clientX + 
     27      (document.documentElement.scrollLeft || document.body.scrollLeft)); 
     28  }, 
     29 
     30  pointerY: function(event) { 
     31    return event.pageY || (event.clientY + 
     32      (document.documentElement.scrollTop || document.body.scrollTop)); 
     33  }, 
     34 
     35  stop: function(event) { 
     36    if (event.preventDefault) { 
     37      event.preventDefault(); 
     38      event.stopPropagation(); 
     39    } else { 
     40      event.returnValue = false; 
     41      event.cancelBubble = true; 
     42    } 
     43  }, 
     44 
     45  // find the first node with the given tagName, starting from the 
     46  // node the event was triggered on; traverses the DOM upwards 
     47  findElement: function(event, tagName) { 
     48    var element = OpenLayers.Event.element(event); 
     49    while (element.parentNode && (!element.tagName || 
     50        (element.tagName.toUpperCase() != tagName.toUpperCase()))) 
     51      element = element.parentNode; 
     52    return element; 
     53  }, 
     54 
     55  observers: false, 
     56 
     57  _observeAndCache: function(element, name, observer, useCapture) { 
     58    if (!this.observers) this.observers = []; 
     59    if (element.addEventListener) { 
     60      this.observers.push([element, name, observer, useCapture]); 
     61      element.addEventListener(name, observer, useCapture); 
     62    } else if (element.attachEvent) { 
     63      this.observers.push([element, name, observer, useCapture]); 
     64      element.attachEvent('on' + name, observer); 
     65    } 
     66  }, 
     67 
     68  unloadCache: function() { 
     69    if (!OpenLayers.Event.observers) return; 
     70    for (var i = 0; i < OpenLayers.Event.observers.length; i++) { 
     71      OpenLayers.Event.stopObserving.apply(this, OpenLayers.Event.observers[i]); 
     72      OpenLayers.Event.observers[i][0] = null; 
     73    } 
     74    OpenLayers.Event.observers = false; 
     75  }, 
     76 
     77  observe: function(elementParam, name, observer, useCapture) { 
     78    var element = $(elementParam); 
     79    useCapture = useCapture || false; 
     80 
     81    if (name == 'keypress' && 
     82        (navigator.appVersion.match(/Konqueror|Safari|KHTML/) 
     83        || element.attachEvent)) 
     84      name = 'keydown'; 
     85 
     86    this._observeAndCache(element, name, observer, useCapture); 
     87  }, 
     88 
     89  stopObserving: function(elementParam, name, observer, useCapture) { 
     90    var element = $(elementParam); 
     91    useCapture = useCapture || false; 
     92 
     93    if (name == 'keypress' && 
     94        (navigator.appVersion.match(/Konqueror|Safari|KHTML/) 
     95        || element.detachEvent)) 
     96      name = 'keydown'; 
     97 
     98    if (element.removeEventListener) { 
     99      element.removeEventListener(name, observer, useCapture); 
     100    } else if (element.detachEvent) { 
     101      element.detachEvent('on' + name, observer); 
     102    } 
     103  } 
     104}; 
     105/* prevent memory leaks in IE */ 
     106OpenLayers.Event.observe(window, 'unload', OpenLayers.Event.unloadCache, false); 
     107 
     108if (window.Event) { 
     109  OpenLayers.Util.extend(window.Event, OpenLayers.Event); 
     110} else { 
     111  var Event = OpenLayers.Event; 
     112} 
     113 
     114 
    4115 
    5116/** 
     
    30141    eventTypes: null, 
    31142 
    32  
    33143    /** 
    34144     * @constructor  
     
    73183 
    74184            // use Prototype to register the event cross-browser 
    75             Event.observe(element, eventType,  
     185            OpenLayers.Event.observe(element, eventType,  
    76186                this.handleBrowserEvent.bindAsEventListener(this)); 
    77187        } 
    78188        // disable dragstart in IE so that mousedown/move/up works normally 
    79         Event.observe(element, "dragstart", Event.stop); 
     189        OpenLayers.Event.observe(element, "dragstart", OpenLayers.Event.stop); 
    80190    }, 
    81191 
     
    181291            // don't fall through to other DOM elements 
    182292            if (!this.fallThrough) {             
    183                 Event.stop(evt); 
     293                OpenLayers.Event.stop(evt); 
    184294            } 
    185295        } 
     
    212322        } 
    213323        return new OpenLayers.Pixel( 
    214                         (evt.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft)) - this.element.offsets[0],  
    215                         (evt.clientY + (document.documentElement.scrollTop || document.body.scrollTop)) - this.element.offsets[1]  
    216                         );  
     324            (evt.clientX + (document.documentElement.scrollLeft 
     325                         || document.body.scrollLeft)) - this.element.offsets[0],  
     326            (evt.clientY + (document.documentElement.scrollTop 
     327                         || document.body.scrollTop)) - this.element.offsets[1]  
     328        );  
    217329    }, 
    218330 
  • sandbox/crschmidt/noprototype/lib/OpenLayers/Layer/GeoRSS.js

    r1586 r1587  
    131131        if (!sameMarkerClicked) { 
    132132            var popup = this.createPopup(); 
    133             Event.observe(popup.div, "click", 
     133            OpenLayers.Event.observe(popup.div, "click", 
    134134            function() {  
    135135              for(var i=0; i < this.layer.map.popups.length; i++) {  
     
    139139            this.layer.map.addPopup(popup);  
    140140        } 
    141         Event.stop(evt); 
     141        OpenLayers.Event.stop(evt); 
    142142    }, 
    143143 
  • sandbox/crschmidt/noprototype/lib/OpenLayers/Layer/Text.js

    r1586 r1587  
    146146            this.layer.map.addPopup(this.createPopup());  
    147147        } 
    148         Event.stop(evt); 
     148        OpenLayers.Event.stop(evt); 
    149149    }, 
    150150 
  • sandbox/crschmidt/noprototype/lib/OpenLayers/Map.js

    r1586 r1587  
    153153            //  Note that this is ok, as updateSize() does nothing if the  
    154154            //  map's size has not actually changed. 
    155             Event.observe(window, 'resize',  
     155            OpenLayers.Event.observe(window, 'resize',  
    156156                          this.updateSize.bindAsEventListener(this)); 
    157157        } 
     
    174174 
    175175        // always call map.destroy() 
    176         Event.observe(window,  
     176        OpenLayers.Event.observe(window,  
    177177                      'unload',  
    178178                      this.destroy.bindAsEventListener(this)); 
  • sandbox/crschmidt/noprototype/lib/OpenLayers/Util.js

    r1586 r1587  
    134134    if(delayDisplay) { 
    135135        image.style.display = "none"; 
    136         Event.observe(image, "load",  
     136        OpenLayers.Event.observe(image, "load",  
    137137                      OpenLayers.Util.onImageLoad.bindAsEventListener(image)); 
    138         Event.observe(image, "error",  
     138        OpenLayers.Event.observe(image, "error",  
    139139                      OpenLayers.Util.onImageLoadError.bindAsEventListener(image)); 
    140140         
     
    273273    if (delayDisplay) { 
    274274        img.style.display = "none"; 
    275         Event.observe(img, "load", 
     275        OpenLayers.Event.observe(img, "load", 
    276276                      OpenLayers.Util.onImageLoad.bindAsEventListener(div)); 
    277         Event.observe(img, "error", 
     277        OpenLayers.Event.observe(img, "error", 
    278278                      OpenLayers.Util.onImageLoadError.bindAsEventListener(div)); 
    279279    }