Trigger feature related events with feature information and layer related events with layer information. Also adding events.on and events.un convenience methods. r=crschmidt (closes #1343)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@6149 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2008-02-08 23:31:27 +00:00
parent 464fb30589
commit f27833f1db
20 changed files with 326 additions and 118 deletions
+45 -10
View File
@@ -481,6 +481,27 @@ OpenLayers.Events = OpenLayers.Class({
// disable dragstart in IE so that mousedown/move/up works normally
OpenLayers.Event.observe(element, "dragstart", OpenLayers.Event.stop);
},
/**
* Method: on
* Convenience method for registering listeners with a common scope.
*
* Example use:
* (code)
* events.on({
* "loadstart": loadStartListener,
* "loadend": loadEndListener,
* scope: object
* });
* (end)
*/
on: function(object) {
for(var type in object) {
if(type != "scope") {
this.register(type, object.scope, object[type]);
}
}
},
/**
* APIMethod: register
@@ -552,6 +573,27 @@ OpenLayers.Events = OpenLayers.Class({
}
},
/**
* Method: un
* Convenience method for unregistering listeners with a common scope.
*
* Example use:
* (code)
* events.un({
* "loadstart": loadStartListener,
* "loadend": loadEndListener,
* scope: object
* });
* (end)
*/
un: function(object) {
for(var type in object) {
if(type != "scope") {
this.unregister(type, object.scope, object[type]);
}
}
},
/**
* APIMethod: unregister
*
@@ -596,13 +638,12 @@ OpenLayers.Events = OpenLayers.Class({
* Parameters:
* type - {String}
* evt - {Event}
* args - {Array} Optional array of arguments to call the listener with.
*
* Returns:
* {Boolean} The last listener return. If a listener returns false, the
* chain of listeners will stop getting called.
*/
triggerEvent: function (type, evt, args) {
triggerEvent: function (type, evt) {
// prep evt object with object & div references
if (evt == null) {
@@ -610,13 +651,7 @@ OpenLayers.Events = OpenLayers.Class({
}
evt.object = this.object;
evt.element = this.element;
if(!args) {
args = [evt];
} else {
args.unshift(evt);
}
// execute all callbacks registered for specified type
// get a clone of the listeners array to
// allow for splicing during callbacks
@@ -627,7 +662,7 @@ OpenLayers.Events = OpenLayers.Class({
for (var i = 0; i < listeners.length; i++) {
var callback = listeners[i];
// bind the context to callback.obj
continueChain = callback.func.apply(callback.obj, args);
continueChain = callback.func.apply(callback.obj, [evt]);
if ((continueChain != undefined) && (continueChain == false)) {
// if callback returns false, execute no more callbacks.