OpenLayers OpenLayers

Ticket #567: selection.patch

File selection.patch, 5.0 kB (added by tschaub, 2 years ago)

only disable IE selecting while dragging

  • lib/OpenLayers/Handler/Drag.js

    old new  
    1616     * When a mousedown event is received, we want to record it, but not set  
    1717     * 'dragging' until the mouse moves after starting.  
    1818     *  
    19      * @type boolean  
     19     * @type Boolean  
    2020     **/ 
    2121    started: false, 
    2222     
    23     /** @type boolean **/ 
    24     dragging: null
     23    /** @type Boolean **/ 
     24    dragging: false
    2525 
    2626    /** @type OpenLayers.Pixel **/ 
    2727    start: null, 
     
    4040        OpenLayers.Handler.prototype.initialize.apply(this, arguments); 
    4141    }, 
    4242     
     43    /** 
     44     * Handle mousedown events 
     45     * @param {Event} evt 
     46     * @type Boolean 
     47     * @return Should the event propagate 
     48     */ 
    4349    mousedown: function (evt) { 
    4450        if (this.checkModifiers(evt) && OpenLayers.Event.isLeftClick(evt)) { 
    4551            this.started = true; 
    46             this.dragging = null
     52            this.dragging = false
    4753            this.start = evt.xy.clone(); 
    4854            // TBD replace with CSS classes 
    4955            this.map.div.style.cursor = "move"; 
     
    5157            OpenLayers.Event.stop(evt); 
    5258            return false; 
    5359        } 
     60        return true; 
    5461    }, 
    5562 
     63    /** 
     64     * Handle mousemove events 
     65     * @param {Event} evt 
     66     * @type Boolean 
     67     * @return Should the event propagate 
     68     */ 
    5669    mousemove: function (evt) { 
    5770        if (this.started) { 
    5871            this.dragging = true; 
    5972            this.callback("move", [evt.xy]); 
     73            if(document.onselectstart) { 
     74                if(!this.oldOnselectstart) { 
     75                    this.oldOnselectstart = document.onselectstart; 
     76                    document.onselectstart = function() {return false;} 
     77                } 
     78            } 
    6079        } 
     80        return true; 
    6181    }, 
    6282 
     83    /** 
     84     * Handle mouseup events 
     85     * @param {Event} evt 
     86     * @type Boolean 
     87     * @return Should the event propagate 
     88     */ 
    6389    mouseup: function (evt) { 
    6490        if (this.started) { 
    65             this.started = false;  
     91            this.started = false; 
     92            this.dragging = false; 
    6693            // TBD replace with CSS classes 
    6794            this.map.div.style.cursor = "default"; 
    6895            this.callback("up", [evt.xy]); 
     96            if(document.onselectstart) { 
     97                document.onselectstart = this.oldOnselectstart; 
     98            } 
    6999        } 
     100        return true; 
    70101    }, 
    71102 
     103    /** 
     104     * Handle mouseout events 
     105     * @param {Event} evt 
     106     * @type Boolean 
     107     * @return Should the event propagate 
     108     */ 
    72109    mouseout: function (evt) { 
    73110        if (this.started && OpenLayers.Util.mouseLeft(evt, this.map.div)) { 
    74111            this.started = false;  
    75             this.dragging = null
     112            this.dragging = false
    76113            // TBD replace with CSS classes 
    77114            this.map.div.style.cursor = "default"; 
    78115            this.callback("out", []); 
     116            if(document.onselectstart) { 
     117                document.onselectstart = this.oldOnselectstart; 
     118            } 
    79119        } 
     120        return true; 
    80121    }, 
    81122 
    82123    /** 
     124     * The drag handler captures the click event.  If something else registers 
     125     * for clicks on the same element, its listener will not be called after a 
     126     * drag. 
    83127     * @param {Event} evt 
    84      *  
    85128     * @type Boolean 
     129     * @return Should the event propagate 
    86130     */ 
    87131    click: function (evt) { 
    88132        // throw away the first left click event that happens after a mouse up 
    89         if (OpenLayers.Event.isLeftClick(evt) && this.dragging != null) { 
    90             this.dragging = null
     133        if (OpenLayers.Event.isLeftClick(evt) && this.dragging) { 
     134            this.dragging = true
    91135            return false;  
    92136        } 
    93137        this.started = false; 
     138        return true; 
    94139    }, 
    95140 
    96     activate: function (evt) { 
    97         OpenLayers.Handler.prototype.activate.apply(this, arguments); 
    98         document.onselectstart = function() { return false; }; 
    99         this.dragging = null; 
     141    /** 
     142     * Activate the handler. 
     143     * @type Boolean 
     144     * @return Was activation successful.  Returns false if already active. 
     145     */ 
     146    activate: function() { 
     147        if(OpenLayers.Handler.prototype.activate.apply(this, arguments)) { 
     148            this.dragging = false; 
     149            return true; 
     150        } else { 
     151            return false; 
     152        } 
    100153    }, 
    101154 
    102     deactivate: function (evt) { 
    103         OpenLayers.Handler.prototype.deactivate.apply(this, arguments); 
    104         document.onselectstart = null; 
    105         this.dragging = null; 
     155    /** 
     156     * Deactivate the handler. 
     157     * @type Boolean 
     158     * @return Was deactivation successful.  Returns false if not already active. 
     159     */ 
     160    deactivate: function() { 
     161        if(OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { 
     162            this.dragging = false; 
     163            return true; 
     164        } else { 
     165            return false; 
     166        } 
    106167    }, 
    107168 
    108169    /** @final @type String */