Ticket #624: preventDefaults.patch
| File preventDefaults.patch, 5.0 kB (added by euzuro, 2 years ago) |
|---|
-
lib/OpenLayers/Events.js
old new 81 81 (document.documentElement.scrollTop || document.body.scrollTop)); 82 82 }, 83 83 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. 87 85 * 88 86 * @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 89 92 */ 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) { 93 105 event.stopPropagation(); 94 106 } else { 95 event.returnValue = false;96 107 event.cancelBubble = true; 97 108 } 98 109 }, … … 509 520 } 510 521 // don't fall through to other DOM elements 511 522 if (!this.fallThrough) { 512 OpenLayers. Util.safeStopPropagation(evt);523 OpenLayers.Event.stop(evt, false); 513 524 } 514 525 } 515 526 }, -
lib/OpenLayers/Util.js
old new 717 717 return scale; 718 718 }; 719 719 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 721 724 * the default browser action from occurring. 722 725 * 723 726 * @param {Event} evt 724 727 */ 725 728 OpenLayers.Util.safeStopPropagation = function(evt) { 726 if (evt.stopPropagation) { 727 evt.stopPropagation(); 728 } 729 evt.cancelBubble = true; 729 OpenLayers.Event.stop(evt, false); 730 730 }; 731 731 732 732 OpenLayers.Util.pagePosition = function(forElement) { -
lib/OpenLayers/Popup.js
old new 296 296 this.events.register("mousedown", this, this.onmousedown); 297 297 this.events.register("mousemove", this, this.onmousemove); 298 298 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); 301 300 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); 304 302 }, 305 303 306 304 /** When mouse goes down within the popup, make a note of … … 311 309 */ 312 310 onmousedown: function (evt) { 313 311 this.mousedown = true; 314 OpenLayers. Util.safeStopPropagation(evt);312 OpenLayers.Event.stop(evt, false); 315 313 }, 316 314 317 315 /** If the drag was started within the popup, then … … 322 320 */ 323 321 onmousemove: function (evt) { 324 322 if (this.mousedown) { 325 OpenLayers. Util.safeStopPropagation(evt);323 OpenLayers.Event.stop(evt, false); 326 324 } 327 325 }, 328 326 … … 336 334 onmouseup: function (evt) { 337 335 if (this.mousedown) { 338 336 this.mousedown = false; 339 OpenLayers. Util.safeStopPropagation(evt);337 OpenLayers.Event.stop(evt, false); 340 338 } 341 339 }, 342 340 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 343 349 /** When mouse goes out of the popup set the flag to false so that 344 350 * if they let go and then drag back in, we won't be confused. 345 351 * … … 351 357 this.mousedown = false; 352 358 }, 353 359 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 354 368 /** @final @type String */ 355 369 CLASS_NAME: "OpenLayers.Popup" 356 370 };
