Improving documentation for extensions.

Includes a currently non-functional change to make OpenLayers.Events work with extensions like the one in the code example.
This commit is contained in:
ahocevar
2012-01-22 15:31:57 +01:00
parent 3b96046669
commit 1ecc5d6c90

View File

@@ -452,7 +452,9 @@ OpenLayers.Events = OpenLayers.Class({
/** /**
* APIProperty: extensions * APIProperty: extensions
* {Object} Event extensions registered with this instance. Keys are * {Object} Event extensions registered with this instance. Keys are
* event types, values are <OpenLayers.Events.*> extension instances. * event types, values are {OpenLayers.Events.*} extension instances or
* {Boolean} for events that an instantiated extension provides in
* addition to the one it was created for.
* *
* Extensions create an event in addition to browser events, which usually * Extensions create an event in addition to browser events, which usually
* fires when a sequence of browser events is completed. Extensions are * fires when a sequence of browser events is completed. Extensions are
@@ -462,9 +464,9 @@ OpenLayers.Events = OpenLayers.Class({
* Extensions are created in the <OpenLayers.Events> namespace using * Extensions are created in the <OpenLayers.Events> namespace using
* <OpenLayers.Class>, and named after the event they provide. * <OpenLayers.Class>, and named after the event they provide.
* The constructor receives the target <OpenLayers.Events> instance as * The constructor receives the target <OpenLayers.Events> instance as
* argument. Extensions should register their browser events using * argument. Extensions that need to capture browser events before they
* <register>, with {extension: true} as 4th argument. See below for a * propagate can register their listeners events using <register>, with
* minimal extension. * {extension: true} as 4th argument.
* *
* If an extension creates more than one event, an alias for each event * If an extension creates more than one event, an alias for each event
* type should be created and reference the same class. The constructor * type should be created and reference the same class. The constructor
@@ -480,11 +482,14 @@ OpenLayers.Events = OpenLayers.Class({
* this.target = target; * this.target = target;
* this.target.register("click", this, this.doStuff, {extension: true}); * this.target.register("click", this, this.doStuff, {extension: true});
* // only required if extension provides more than one event type * // only required if extension provides more than one event type
* this.target.extensions["foostart"] = this; * this.target.extensions["foostart"] = true;
* this.target.extensions["fooend"] = this; * this.target.extensions["fooend"] = true;
* }, * },
* destroy: function() { * destroy: function() {
* this.target.unregister("click", this, this.doStuff); * this.target.unregister("click", this, this.doStuff);
* // only required if extension provides more than one event type
* delete this.target.extensions["foostart"];
* delete this.target.extensions["fooend"];
* }, * },
* doStuff: function(evt) { * doStuff: function(evt) {
* var propagate = true; * var propagate = true;
@@ -565,8 +570,10 @@ OpenLayers.Events = OpenLayers.Class({
*/ */
destroy: function () { destroy: function () {
for (var e in this.extensions) { for (var e in this.extensions) {
if (typeof this.extensions[e] !== "boolean") {
this.extensions[e].destroy(); this.extensions[e].destroy();
} }
}
this.extensions = null; this.extensions = null;
if (this.element) { if (this.element) {
OpenLayers.Event.stopObservingElement(this.element); OpenLayers.Event.stopObservingElement(this.element);