fix for #624 - merge stop() and safeStopPropagation()

git-svn-id: http://svn.openlayers.org/trunk/openlayers@2994 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2007-04-03 17:15:57 +00:00
parent 10b5c2df17
commit 23131012dd
3 changed files with 44 additions and 20 deletions
+18 -8
View File
@@ -66,18 +66,28 @@ OpenLayers.Event = {
((event.button) && (event.button == 1))); ((event.button) && (event.button == 1)));
}, },
/** Stops an event from propagating. If the event's 'preventDefault' /** Stops an event from propagating.
* property is set, then we prevent the default browser behaviour
* (such as text selection, radio-button clicking, etc) from occurring
* *
* @param {Event} event * @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) { stop: function(event, allowDefault) {
if (event.preventDefault) {
event.preventDefault(); if (!allowDefault) {
if (event.preventDefault) {
event.preventDefault();
} else {
event.returnValue = false;
}
}
if (event.stopPropagation) {
event.stopPropagation(); event.stopPropagation();
} else { } else {
event.returnValue = false;
event.cancelBubble = true; event.cancelBubble = true;
} }
}, },
@@ -504,7 +514,7 @@ OpenLayers.Events.prototype = {
} }
// don't fall through to other DOM elements // don't fall through to other DOM elements
if (!this.fallThrough) { if (!this.fallThrough) {
OpenLayers.Util.safeStopPropagation(evt); OpenLayers.Event.stop(evt, true);
} }
} }
}, },
+21 -7
View File
@@ -296,11 +296,9 @@ OpenLayers.Popup.prototype = {
this.events.register("mousedown", this, this.onmousedown); this.events.register("mousedown", this, this.onmousedown);
this.events.register("mousemove", this, this.onmousemove); this.events.register("mousemove", this, this.onmousemove);
this.events.register("mouseup", this, this.onmouseup); this.events.register("mouseup", this, this.onmouseup);
this.events.register("click", this, this.events.register("click", this, this.onclick);
OpenLayers.Util.safeStopPropagation);
this.events.register("mouseout", this, this.onmouseout); this.events.register("mouseout", this, this.onmouseout);
this.events.register("dblclick", this, this.events.register("dblclick", this, this.ondblclick);
OpenLayers.Util.safeStopPropagation);
}, },
/** When mouse goes down within the popup, make a note of /** When mouse goes down within the popup, make a note of
@@ -311,7 +309,7 @@ OpenLayers.Popup.prototype = {
*/ */
onmousedown: function (evt) { onmousedown: function (evt) {
this.mousedown = true; this.mousedown = true;
OpenLayers.Util.safeStopPropagation(evt); OpenLayers.Event.stop(evt, true);
}, },
/** If the drag was started within the popup, then /** If the drag was started within the popup, then
@@ -322,7 +320,7 @@ OpenLayers.Popup.prototype = {
*/ */
onmousemove: function (evt) { onmousemove: function (evt) {
if (this.mousedown) { if (this.mousedown) {
OpenLayers.Util.safeStopPropagation(evt); OpenLayers.Event.stop(evt, true);
} }
}, },
@@ -336,10 +334,18 @@ OpenLayers.Popup.prototype = {
onmouseup: function (evt) { onmouseup: function (evt) {
if (this.mousedown) { if (this.mousedown) {
this.mousedown = false; 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 /** 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. * if they let go and then drag back in, we won't be confused.
* *
@@ -351,6 +357,14 @@ OpenLayers.Popup.prototype = {
this.mousedown = false; 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 */ /** @final @type String */
CLASS_NAME: "OpenLayers.Popup" CLASS_NAME: "OpenLayers.Popup"
}; };
+5 -5
View File
@@ -717,16 +717,16 @@ OpenLayers.Util.getScaleFromResolution = function (resolution, units) {
return scale; 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. * the default browser action from occurring.
* *
* @param {Event} evt * @param {Event} evt
*/ */
OpenLayers.Util.safeStopPropagation = function(evt) { OpenLayers.Util.safeStopPropagation = function(evt) {
if (evt.stopPropagation) { OpenLayers.Event.stop(evt, true);
evt.stopPropagation();
}
evt.cancelBubble = true;
}; };
OpenLayers.Util.pagePosition = function(forElement) { OpenLayers.Util.pagePosition = function(forElement) {