remove event type list from Events (lazy listener initialization) p=tschaub,me r=erilem (closes #2555)
git-svn-id: http://svn.openlayers.org/trunk/openlayers@12384 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
+35
-63
@@ -419,12 +419,6 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
*/
|
||||
element: null,
|
||||
|
||||
/**
|
||||
* Property: eventTypes
|
||||
* {Array(String)} list of support application events
|
||||
*/
|
||||
eventTypes: null,
|
||||
|
||||
/**
|
||||
* Property: eventHandler
|
||||
* {Function} bound event handler attached to elements
|
||||
@@ -480,7 +474,9 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
* Parameters:
|
||||
* object - {Object} The js object to which this Events object is being added
|
||||
* element - {DOMElement} A dom element to respond to browser events
|
||||
* eventTypes - {Array(String)} Array of custom application events
|
||||
* eventTypes - {Array(String)} Deprecated. Array of custom application
|
||||
* events. A listener may be registered for any named event, regardless
|
||||
* of the values provided here.
|
||||
* fallThrough - {Boolean} Allow events to fall through after these have
|
||||
* been handled?
|
||||
* options - {Object} Options for the events object.
|
||||
@@ -490,30 +486,20 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
this.object = object;
|
||||
this.fallThrough = fallThrough;
|
||||
this.listeners = {};
|
||||
|
||||
// keep a bound copy of handleBrowserEvent() so that we can
|
||||
// pass the same function to both Event.observe() and .stopObserving()
|
||||
this.eventHandler = OpenLayers.Function.bindAsEventListener(
|
||||
this.handleBrowserEvent, this
|
||||
);
|
||||
|
||||
// to be used with observe and stopObserving
|
||||
this.clearMouseListener = OpenLayers.Function.bind(
|
||||
this.clearMouseCache, this
|
||||
);
|
||||
|
||||
// if eventTypes is specified, create a listeners list for each
|
||||
// custom application event.
|
||||
this.eventTypes = [];
|
||||
if (eventTypes != null) {
|
||||
for (var i=0, len=eventTypes.length; i<len; i++) {
|
||||
this.addEventType(eventTypes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// if a dom element is specified, add a listeners list
|
||||
// for browser events on the element and register them
|
||||
if (element != null) {
|
||||
// keep a bound copy of handleBrowserEvent() so that we can
|
||||
// pass the same function to both Event.observe() and .stopObserving()
|
||||
this.eventHandler = OpenLayers.Function.bindAsEventListener(
|
||||
this.handleBrowserEvent, this
|
||||
);
|
||||
|
||||
// to be used with observe and stopObserving
|
||||
this.clearMouseListener = OpenLayers.Function.bind(
|
||||
this.clearMouseCache, this
|
||||
);
|
||||
this.attachToElement(element);
|
||||
}
|
||||
},
|
||||
@@ -534,24 +520,18 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
|
||||
this.listeners = null;
|
||||
this.object = null;
|
||||
this.eventTypes = null;
|
||||
this.fallThrough = null;
|
||||
this.eventHandler = null;
|
||||
},
|
||||
|
||||
/**
|
||||
* APIMethod: addEventType
|
||||
* Add a new event type to this events object.
|
||||
* If the event type has already been added, do nothing.
|
||||
* Deprecated. Any event can be triggered without adding it first.
|
||||
*
|
||||
* Parameters:
|
||||
* eventName - {String}
|
||||
*/
|
||||
addEventType: function(eventName) {
|
||||
if (!this.listeners[eventName]) {
|
||||
this.eventTypes.push(eventName);
|
||||
this.listeners[eventName] = [];
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -565,15 +545,11 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
OpenLayers.Event.stopObservingElement(this.element);
|
||||
}
|
||||
this.element = element;
|
||||
for (var i=0, len=this.BROWSER_EVENTS.length; i<len; i++) {
|
||||
var eventType = this.BROWSER_EVENTS[i];
|
||||
|
||||
// every browser event has a corresponding application event
|
||||
// (whether it's listened for or not).
|
||||
this.addEventType(eventType);
|
||||
|
||||
// use Prototype to register the event cross-browser
|
||||
OpenLayers.Event.observe(element, eventType, this.eventHandler);
|
||||
for (var i = 0, len = this.BROWSER_EVENTS.length; i < len; i++) {
|
||||
// register the event cross-browser
|
||||
OpenLayers.Event.observe(
|
||||
element, this.BROWSER_EVENTS[i], this.eventHandler
|
||||
);
|
||||
}
|
||||
// disable dragstart in IE so that mousedown/move/up works normally
|
||||
OpenLayers.Event.observe(element, "dragstart", OpenLayers.Event.stop);
|
||||
@@ -610,7 +586,7 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
*/
|
||||
on: function(object) {
|
||||
for(var type in object) {
|
||||
if(type != "scope") {
|
||||
if(type != "scope" && object.hasOwnProperty(type)) {
|
||||
this.register(type, object.scope, object[type]);
|
||||
}
|
||||
}
|
||||
@@ -640,19 +616,24 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
* 'object' property.
|
||||
* func - {Function} The callback function. If no callback is
|
||||
* specified, this function does nothing.
|
||||
*
|
||||
*
|
||||
* priority - {Boolean} If true, adds the new listener to the *front* of
|
||||
* the events queue instead of to the end.
|
||||
*/
|
||||
register: function (type, obj, func) {
|
||||
|
||||
if ( (func != null) &&
|
||||
(OpenLayers.Util.indexOf(this.eventTypes, type) != -1) ) {
|
||||
|
||||
register: function (type, obj, func, priority) {
|
||||
if (func != null) {
|
||||
if (obj == null) {
|
||||
obj = this.object;
|
||||
}
|
||||
var listeners = this.listeners[type];
|
||||
listeners.push( {obj: obj, func: func} );
|
||||
if (!listeners) {
|
||||
listeners = [];
|
||||
this.listeners[type] = listeners;
|
||||
}
|
||||
if (priority) {
|
||||
listeners.unshift({obj: obj, func: func});
|
||||
} else {
|
||||
listeners.push({obj: obj, func: func});
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -674,16 +655,7 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
* specified, this function does nothing.
|
||||
*/
|
||||
registerPriority: function (type, obj, func) {
|
||||
|
||||
if (func != null) {
|
||||
if (obj == null) {
|
||||
obj = this.object;
|
||||
}
|
||||
var listeners = this.listeners[type];
|
||||
if (listeners != null) {
|
||||
listeners.unshift( {obj: obj, func: func} );
|
||||
}
|
||||
}
|
||||
this.register(type, obj, func, true);
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -714,7 +686,7 @@ OpenLayers.Events = OpenLayers.Class({
|
||||
*/
|
||||
un: function(object) {
|
||||
for(var type in object) {
|
||||
if(type != "scope") {
|
||||
if(type != "scope" && object.hasOwnProperty(type)) {
|
||||
this.unregister(type, object.scope, object[type]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user