OpenLayers OpenLayers

Ticket #624: allowDefaults.patch

File allowDefaults.patch, 4.8 kB (added by euzuro, 2 years ago)

why do i always have to be so *negative* about everything? :-)

  • lib/OpenLayers/Events.js

    old new  
    6666                ((event.button) && (event.button == 1))); 
    6767    }, 
    6868 
    69     /** Stops an event from propagating. If the event's 'preventDefault'  
    70      *   property is set, then we prevent the default browser behaviour 
    71      *   (such as text selection, radio-button clicking, etc) from occurring 
     69    /** Stops an event from propagating.  
    7270     *  
    7371     * @param {Event} event 
     72     * @param {Boolean} allowDefault If true, we stop the event chain but  
     73     *                               still allow the default browser  
     74     *                               behaviour (text selection, radio-button  
     75     *                               clicking, etc) 
     76     *                               Default false 
    7477     */ 
    75     stop: function(event) { 
    76         if (event.preventDefault) { 
    77             event.preventDefault(); 
     78    stop: function(event, allowDefault) { 
     79         
     80        if (!allowDefault) {  
     81            if (event.preventDefault) { 
     82                event.preventDefault(); 
     83            } else { 
     84                event.returnValue = false; 
     85            } 
     86        } 
     87                 
     88        if (event.stopPropagation) { 
    7889            event.stopPropagation(); 
    7990        } else { 
    80             event.returnValue = false; 
    8191            event.cancelBubble = true; 
    8292        } 
    8393    }, 
     
    504514            } 
    505515            // don't fall through to other DOM elements 
    506516            if (!this.fallThrough) {            
    507                 OpenLayers.Util.safeStopPropagation(evt); 
     517                OpenLayers.Event.stop(evt, true); 
    508518            } 
    509519        } 
    510520    }, 
  • 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 'true' 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, true); 
    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, true); 
    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, true); 
    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, true); 
    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, true); 
     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, true); 
     366    }, 
     367 
    354368    /** @final @type String */ 
    355369    CLASS_NAME: "OpenLayers.Popup" 
    356370};