OpenLayers OpenLayers

Changeset 2908

Show
Ignore:
Timestamp:
03/28/07 11:59:49 (2 years ago)
Author:
tschaub
Message:

modify the drag handler so that it only modifies IE's document.onselectstart while dragging - add jsodc text - all browser event handlers now return a boolean - activate and deactivate respect the return of the parent class and return the same

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Handler/Drag.js

    r2803 r2908  
    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, 
     28 
     29    /** 
     30     * @type Function 
     31     * @private 
     32     */ 
     33    oldOnselectstart: null, 
    2834 
    2935    /** 
     
    4147    }, 
    4248     
     49    /** 
     50     * Handle mousedown events 
     51     * @param {Event} evt 
     52     * @type Boolean 
     53     * @return Should the event propagate 
     54     */ 
    4355    mousedown: function (evt) { 
    4456        if (this.checkModifiers(evt) && OpenLayers.Event.isLeftClick(evt)) { 
    4557            this.started = true; 
    46             this.dragging = null
     58            this.dragging = false
    4759            this.start = evt.xy.clone(); 
    4860            // TBD replace with CSS classes 
     
    5264            return false; 
    5365        } 
     66        return true; 
    5467    }, 
    5568 
     69    /** 
     70     * Handle mousemove events 
     71     * @param {Event} evt 
     72     * @type Boolean 
     73     * @return Should the event propagate 
     74     */ 
    5675    mousemove: function (evt) { 
    5776        if (this.started) { 
    5877            this.dragging = true; 
    5978            this.callback("move", [evt.xy]); 
     79            if(document.onselectstart) { 
     80                if(!this.oldOnselectstart) { 
     81                    this.oldOnselectstart = document.onselectstart; 
     82                    document.onselectstart = function() {return false;} 
     83                } 
     84            } 
    6085        } 
     86        return true; 
    6187    }, 
    6288 
     89    /** 
     90     * Handle mouseup events 
     91     * @param {Event} evt 
     92     * @type Boolean 
     93     * @return Should the event propagate 
     94     */ 
    6395    mouseup: function (evt) { 
    6496        if (this.started) { 
    65             this.started = false;  
     97            this.started = false; 
     98            this.dragging = false; 
    6699            // TBD replace with CSS classes 
    67100            this.map.div.style.cursor = "default"; 
    68101            this.callback("up", [evt.xy]); 
     102            if(document.onselectstart) { 
     103                document.onselectstart = this.oldOnselectstart; 
     104            } 
    69105        } 
     106        return true; 
    70107    }, 
    71108 
     109    /** 
     110     * Handle mouseout events 
     111     * @param {Event} evt 
     112     * @type Boolean 
     113     * @return Should the event propagate 
     114     */ 
    72115    mouseout: function (evt) { 
    73116        if (this.started && OpenLayers.Util.mouseLeft(evt, this.map.div)) { 
    74117            this.started = false;  
    75             this.dragging = null
     118            this.dragging = false
    76119            // TBD replace with CSS classes 
    77120            this.map.div.style.cursor = "default"; 
    78121            this.callback("out", []); 
     122            if(document.onselectstart) { 
     123                document.onselectstart = this.oldOnselectstart; 
     124            } 
     125        } 
     126        return true; 
     127    }, 
     128 
     129    /** 
     130     * The drag handler captures the click event.  If something else registers 
     131     * for clicks on the same element, its listener will not be called after a 
     132     * drag. 
     133     * @param {Event} evt 
     134     * @type Boolean 
     135     * @return Should the event propagate 
     136     */ 
     137    click: function (evt) { 
     138        // throw away the first left click event that happens after a mouse up 
     139        if (OpenLayers.Event.isLeftClick(evt) && this.dragging) { 
     140            this.dragging = true; 
     141            return false;  
     142        } 
     143        this.started = false; 
     144        return true; 
     145    }, 
     146 
     147    /** 
     148     * Activate the handler. 
     149     * @type Boolean 
     150     * @return Was activation successful.  Returns false if already active. 
     151     */ 
     152    activate: function() { 
     153        if(OpenLayers.Handler.prototype.activate.apply(this, arguments)) { 
     154            this.dragging = false; 
     155            return true; 
     156        } else { 
     157            return false; 
    79158        } 
    80159    }, 
    81160 
    82161    /** 
    83      * @param {Event} evt 
    84      *  
     162     * Deactivate the handler. 
    85163     * @type Boolean 
     164     * @return Was deactivation successful.  Returns false if not already active. 
    86165     */ 
    87     click: function (evt) { 
    88         // 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; 
    91             return false;  
     166    deactivate: function() { 
     167        if(OpenLayers.Handler.prototype.deactivate.apply(this, arguments)) { 
     168            this.dragging = false; 
     169            return true; 
     170        } else { 
     171            return false; 
    92172        } 
    93         this.started = false; 
    94     }, 
    95  
    96     activate: function (evt) { 
    97         OpenLayers.Handler.prototype.activate.apply(this, arguments); 
    98         document.onselectstart = function() { return false; }; 
    99         this.dragging = null; 
    100     }, 
    101  
    102     deactivate: function (evt) { 
    103         OpenLayers.Handler.prototype.deactivate.apply(this, arguments); 
    104         document.onselectstart = null; 
    105         this.dragging = null; 
    106173    }, 
    107174