Don't let button controls interfer with handlers.
This change involves removal of the map's eventsDiv and introduces an OpenLayers.Events.buttonclick component that adds a buttonclick event which makes sure that only events that are not related to clicking a button propagate. This allows button controls to be on the map's viewPortDiv again.
This commit is contained in:
@@ -155,13 +155,18 @@ OpenLayers.Event = {
|
||||
* Parameters:
|
||||
* event - {Event}
|
||||
* allowDefault - {Boolean} If true, we stop the event chain but
|
||||
* still allow the default browser
|
||||
* behaviour (text selection, radio-button
|
||||
* clicking, etc)
|
||||
* Default false
|
||||
* still allow the default browser behaviour (text selection,
|
||||
* radio-button clicking, etc). Default is false.
|
||||
* terminate - {Boolean} If true, no more listeners registered through an
|
||||
* <OpenLayers.Events> instance on the same event on the same element
|
||||
* will receive this event. Extensions that call <stop> should set
|
||||
* this to true. Default is false.
|
||||
*/
|
||||
stop: function(event, allowDefault) {
|
||||
stop: function(event, allowDefault, terminate) {
|
||||
|
||||
if (terminate) {
|
||||
event._terminated = true;
|
||||
}
|
||||
if (!allowDefault) {
|
||||
if (event.preventDefault) {
|
||||
event.preventDefault();
|
||||
@@ -450,6 +455,26 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
* the location of the element in the page changes
|
||||
*/
|
||||
includeXY: false,
|
||||
|
||||
/**
|
||||
* Property: extensions
|
||||
* {Object} Event extensions registered with this instance. Keys are
|
||||
* event types, values are <OpenLayers.Events.*> extension instances.
|
||||
*
|
||||
* Extensions create an event in addition to browser events, which usually
|
||||
* fires when a sequence of browser events is completed. Extensions are
|
||||
* automatically instantiated when a listener is registered for an event
|
||||
* provided by an extension.
|
||||
*
|
||||
* Extesions are created in the <OpenLayers.Events> namespace using
|
||||
* <OpenLayers.Class>, and named after the event they provide.
|
||||
* The constructor recieves the target <OpenLayers.Events> instance as
|
||||
* argument. Extensions are expected to have an "observe" method, which is
|
||||
* called to register its sequence events on the target's dom element,
|
||||
* using <OpenLayers.Event.observe>. See <OpenLayers.Events.buttonclick>
|
||||
* for a reference implementation.
|
||||
*/
|
||||
extensions: null,
|
||||
|
||||
/**
|
||||
* Method: clearMouseListener
|
||||
@@ -478,6 +503,7 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
this.object = object;
|
||||
this.fallThrough = fallThrough;
|
||||
this.listeners = {};
|
||||
this.extensions = {};
|
||||
|
||||
// if a dom element is specified, add a listeners list
|
||||
// for browser events on the element and register them
|
||||
@@ -500,6 +526,12 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
* APIMethod: destroy
|
||||
*/
|
||||
destroy: function () {
|
||||
for (var e in this.extensions) {
|
||||
if (typeof this.extensions[e].destroy === "function") {
|
||||
this.extensions[e].destroy();
|
||||
}
|
||||
}
|
||||
this.extensions = null;
|
||||
if (this.element) {
|
||||
OpenLayers.Event.stopObservingElement(this.element);
|
||||
if(this.element.hasScrollEvent) {
|
||||
@@ -531,9 +563,15 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
*
|
||||
* Parameters:
|
||||
* element - {HTMLDOMElement} a DOM element to attach browser events to
|
||||
* options - {Object} Additional options for his method.
|
||||
*
|
||||
* Valid options:
|
||||
* keepElement - {Boolean} If set to true, the instance will not stop
|
||||
* observing events on an element it was previously attached to.
|
||||
*/
|
||||
attachToElement: function (element) {
|
||||
if(this.element) {
|
||||
attachToElement: function (element, options) {
|
||||
options = options || {};
|
||||
if(this.element && !options.keepElement) {
|
||||
OpenLayers.Event.stopObservingElement(this.element);
|
||||
}
|
||||
this.element = element;
|
||||
@@ -547,6 +585,33 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
OpenLayers.Event.observe(element, "dragstart", OpenLayers.Event.stop);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: addExtension
|
||||
* Adds an extension event to this instance.
|
||||
*
|
||||
* Parameters:
|
||||
* type - {String} the name of the extension event type to add
|
||||
*/
|
||||
addExtension: function(type) {
|
||||
if (this.element.attachEvent && !this.element.addEventListener) {
|
||||
// old IE - last registered, first triggered. No need to
|
||||
// re-register the events to get them in a working order
|
||||
this.extensions[type] = new OpenLayers.Events[type](this);
|
||||
} else {
|
||||
// Other browsers - last registered, last triggered. We stop
|
||||
// observing the element, let the extensions register their browser
|
||||
// events, and then we attach this instance to the element again.
|
||||
OpenLayers.Event.stopObservingElement(this.element);
|
||||
for (var t in this.extensions) {
|
||||
if (typeof this.extensions[t].observe === "function") {
|
||||
this.extensions[t].observe();
|
||||
}
|
||||
}
|
||||
this.extensions[type] = new OpenLayers.Events[type](this);
|
||||
this.attachToElement(this.element, {keepElement: true});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: on
|
||||
* Convenience method for registering listeners with a common scope.
|
||||
@@ -612,6 +677,9 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
* the events queue instead of to the end.
|
||||
*/
|
||||
register: function (type, obj, func, priority) {
|
||||
if (type in OpenLayers.Events && !this.extensions[type]) {
|
||||
this.addExtension(type);
|
||||
}
|
||||
if (func != null) {
|
||||
if (obj == null) {
|
||||
obj = this.object;
|
||||
@@ -784,8 +852,8 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
*/
|
||||
handleBrowserEvent: function (evt) {
|
||||
var type = evt.type, listeners = this.listeners[type];
|
||||
if(!listeners || listeners.length == 0) {
|
||||
// noone's listening, bail out
|
||||
if(!listeners || listeners.length == 0 || evt._terminated) {
|
||||
// noone's listening or event was terminated through <stop>, bail out
|
||||
return;
|
||||
}
|
||||
// add clientX & clientY to all events - corresponds to average x, y
|
||||
|
||||
Reference in New Issue
Block a user