OpenLayers OpenLayers

Ticket #624: preventDefaults.patch

File preventDefaults.patch, 5.0 kB (added by euzuro, 2 years ago)

add extra parameter to stop() function, mark safestoppropagation() as deprecated, switch all uses of the previous to the new. alll tests pass in ff & ie

  • lib/OpenLayers/Events.js

    old new  
    8181              (document.documentElement.scrollTop || document.body.scrollTop)); 
    8282    }, 
    8383 
    84     /** Stops an event from propagating. If the event's 'preventDefault'  
    85      *   property is set, then we prevent the default browser behaviour 
    86      *   (such as text selection, radio-button clicking, etc) from occurring 
     84    /** Stops an event from propagating.  
    8785     *  
    8886     * @param {Event} event 
     87     * @param {Boolean} preventDefault If false, we stop the event chain but  
     88     *                                 still allow the default browser  
     89     *                                 behaviour (text selection, radio-button  
     90     *                                 clicking, etc) 
     91     *                                 Default true 
    8992     */ 
    90     stop: function(event) { 
    91         if (event.preventDefault) { 
    92             event.preventDefault(); 
     93    stop: function(event, preventDefault) { 
     94        preventDefault = (preventDefault != null) ? preventDefault : true; 
     95         
     96        if (preventDefault) {  
     97            if (event.preventDefault) { 
     98                event.preventDefault(); 
     99            } else { 
     100                event.returnValue = false; 
     101            } 
     102        } 
     103                 
     104        if (event.stopPropagation) { 
    93105            event.stopPropagation(); 
    94106        } else { 
    95             event.returnValue = false; 
    96107            event.cancelBubble = true; 
    97108        } 
    98109    }, 
     
    509520            } 
    510521            // don't fall through to other DOM elements 
    511522            if (!this.fallThrough) {            
    512                 OpenLayers.Util.safeStopPropagation(evt); 
     523                OpenLayers.Event.stop(evt, false); 
    513524            } 
    514525        } 
    515526    }, 
  • lib/OpenLayers/Util.js

    old new  
    717717    return scale; 
    718718}; 
    719719 
    720 /** Safely stop the propagation of an event *without* preventing 
     720/** @deprecated Please use directly OpenLayers.Event.stop() passing 'false' as  
     721 *              the 2nd argument (preventDefault) 
     722 *  
     723 * Safely stop the propagation of an event *without* preventing 
    721724 *   the default browser action from occurring. 
    722725 *  
    723726 * @param {Event} evt 
    724727 */ 
    725728OpenLayers.Util.safeStopPropagation = function(evt) { 
    726     if (evt.stopPropagation) { 
    727         evt.stopPropagation(); 
    728     }  
    729     evt.cancelBubble = true;     
     729    OpenLayers.Event.stop(evt, false); 
    730730}; 
    731731 
    732732OpenLayers.Util.pagePosition = function(forElement) { 
  • lib/OpenLayers/Popup.js

    old new  
    296296        this.events.register("mousedown", this, this.onmousedown); 
    297297        this.events.register("mousemove", this, this.onmousemove); 
    298298        this.events.register("mouseup", this, this.onmouseup); 
    299         this.events.register("click", this,  
    300                              OpenLayers.Util.safeStopPropagation); 
     299        this.events.register("click", this, this.onclick); 
    301300        this.events.register("mouseout", this, this.onmouseout); 
    302         this.events.register("dblclick", this,  
    303                              OpenLayers.Util.safeStopPropagation); 
     301        this.events.register("dblclick", this, this.ondblclick); 
    304302     }, 
    305303 
    306304    /** When mouse goes down within the popup, make a note of 
     
    311309     */ 
    312310    onmousedown: function (evt) { 
    313311        this.mousedown = true; 
    314         OpenLayers.Util.safeStopPropagation(evt); 
     312        OpenLayers.Event.stop(evt, false); 
    315313    }, 
    316314 
    317315    /** If the drag was started within the popup, then  
     
    322320     */ 
    323321    onmousemove: function (evt) { 
    324322        if (this.mousedown) { 
    325             OpenLayers.Util.safeStopPropagation(evt); 
     323            OpenLayers.Event.stop(evt, false); 
    326324        } 
    327325    }, 
    328326 
     
    336334    onmouseup: function (evt) { 
    337335        if (this.mousedown) { 
    338336            this.mousedown = false; 
    339             OpenLayers.Util.safeStopPropagation(evt); 
     337            OpenLayers.Event.stop(evt, false); 
    340338        } 
    341339    }, 
    342340 
     341    /** Ignore clicks, but allowing default browser handling 
     342     *  
     343     * @param {Event} evt 
     344     */ 
     345    onclick: function (evt) { 
     346        OpenLayers.Event.stop(evt, false); 
     347    }, 
     348 
    343349    /** When mouse goes out of the popup set the flag to false so that 
    344350     *   if they let go and then drag back in, we won't be confused. 
    345351     *  
     
    351357        this.mousedown = false; 
    352358    }, 
    353359     
     360    /** Ignore double-clicks, but allowing default browser handling 
     361     *  
     362     * @param {Event} evt 
     363     */ 
     364    ondblclick: function (evt) { 
     365        OpenLayers.Event.stop(evt, false); 
     366    }, 
     367 
    354368    /** @final @type String */ 
    355369    CLASS_NAME: "OpenLayers.Popup" 
    356370};