update default behaviour of popups. now you can click and drag inside a popup without the events dropping through to the map, yet if you are dragging a zoombox over a popup, it still responds. this is all thanks to a new function i am adding to Util.js which is called OpenLayers.Util.safeStopPropagaition(). Turns out the default Event.stop() from prototype.js is also calling a function called preventDefault() which disallows things like selecting text or clicking a hyperlink. all tests pass.

git-svn-id: http://svn.openlayers.org/trunk/openlayers@1438 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2006-09-13 08:20:02 +00:00
parent 6793507a34
commit 7ce7f2484b
4 changed files with 114 additions and 8 deletions

View File

@@ -75,7 +75,7 @@ OpenLayers.Popup.prototype = {
this.div = OpenLayers.Util.createDiv(this.id, null, null,
null, null, null, "hidden");
this.events = new OpenLayers.Events(this, this.div, null);
this.registerEvents();
},
/**
@@ -231,5 +231,86 @@ OpenLayers.Popup.prototype = {
}
},
/** Do this in a separate function so that subclasses can
* choose to override it if they wish to deal differently
* with mouse events
*
* Note in the following handler functions that some special
* care is needed to deal correctly with mousing and popups.
*
* Because the user might select the zoom-rectangle option and
* then drag it over a popup, we need a safe way to allow the
* mousemove and mouseup events to pass through the popup when
* they are initiated from outside.
*
* Otherwise, we want to essentially kill the event propagation
* for all other events, though we have to do so carefully,
* without disabling basic html functionality, like clicking on
* hyperlinks or drag-selecting text.
*/
registerEvents:function() {
Event.observe(this.div, "mousedown",
this.onmousedown.bindAsEventListener(this));
Event.observe(this.div, "mousemove",
this.onmousemove.bindAsEventListener(this));
Event.observe(this.div, "mouseup",
this.onmouseup.bindAsEventListener(this));
Event.observe(this.div, "click",
OpenLayers.Util.safeStopPropagation);
Event.observe(this.div, "mouseout",
this.onmouseout.bindAsEventListener(this));
Event.observe(this.div, "dblclick",
OpenLayers.Util.safeStopPropagation);
},
/** When mouse goes down within the popup, make a note of
* it locally, and then do not propagate the mousedown
* (but do so safely so that user can select text inside)
*
* @param {Event} evt
*/
onmousedown: function (evt) {
this.mousedown = true;
OpenLayers.Util.safeStopPropagation(evt);
},
/** If the drag was started within the popup, then
* do not propagate the mousemove (but do so safely
* so that user can select text inside)
*
* @param {Event} evt
*/
onmousemove: function (evt) {
if (this.mousedown) {
OpenLayers.Util.safeStopPropagation(evt);
}
},
/** When mouse comes up within the popup, after going down
* in it, reset the flag, and then (once again) do not
* propagate the event, but do so safely so that user can
* select text inside
*
* @param {Event} evt
*/
onmouseup: function (evt) {
if (this.mousedown) {
this.mousedown = false;
OpenLayers.Util.safeStopPropagation(evt);
}
},
/** 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.
*
* @param {Event} evt
*
* @type Boolean
*/
onmouseout: function (evt) {
this.mousedown = false;
},
CLASS_NAME: "OpenLayers.Popup"
};

View File

@@ -516,3 +516,16 @@ OpenLayers.Util.getResolutionFromScale = function (scale, units) {
* OpenLayers.DOTS_PER_INCH);
return resolution;
};
/** 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.returnValue = false;
evt.cancelBubble = true;
};