Ticket #567: selection.patch
| File selection.patch, 5.0 kB (added by tschaub, 2 years ago) |
|---|
-
lib/OpenLayers/Handler/Drag.js
old new 16 16 * When a mousedown event is received, we want to record it, but not set 17 17 * 'dragging' until the mouse moves after starting. 18 18 * 19 * @type boolean19 * @type Boolean 20 20 **/ 21 21 started: false, 22 22 23 /** @type boolean **/24 dragging: null,23 /** @type Boolean **/ 24 dragging: false, 25 25 26 26 /** @type OpenLayers.Pixel **/ 27 27 start: null, … … 40 40 OpenLayers.Handler.prototype.initialize.apply(this, arguments); 41 41 }, 42 42 43 /** 44 * Handle mousedown events 45 * @param {Event} evt 46 * @type Boolean 47 * @return Should the event propagate 48 */ 43 49 mousedown: function (evt) { 44 50 if (this.checkModifiers(evt) && OpenLayers.Event.isLeftClick(evt)) { 45 51 this.started = true; 46 this.dragging = null;52 this.dragging = false; 47 53 this.start = evt.xy.clone(); 48 54 // TBD replace with CSS classes 49 55 this.map.div.style.cursor = "move"; … … 51 57 OpenLayers.Event.stop(evt); 52 58 return false; 53 59 } 60 return true; 54 61 }, 55 62 63 /** 64 * Handle mousemove events 65 * @param {Event} evt 66 * @type Boolean 67 * @return Should the event propagate 68 */ 56 69 mousemove: function (evt) { 57 70 if (this.started) { 58 71 this.dragging = true; 59 72 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 } 60 79 } 80 return true; 61 81 }, 62 82 83 /** 84 * Handle mouseup events 85 * @param {Event} evt 86 * @type Boolean 87 * @return Should the event propagate 88 */ 63 89 mouseup: function (evt) { 64 90 if (this.started) { 65 this.started = false; 91 this.started = false; 92 this.dragging = false; 66 93 // TBD replace with CSS classes 67 94 this.map.div.style.cursor = "default"; 68 95 this.callback("up", [evt.xy]); 96 if(document.onselectstart) { 97 document.onselectstart = this.oldOnselectstart; 98 } 69 99 } 100 return true; 70 101 }, 71 102 103 /** 104 * Handle mouseout events 105 * @param {Event} evt 106 * @type Boolean 107 * @return Should the event propagate 108 */ 72 109 mouseout: function (evt) { 73 110 if (this.started && OpenLayers.Util.mouseLeft(evt, this.map.div)) { 74 111 this.started = false; 75 this.dragging = null;112 this.dragging = false; 76 113 // TBD replace with CSS classes 77 114 this.map.div.style.cursor = "default"; 78 115 this.callback("out", []); 116 if(document.onselectstart) { 117 document.onselectstart = this.oldOnselectstart; 118 } 79 119 } 120 return true; 80 121 }, 81 122 82 123 /** 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. 83 127 * @param {Event} evt 84 *85 128 * @type Boolean 129 * @return Should the event propagate 86 130 */ 87 131 click: function (evt) { 88 132 // 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; 91 135 return false; 92 136 } 93 137 this.started = false; 138 return true; 94 139 }, 95 140 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 } 100 153 }, 101 154 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 } 106 167 }, 107 168 108 169 /** @final @type String */
