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

View File

@@ -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);
}
}
},

View File

@@ -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"
};

View File

@@ -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) {