From 23131012dd55e0e856511be79b5079b191c95747 Mon Sep 17 00:00:00 2001 From: euzuro Date: Tue, 3 Apr 2007 17:15:57 +0000 Subject: [PATCH] fix for #624 - merge stop() and safeStopPropagation() git-svn-id: http://svn.openlayers.org/trunk/openlayers@2994 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Events.js | 26 ++++++++++++++++++-------- lib/OpenLayers/Popup.js | 28 +++++++++++++++++++++------- lib/OpenLayers/Util.js | 10 +++++----- 3 files changed, 44 insertions(+), 20 deletions(-) diff --git a/lib/OpenLayers/Events.js b/lib/OpenLayers/Events.js index 3e69d3c090..014a334c35 100644 --- a/lib/OpenLayers/Events.js +++ b/lib/OpenLayers/Events.js @@ -66,18 +66,28 @@ OpenLayers.Event = { ((event.button) && (event.button == 1))); }, - /** Stops an event from propagating. If the event's 'preventDefault' - * property is set, then we prevent the default browser behaviour - * (such as text selection, radio-button clicking, etc) from occurring + /** Stops an event from propagating. * * @param {Event} event + * @param {Boolean} allowDefault If true, we stop the event chain but + * still allow the default browser + * behaviour (text selection, radio-button + * clicking, etc) + * Default false */ - stop: function(event) { - if (event.preventDefault) { - event.preventDefault(); + stop: function(event, allowDefault) { + + if (!allowDefault) { + if (event.preventDefault) { + event.preventDefault(); + } else { + event.returnValue = false; + } + } + + if (event.stopPropagation) { event.stopPropagation(); } else { - event.returnValue = false; event.cancelBubble = true; } }, @@ -504,7 +514,7 @@ OpenLayers.Events.prototype = { } // don't fall through to other DOM elements if (!this.fallThrough) { - OpenLayers.Util.safeStopPropagation(evt); + OpenLayers.Event.stop(evt, true); } } }, diff --git a/lib/OpenLayers/Popup.js b/lib/OpenLayers/Popup.js index 51bc3d2c7f..1132d08d00 100644 --- a/lib/OpenLayers/Popup.js +++ b/lib/OpenLayers/Popup.js @@ -296,11 +296,9 @@ OpenLayers.Popup.prototype = { this.events.register("mousedown", this, this.onmousedown); this.events.register("mousemove", this, this.onmousemove); this.events.register("mouseup", this, this.onmouseup); - this.events.register("click", this, - OpenLayers.Util.safeStopPropagation); + this.events.register("click", this, this.onclick); this.events.register("mouseout", this, this.onmouseout); - this.events.register("dblclick", this, - OpenLayers.Util.safeStopPropagation); + this.events.register("dblclick", this, this.ondblclick); }, /** When mouse goes down within the popup, make a note of @@ -311,7 +309,7 @@ OpenLayers.Popup.prototype = { */ onmousedown: function (evt) { this.mousedown = true; - OpenLayers.Util.safeStopPropagation(evt); + OpenLayers.Event.stop(evt, true); }, /** If the drag was started within the popup, then @@ -322,7 +320,7 @@ OpenLayers.Popup.prototype = { */ onmousemove: function (evt) { if (this.mousedown) { - OpenLayers.Util.safeStopPropagation(evt); + OpenLayers.Event.stop(evt, true); } }, @@ -336,10 +334,18 @@ OpenLayers.Popup.prototype = { onmouseup: function (evt) { if (this.mousedown) { this.mousedown = false; - OpenLayers.Util.safeStopPropagation(evt); + OpenLayers.Event.stop(evt, true); } }, + /** Ignore clicks, but allowing default browser handling + * + * @param {Event} evt + */ + onclick: function (evt) { + OpenLayers.Event.stop(evt, true); + }, + /** When mouse goes out of the popup set the flag to false so that * if they let go and then drag back in, we won't be confused. * @@ -351,6 +357,14 @@ OpenLayers.Popup.prototype = { this.mousedown = false; }, + /** Ignore double-clicks, but allowing default browser handling + * + * @param {Event} evt + */ + ondblclick: function (evt) { + OpenLayers.Event.stop(evt, true); + }, + /** @final @type String */ CLASS_NAME: "OpenLayers.Popup" }; diff --git a/lib/OpenLayers/Util.js b/lib/OpenLayers/Util.js index 1ca26c0fab..f1e048d87b 100644 --- a/lib/OpenLayers/Util.js +++ b/lib/OpenLayers/Util.js @@ -717,16 +717,16 @@ OpenLayers.Util.getScaleFromResolution = function (resolution, units) { return scale; }; -/** Safely stop the propagation of an event *without* preventing +/** @deprecated Please use directly OpenLayers.Event.stop() passing 'true' as + * the 2nd argument (preventDefault) + * + * Safely stop the propagation of an event *without* preventing * the default browser action from occurring. * * @param {Event} evt */ OpenLayers.Util.safeStopPropagation = function(evt) { - if (evt.stopPropagation) { - evt.stopPropagation(); - } - evt.cancelBubble = true; + OpenLayers.Event.stop(evt, true); }; OpenLayers.Util.pagePosition = function(forElement) {