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:
@@ -145,9 +145,7 @@ OpenLayers.Control = OpenLayers.Class({
|
||||
events: null,
|
||||
|
||||
/**
|
||||
* Constant: EVENT_TYPES
|
||||
* {Array(String)} Supported application event types. Register a listener
|
||||
* for a particular event with the following syntax:
|
||||
* Register a listener for a particular event with the following syntax:
|
||||
* (code)
|
||||
* control.events.register(type, obj, listener);
|
||||
* (end)
|
||||
@@ -165,7 +163,6 @@ OpenLayers.Control = OpenLayers.Class({
|
||||
* activate - Triggered when activated.
|
||||
* deactivate - Triggered when deactivated.
|
||||
*/
|
||||
EVENT_TYPES: ["activate", "deactivate"],
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Control
|
||||
@@ -187,7 +184,7 @@ OpenLayers.Control = OpenLayers.Class({
|
||||
|
||||
OpenLayers.Util.extend(this, options);
|
||||
|
||||
this.events = new OpenLayers.Events(this, null, this.EVENT_TYPES);
|
||||
this.events = new OpenLayers.Events(this);
|
||||
if(this.eventListeners instanceof Object) {
|
||||
this.events.on(this.eventListeners);
|
||||
}
|
||||
|
||||
@@ -32,12 +32,9 @@ OpenLayers.Control.DrawFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
callbacks: null,
|
||||
|
||||
/**
|
||||
* Constant: EVENT_TYPES
|
||||
*
|
||||
* Supported event types:
|
||||
* featureadded - Triggered when a feature is added
|
||||
*/
|
||||
EVENT_TYPES: ["featureadded"],
|
||||
|
||||
/**
|
||||
* APIProperty: multi
|
||||
@@ -67,13 +64,6 @@ OpenLayers.Control.DrawFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
* options - {Object}
|
||||
*/
|
||||
initialize: function(layer, handler, options) {
|
||||
|
||||
// concatenate events specific to vector with those from the base
|
||||
this.EVENT_TYPES =
|
||||
OpenLayers.Control.DrawFeature.prototype.EVENT_TYPES.concat(
|
||||
OpenLayers.Control.prototype.EVENT_TYPES
|
||||
);
|
||||
|
||||
OpenLayers.Control.prototype.initialize.apply(this, [options]);
|
||||
this.callbacks = OpenLayers.Util.extend(
|
||||
{
|
||||
|
||||
@@ -23,14 +23,12 @@
|
||||
OpenLayers.Control.Geolocate = OpenLayers.Class(OpenLayers.Control, {
|
||||
|
||||
/**
|
||||
* Constant: EVENT_TYPES
|
||||
* Supported event types:
|
||||
* - *locationupdated* Triggered when browser return a new position
|
||||
* - *locationfailed* Triggered when geolocation has failed
|
||||
* - *locationuncapable* Triggered when control is activated on a browser
|
||||
* which doesn't support geolocation
|
||||
*/
|
||||
EVENT_TYPES: ["locationupdated", "locationfailed", "locationuncapable"],
|
||||
|
||||
/**
|
||||
* Property: geolocation
|
||||
@@ -63,15 +61,6 @@ OpenLayers.Control.Geolocate = OpenLayers.Class(OpenLayers.Control, {
|
||||
* Create a new control to deal with browser geolocation API
|
||||
*
|
||||
*/
|
||||
initialize: function(options) {
|
||||
// concatenate events specific to this control with those from the base
|
||||
this.EVENT_TYPES =
|
||||
OpenLayers.Control.Geolocate.prototype.EVENT_TYPES.concat(
|
||||
OpenLayers.Control.prototype.EVENT_TYPES
|
||||
);
|
||||
this.geolocationOptions = {};
|
||||
OpenLayers.Control.prototype.initialize.apply(this, [options]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Method: destroy
|
||||
|
||||
@@ -170,8 +170,6 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
filterType: OpenLayers.Filter.Spatial.BBOX,
|
||||
|
||||
/**
|
||||
* Constant: EVENT_TYPES
|
||||
*
|
||||
* Supported event types:
|
||||
* beforefeatureselected - Triggered when <click> is true before a
|
||||
* feature is selected. The event object has a feature property with
|
||||
@@ -197,9 +195,6 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
* outfeature - Triggered when <hover> is true and the mouse moves
|
||||
* moved away from a hover-selected feature
|
||||
*/
|
||||
EVENT_TYPES: ["featureselected", "featuresselected", "featureunselected",
|
||||
"clickout", "beforefeatureselected", "beforefeaturesselected",
|
||||
"hoverfeature", "outfeature"],
|
||||
|
||||
/**
|
||||
* Constructor: OpenLayers.Control.GetFeature
|
||||
@@ -211,12 +206,6 @@ OpenLayers.Control.GetFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
* made)
|
||||
*/
|
||||
initialize: function(options) {
|
||||
// concatenate events specific to vector with those from the base
|
||||
this.EVENT_TYPES =
|
||||
OpenLayers.Control.GetFeature.prototype.EVENT_TYPES.concat(
|
||||
OpenLayers.Control.prototype.EVENT_TYPES
|
||||
);
|
||||
|
||||
options.handlerOptions = options.handlerOptions || {};
|
||||
|
||||
OpenLayers.Control.prototype.initialize.apply(this, [options]);
|
||||
|
||||
@@ -18,9 +18,7 @@
|
||||
OpenLayers.Control.Measure = OpenLayers.Class(OpenLayers.Control, {
|
||||
|
||||
/**
|
||||
* Constant: EVENT_TYPES
|
||||
* {Array(String)} Supported application event types. Register a listener
|
||||
* for a particular event with the following syntax:
|
||||
* Register a listener for a particular event with the following syntax:
|
||||
* (code)
|
||||
* control.events.register(type, obj, listener);
|
||||
* (end)
|
||||
@@ -37,7 +35,6 @@ OpenLayers.Control.Measure = OpenLayers.Class(OpenLayers.Control, {
|
||||
* measurement sketch is modified. Listeners receive an event with measure,
|
||||
* units, order, and geometry.
|
||||
*/
|
||||
EVENT_TYPES: ['measure', 'measurepartial'],
|
||||
|
||||
/**
|
||||
* APIProperty: handlerOptions
|
||||
@@ -120,11 +117,6 @@ OpenLayers.Control.Measure = OpenLayers.Class(OpenLayers.Control, {
|
||||
* options - {Object}
|
||||
*/
|
||||
initialize: function(handler, options) {
|
||||
// concatenate events specific to measure with those from the base
|
||||
this.EVENT_TYPES =
|
||||
OpenLayers.Control.Measure.prototype.EVENT_TYPES.concat(
|
||||
OpenLayers.Control.prototype.EVENT_TYPES
|
||||
);
|
||||
OpenLayers.Control.prototype.initialize.apply(this, [options]);
|
||||
var callbacks = {done: this.measureComplete,
|
||||
point: this.measurePartial};
|
||||
|
||||
@@ -24,9 +24,7 @@
|
||||
OpenLayers.Control.SLDSelect = OpenLayers.Class(OpenLayers.Control, {
|
||||
|
||||
/**
|
||||
* Constant: EVENT_TYPES
|
||||
* {Array(String)} Supported application event types. Register a listener
|
||||
* for a particular event with the following syntax:
|
||||
* Register a listener for a particular event with the following syntax:
|
||||
* (code)
|
||||
* control.events.register(type, obj, listener);
|
||||
* (end)
|
||||
@@ -41,7 +39,6 @@ OpenLayers.Control.SLDSelect = OpenLayers.Class(OpenLayers.Control, {
|
||||
* array of OpenLayers.Filter objects created in order to perform
|
||||
* the particular selection.
|
||||
*/
|
||||
EVENT_TYPES: ["selected"],
|
||||
|
||||
/**
|
||||
* APIProperty: clearOnDeactivate
|
||||
@@ -148,11 +145,6 @@ OpenLayers.Control.SLDSelect = OpenLayers.Class(OpenLayers.Control, {
|
||||
* selection on.
|
||||
*/
|
||||
initialize: function(handler, options) {
|
||||
// concatenate events specific to this control with those from the base
|
||||
this.EVENT_TYPES =
|
||||
OpenLayers.Control.SLDSelect.prototype.EVENT_TYPES.concat(
|
||||
OpenLayers.Control.prototype.EVENT_TYPES
|
||||
);
|
||||
OpenLayers.Control.prototype.initialize.apply(this, [options]);
|
||||
|
||||
this.callbacks = OpenLayers.Util.extend({done: this.select,
|
||||
|
||||
@@ -22,14 +22,11 @@
|
||||
OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
|
||||
/**
|
||||
* Constant: EVENT_TYPES
|
||||
*
|
||||
* Supported event types:
|
||||
* - *beforefeaturehighlighted* Triggered before a feature is highlighted
|
||||
* - *featurehighlighted* Triggered when a feature is highlighted
|
||||
* - *featureunhighlighted* Triggered when a feature is unhighlighted
|
||||
*/
|
||||
EVENT_TYPES: ["beforefeaturehighlighted", "featurehighlighted", "featureunhighlighted"],
|
||||
|
||||
/**
|
||||
* Property: multipleKey
|
||||
@@ -173,11 +170,6 @@ OpenLayers.Control.SelectFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
* options - {Object}
|
||||
*/
|
||||
initialize: function(layers, options) {
|
||||
// concatenate events specific to this control with those from the base
|
||||
this.EVENT_TYPES =
|
||||
OpenLayers.Control.SelectFeature.prototype.EVENT_TYPES.concat(
|
||||
OpenLayers.Control.prototype.EVENT_TYPES
|
||||
);
|
||||
OpenLayers.Control.prototype.initialize.apply(this, [options]);
|
||||
|
||||
if(this.scope === null) {
|
||||
|
||||
@@ -18,9 +18,7 @@
|
||||
OpenLayers.Control.Snapping = OpenLayers.Class(OpenLayers.Control, {
|
||||
|
||||
/**
|
||||
* Constant: EVENT_TYPES
|
||||
* {Array(String)} Supported application event types. Register a listener
|
||||
* for a particular event with the following syntax:
|
||||
* Register a listener for a particular event with the following syntax:
|
||||
* (code)
|
||||
* control.events.register(type, obj, listener);
|
||||
* (end)
|
||||
@@ -45,7 +43,6 @@ OpenLayers.Control.Snapping = OpenLayers.Class(OpenLayers.Control, {
|
||||
* unsnap - Triggered when a vertex is unsnapped. Listeners receive an
|
||||
* event with a *point* property.
|
||||
*/
|
||||
EVENT_TYPES: ["beforesnap", "snap", "unsnap"],
|
||||
|
||||
/**
|
||||
* CONSTANT: DEFAULTS
|
||||
@@ -175,10 +172,6 @@ OpenLayers.Control.Snapping = OpenLayers.Class(OpenLayers.Control, {
|
||||
* no maximum resolution limit.
|
||||
*/
|
||||
initialize: function(options) {
|
||||
// concatenate events specific to measure with those from the base
|
||||
Array.prototype.push.apply(
|
||||
this.EVENT_TYPES, OpenLayers.Control.prototype.EVENT_TYPES
|
||||
);
|
||||
OpenLayers.Control.prototype.initialize.apply(this, [options]);
|
||||
this.options = options || {}; // TODO: this could be done by the super
|
||||
|
||||
|
||||
@@ -19,9 +19,7 @@
|
||||
OpenLayers.Control.Split = OpenLayers.Class(OpenLayers.Control, {
|
||||
|
||||
/**
|
||||
* Constant: EVENT_TYPES
|
||||
* {Array(String)} Supported application event types. Register a listener
|
||||
* for a particular event with the following syntax:
|
||||
* Register a listener for a particular event with the following syntax:
|
||||
* (code)
|
||||
* control.events.register(type, obj, listener);
|
||||
* (end)
|
||||
@@ -47,7 +45,6 @@ OpenLayers.Control.Split = OpenLayers.Class(OpenLayers.Control, {
|
||||
* sketch or modified feature used as a splitter. The features
|
||||
* property is a list of all resulting features.
|
||||
*/
|
||||
EVENT_TYPES: ["beforesplit", "split", "aftersplit"],
|
||||
|
||||
/**
|
||||
* APIProperty: layer
|
||||
@@ -169,10 +166,6 @@ OpenLayers.Control.Split = OpenLayers.Class(OpenLayers.Control, {
|
||||
* splitting.
|
||||
*/
|
||||
initialize: function(options) {
|
||||
// concatenate events specific to measure with those from the base
|
||||
Array.prototype.push.apply(
|
||||
this.EVENT_TYPES, OpenLayers.Control.prototype.EVENT_TYPES
|
||||
);
|
||||
OpenLayers.Control.prototype.initialize.apply(this, [options]);
|
||||
this.options = options || {}; // TODO: this could be done by the super
|
||||
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
OpenLayers.Control.TransformFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
|
||||
/**
|
||||
* Constant: EVENT_TYPES
|
||||
*
|
||||
* Supported event types:
|
||||
* - *beforesetfeature* Triggered before a feature is set for
|
||||
* tranformation. The feature will not be set if a listener returns
|
||||
@@ -51,8 +49,6 @@ OpenLayers.Control.TransformFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
* - *transformcomplete* Triggered after dragging. Listeners receive
|
||||
* an event object with the transformed *feature*.
|
||||
*/
|
||||
EVENT_TYPES: ["beforesetfeature", "setfeature", "beforetransform",
|
||||
"transform", "transformcomplete"],
|
||||
|
||||
/**
|
||||
* APIProperty: geometryTypes
|
||||
@@ -181,11 +177,6 @@ OpenLayers.Control.TransformFeature = OpenLayers.Class(OpenLayers.Control, {
|
||||
* control.
|
||||
*/
|
||||
initialize: function(layer, options) {
|
||||
// concatenate events specific to this control with those from the base
|
||||
this.EVENT_TYPES =
|
||||
OpenLayers.Control.TransformFeature.prototype.EVENT_TYPES.concat(
|
||||
OpenLayers.Control.prototype.EVENT_TYPES
|
||||
);
|
||||
OpenLayers.Control.prototype.initialize.apply(this, [options]);
|
||||
|
||||
this.layer = layer;
|
||||
|
||||
@@ -155,8 +155,6 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
hoverRequest: null,
|
||||
|
||||
/**
|
||||
* Constant: EVENT_TYPES
|
||||
*
|
||||
* Supported event types (in addition to those from <OpenLayers.Control>):
|
||||
* beforegetfeatureinfo - Triggered before the request is sent.
|
||||
* The event object has an *xy* property with the position of the
|
||||
@@ -172,7 +170,6 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
* layers, *text* and *request* will only contain the response body
|
||||
* and request object of the last request.
|
||||
*/
|
||||
EVENT_TYPES: ["beforegetfeatureinfo", "nogetfeatureinfo", "getfeatureinfo"],
|
||||
|
||||
/**
|
||||
* Constructor: <OpenLayers.Control.WMSGetFeatureInfo>
|
||||
@@ -181,12 +178,6 @@ OpenLayers.Control.WMSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
* options - {Object}
|
||||
*/
|
||||
initialize: function(options) {
|
||||
// concatenate events specific to vector with those from the base
|
||||
this.EVENT_TYPES =
|
||||
OpenLayers.Control.WMSGetFeatureInfo.prototype.EVENT_TYPES.concat(
|
||||
OpenLayers.Control.prototype.EVENT_TYPES
|
||||
);
|
||||
|
||||
options = options || {};
|
||||
options.handlerOptions = options.handlerOptions || {};
|
||||
|
||||
|
||||
@@ -136,8 +136,6 @@ OpenLayers.Control.WMTSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
hoverRequest: null,
|
||||
|
||||
/**
|
||||
* Constant: EVENT_TYPES
|
||||
*
|
||||
* Supported event types (in addition to those from <OpenLayers.Control>):
|
||||
* beforegetfeatureinfo - Triggered before each request is sent.
|
||||
* The event object has an *xy* property with the position of the
|
||||
@@ -157,7 +155,6 @@ OpenLayers.Control.WMTSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
* an event with *request*, *xy*, and *layer* properties. In the case
|
||||
* of a parsing error, the event will also contain an *error* property.
|
||||
*/
|
||||
EVENT_TYPES: ["beforegetfeatureinfo", "getfeatureinfo", "exception"],
|
||||
|
||||
/**
|
||||
* Property: pending
|
||||
@@ -172,12 +169,6 @@ OpenLayers.Control.WMTSGetFeatureInfo = OpenLayers.Class(OpenLayers.Control, {
|
||||
* options - {Object}
|
||||
*/
|
||||
initialize: function(options) {
|
||||
// concatenate events specific to vector with those from the base
|
||||
this.EVENT_TYPES =
|
||||
OpenLayers.Control.WMTSGetFeatureInfo.prototype.EVENT_TYPES.concat(
|
||||
OpenLayers.Control.prototype.EVENT_TYPES
|
||||
);
|
||||
|
||||
options = options || {};
|
||||
options.handlerOptions = options.handlerOptions || {};
|
||||
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,9 +58,7 @@ OpenLayers.Layer = OpenLayers.Class({
|
||||
alwaysInRange: null,
|
||||
|
||||
/**
|
||||
* Constant: EVENT_TYPES
|
||||
* {Array(String)} Supported application event types. Register a listener
|
||||
* for a particular event with the following syntax:
|
||||
* Register a listener for a particular event with the following syntax:
|
||||
* (code)
|
||||
* layer.events.register(type, obj, listener);
|
||||
* (end)
|
||||
@@ -89,8 +87,6 @@ OpenLayers.Layer = OpenLayers.Class({
|
||||
* will receive an object with a *map* property referencing the map and
|
||||
* a *layer* property referencing the layer.
|
||||
*/
|
||||
EVENT_TYPES: ["loadstart", "loadend", "loadcancel", "visibilitychanged",
|
||||
"move", "moveend", "added", "removed"],
|
||||
|
||||
/**
|
||||
* Constant: RESOLUTION_PROPERTIES
|
||||
@@ -351,8 +347,7 @@ OpenLayers.Layer = OpenLayers.Class({
|
||||
this.div.style.height = "100%";
|
||||
this.div.dir = "ltr";
|
||||
|
||||
this.events = new OpenLayers.Events(this, this.div,
|
||||
this.EVENT_TYPES);
|
||||
this.events = new OpenLayers.Events(this, this.div);
|
||||
if(this.eventListeners instanceof Object) {
|
||||
this.events.on(this.eventListeners);
|
||||
}
|
||||
|
||||
@@ -24,9 +24,7 @@
|
||||
OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
|
||||
|
||||
/**
|
||||
* Constant: EVENT_TYPES
|
||||
* {Array(String)} Supported application event types. Register a listener
|
||||
* for a particular event with the following syntax:
|
||||
* Register a listener for a particular event with the following syntax:
|
||||
* (code)
|
||||
* layer.events.register(type, obj, listener);
|
||||
* (end)
|
||||
@@ -111,13 +109,6 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
|
||||
* refresh - Triggered when something wants a strategy to ask the protocol
|
||||
* for a new set of features.
|
||||
*/
|
||||
EVENT_TYPES: ["beforefeatureadded", "beforefeaturesadded",
|
||||
"featureadded", "featuresadded", "beforefeatureremoved",
|
||||
"beforefeaturesremoved", "featureremoved", "featuresremoved",
|
||||
"beforefeatureselected", "featureselected", "featureunselected",
|
||||
"beforefeaturemodified", "featuremodified", "afterfeaturemodified",
|
||||
"vertexmodified", "vertexremoved", "sketchstarted",
|
||||
"sketchmodified", "sketchcomplete", "refresh"],
|
||||
|
||||
/**
|
||||
* APIProperty: isBaseLayer
|
||||
@@ -240,13 +231,6 @@ OpenLayers.Layer.Vector = OpenLayers.Class(OpenLayers.Layer, {
|
||||
* {<OpenLayers.Layer.Vector>} A new vector layer
|
||||
*/
|
||||
initialize: function(name, options) {
|
||||
|
||||
// concatenate events specific to vector with those from the base
|
||||
this.EVENT_TYPES =
|
||||
OpenLayers.Layer.Vector.prototype.EVENT_TYPES.concat(
|
||||
OpenLayers.Layer.prototype.EVENT_TYPES
|
||||
);
|
||||
|
||||
OpenLayers.Layer.prototype.initialize.apply(this, arguments);
|
||||
|
||||
// allow user-set renderer, otherwise assign one
|
||||
|
||||
@@ -36,9 +36,7 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
},
|
||||
|
||||
/**
|
||||
* Constant: EVENT_TYPES
|
||||
* {Array(String)} Supported application event types. Register a listener
|
||||
* for a particular event with the following syntax:
|
||||
* Register a listener for a particular event with the following syntax:
|
||||
* (code)
|
||||
* map.events.register(type, obj, listener);
|
||||
* (end)
|
||||
@@ -85,13 +83,6 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
* - *mousemove* triggered after mousemove the map
|
||||
* - *changebaselayer* triggered after the base layer changes
|
||||
*/
|
||||
EVENT_TYPES: [
|
||||
"preaddlayer", "addlayer","preremovelayer", "removelayer",
|
||||
"changelayer", "movestart",
|
||||
"move", "moveend", "zoomend", "popupopen", "popupclose",
|
||||
"addmarker", "removemarker", "clearmarkers", "mouseover",
|
||||
"mouseout", "mousemove", "dragstart", "drag", "dragend",
|
||||
"changebaselayer"],
|
||||
|
||||
/**
|
||||
* Property: id
|
||||
@@ -538,7 +529,7 @@ OpenLayers.Map = OpenLayers.Class({
|
||||
this.viewPortDiv.appendChild(eventsDiv);
|
||||
this.eventsDiv = eventsDiv;
|
||||
this.events = new OpenLayers.Events(
|
||||
this, this.eventsDiv, this.EVENT_TYPES, this.fallThrough,
|
||||
this, this.eventsDiv, null, this.fallThrough,
|
||||
{includeXY: true}
|
||||
);
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ OpenLayers.Marker = OpenLayers.Class({
|
||||
this.icon.offset = newIcon.offset;
|
||||
this.icon.calculateOffset = newIcon.calculateOffset;
|
||||
}
|
||||
this.events = new OpenLayers.Events(this, this.icon.imageDiv, null);
|
||||
this.events = new OpenLayers.Events(this, this.icon.imageDiv);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -40,7 +40,7 @@ OpenLayers.Marker.Box = OpenLayers.Class(OpenLayers.Marker, {
|
||||
this.bounds = bounds;
|
||||
this.div = OpenLayers.Util.createDiv();
|
||||
this.div.style.overflow = 'hidden';
|
||||
this.events = new OpenLayers.Events(this, this.div, null);
|
||||
this.events = new OpenLayers.Events(this, this.div);
|
||||
this.setBorder(borderColor, borderWidth);
|
||||
},
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ OpenLayers.Request = {
|
||||
* success - Triggered when the HTTP response has a success code (200-299).
|
||||
* failure - Triggered when the HTTP response does not have a success code.
|
||||
*/
|
||||
events: new OpenLayers.Events(this, null, ["complete", "success", "failure"]),
|
||||
events: new OpenLayers.Events(this),
|
||||
|
||||
/**
|
||||
* APIMethod: issue
|
||||
|
||||
@@ -20,19 +20,17 @@
|
||||
OpenLayers.Strategy.Save = OpenLayers.Class(OpenLayers.Strategy, {
|
||||
|
||||
/**
|
||||
* Constant: EVENT_TYPES
|
||||
* {Array(String)} Supported application event types. Register a listener
|
||||
* for a particular event with the following syntax:
|
||||
* Register a listener for a particular event with the following syntax:
|
||||
* (code)
|
||||
* strategy.events.register(type, obj, listener);
|
||||
* (end)
|
||||
*
|
||||
* Supported event types:
|
||||
* - *start* Triggered before saving
|
||||
* - *success* Triggered after a successful transaction
|
||||
* - *fail* Triggered after a failed transaction
|
||||
*
|
||||
*/
|
||||
EVENT_TYPES: ["start", "success", "fail"],
|
||||
|
||||
/**
|
||||
* Property: events
|
||||
@@ -66,7 +64,7 @@ OpenLayers.Strategy.Save = OpenLayers.Class(OpenLayers.Strategy, {
|
||||
*/
|
||||
initialize: function(options) {
|
||||
OpenLayers.Strategy.prototype.initialize.apply(this, [options]);
|
||||
this.events = new OpenLayers.Events(this, null, this.EVENT_TYPES);
|
||||
this.events = new OpenLayers.Events(this);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,10 +26,12 @@
|
||||
OpenLayers.Tile = OpenLayers.Class({
|
||||
|
||||
/**
|
||||
* Constant: EVENT_TYPES
|
||||
* {Array(String)} Supported application event types
|
||||
* Supported event types:
|
||||
* - *loadstart* Triggered when tile loading starts.
|
||||
* - *loadend* Triggered when tile loading ends.
|
||||
* - *reload* Triggered when an already loading tile is reloaded.
|
||||
* - *unload* Triggered before a tile is unloaded.
|
||||
*/
|
||||
EVENT_TYPES: [ "loadstart", "loadend", "reload", "unload"],
|
||||
|
||||
/**
|
||||
* APIProperty: events
|
||||
@@ -110,7 +112,7 @@ OpenLayers.Tile = OpenLayers.Class({
|
||||
//give the tile a unique id based on its BBOX.
|
||||
this.id = OpenLayers.Util.createUniqueID("Tile_");
|
||||
|
||||
this.events = new OpenLayers.Events(this, null, this.EVENT_TYPES);
|
||||
this.events = new OpenLayers.Events(this);
|
||||
|
||||
OpenLayers.Util.extend(this, options);
|
||||
},
|
||||
|
||||
@@ -4,12 +4,10 @@
|
||||
<script type="text/javascript">
|
||||
|
||||
function test_initialize(t) {
|
||||
t.plan(2);
|
||||
t.plan(1);
|
||||
var control = new OpenLayers.Control.DrawFeature("foo", function() {});
|
||||
t.ok(control instanceof OpenLayers.Control.DrawFeature,
|
||||
"constructor returns an instance");
|
||||
t.ok(OpenLayers.Util.indexOf(control.EVENT_TYPES, "featureadded") > -1,
|
||||
"featureadded event in EVENT_TYPES");
|
||||
}
|
||||
|
||||
function test_multi(t) {
|
||||
|
||||
@@ -7,38 +7,22 @@
|
||||
var a;
|
||||
|
||||
function test_Events_constructor (t) {
|
||||
t.plan(4);
|
||||
|
||||
var mapDiv = OpenLayers.Util.getElement('map');
|
||||
var obj = {result: 0};
|
||||
var eventTypes = ["doThingA", "doThingB", "doThingC"];
|
||||
var browserTypes = OpenLayers.Events.prototype.BROWSER_EVENTS;
|
||||
|
||||
var totalTests = 4 + 2*eventTypes.length + 2*browserTypes.length;
|
||||
|
||||
t.plan( totalTests );
|
||||
|
||||
events = new OpenLayers.Events(obj, mapDiv, eventTypes);
|
||||
|
||||
events = new OpenLayers.Events(obj, mapDiv);
|
||||
t.ok( events instanceof OpenLayers.Events, "new OpenLayers.Control returns object" );
|
||||
|
||||
t.ok(events.object ==obj, " 'object' property correctly set");
|
||||
t.ok(events.element == mapDiv, " 'element' property correctly set");
|
||||
|
||||
|
||||
for (var i = 0; i < browserTypes.length; i++) {
|
||||
var type = browserTypes[i];
|
||||
t.ok( events.listeners[type] instanceof Array, "browser event: " + type + " correctly registered" );
|
||||
t.ok( OpenLayers.Util.indexOf(events.eventTypes, type) != -1, "browser type " + type + "' correctly added to eventTypes array");
|
||||
}
|
||||
for (var i = 0; i < eventTypes.length; i++) {
|
||||
var type = eventTypes[i];
|
||||
t.ok( events.listeners[type] instanceof Array, "custom event: " + type + " correctly registered");
|
||||
t.ok( OpenLayers.Util.indexOf(events.eventTypes, type) != -1, "eventType " + type + "' correctly added to eventTypes array");
|
||||
}
|
||||
events.destroy();
|
||||
|
||||
// default/nulls
|
||||
events = new OpenLayers.Events(null, null, null);
|
||||
t.ok( events.listeners != null,
|
||||
"init of Events with null object/element/eventTypes still creates listeners array" );
|
||||
events.destroy();
|
||||
}
|
||||
|
||||
function test_Events_register(t){
|
||||
@@ -59,8 +43,7 @@
|
||||
gFuncB = options.func;
|
||||
}
|
||||
}
|
||||
},
|
||||
'eventTypes': ['listenerA', 'listenerB']
|
||||
}
|
||||
};
|
||||
|
||||
var type = null;
|
||||
@@ -99,13 +82,12 @@
|
||||
|
||||
function test_Events_register_unregister(t) {
|
||||
|
||||
t.plan( 18 );
|
||||
t.plan(19);
|
||||
|
||||
var mapDiv = OpenLayers.Util.getElement('map');
|
||||
var obj = {result: 0};
|
||||
var eventTypes = ["doThingA", "doThingB", "doThingC"];
|
||||
|
||||
events = new OpenLayers.Events(obj, mapDiv, eventTypes);
|
||||
events = new OpenLayers.Events(obj, mapDiv);
|
||||
|
||||
var func = function () { this.result++ }
|
||||
events.register( "doThingA", obj, func );
|
||||
@@ -136,8 +118,11 @@
|
||||
var listenerList = events.listeners["doThingA"];
|
||||
t.eq( listenerList.length, 3, "register correctly does not append null callback to event.listeners[doThingA] even when obj passed in is null" );
|
||||
|
||||
events.register( "chicken", obj, func);
|
||||
t.ok( events.listeners["chicken"] == null, "register() does nothing on attempt to register un-enabled event");
|
||||
events.register("chicken", obj, func);
|
||||
t.eq(events.listeners["chicken"].length, 1, "register() allows listeners for any named event");
|
||||
|
||||
events.unregister("chicken", obj, func);
|
||||
t.eq(events.listeners["chicken"].length, 0, "unregistering an event that is not in eventTypes list works")
|
||||
|
||||
events.unregister("doThingA", obj, null);
|
||||
var listenerList = events.listeners["doThingA"];
|
||||
@@ -174,9 +159,12 @@
|
||||
events.unregister("doThingA", obj, null);
|
||||
t.ok( (listenerList.length == 1), "unregister does not bomb if you try to remove a null callback" );
|
||||
|
||||
events.unregister("chicken", null, func3);
|
||||
t.ok( events.listeners["chicken"] == null, "unregistering an event that is not enabled does not wierdly enable it -- or cause a script error")
|
||||
|
||||
try {
|
||||
events.unregister("asdf", obj, func);
|
||||
t.ok("unregistering for an event with no registered listeners works");
|
||||
} catch (err) {
|
||||
t.fail("unregistering for an event with no registered listeners causes trouble: " + err);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -186,9 +174,8 @@
|
||||
|
||||
var mapDiv = OpenLayers.Util.getElement('map');
|
||||
var obj = {result: 0};
|
||||
var eventTypes = ["doThingA", "doThingB", "doThingC"];
|
||||
|
||||
events = new OpenLayers.Events(obj, mapDiv, eventTypes);
|
||||
events = new OpenLayers.Events(obj, mapDiv);
|
||||
|
||||
var func = function () { this.result++ }
|
||||
var func2 = function () { this.result-- }
|
||||
@@ -213,9 +200,8 @@
|
||||
|
||||
var mapDiv = OpenLayers.Util.getElement('map');
|
||||
var obj = {result: 0};
|
||||
var eventTypes = ["doThingA", "doThingB", "doThingC"];
|
||||
|
||||
events = new OpenLayers.Events(obj, mapDiv, eventTypes);
|
||||
events = new OpenLayers.Events(obj, mapDiv);
|
||||
|
||||
|
||||
var func = function () { this.result++ }
|
||||
@@ -248,7 +234,7 @@
|
||||
//no specific t.ok for this one, but if it breaks, you will know it.
|
||||
events.triggerEvent("chicken");
|
||||
|
||||
events = new OpenLayers.Events(null, mapDiv, eventTypes);
|
||||
events = new OpenLayers.Events(null, mapDiv);
|
||||
|
||||
// a is global variable (context-irrelevant)
|
||||
a = 0;
|
||||
@@ -259,8 +245,7 @@
|
||||
t.eq(a, 5, "if Events has no object set and an event is registered also with no object, triggerEvent() calls it without trying to set the context to null");
|
||||
|
||||
// trigger events with additional arguments
|
||||
eventTypes = ["something"];
|
||||
events = new OpenLayers.Events(null, null, eventTypes);
|
||||
events = new OpenLayers.Events();
|
||||
var instance = {id: Math.random()};
|
||||
var listener = function(obj) {
|
||||
t.eq(this.id, instance.id,
|
||||
@@ -309,7 +294,7 @@
|
||||
|
||||
function test_Events_handleBrowserEvent(t) {
|
||||
t.plan(2);
|
||||
var events = new OpenLayers.Events({}, null, ['sometouchevent']);
|
||||
var events = new OpenLayers.Events({}, null);
|
||||
events.on({'sometouchevent': function() {}});
|
||||
|
||||
// this test verifies that when handling a touch event we correctly
|
||||
@@ -424,36 +409,6 @@
|
||||
|
||||
}
|
||||
|
||||
function test_Events_addEventType(t) {
|
||||
|
||||
t.plan( 8 );
|
||||
|
||||
var mapDiv = OpenLayers.Util.getElement('map');
|
||||
var obj = {result: 0};
|
||||
var eventTypes = ["doThingA", "doThingB"];
|
||||
|
||||
events = new OpenLayers.Events(obj, mapDiv, eventTypes);
|
||||
|
||||
|
||||
t.eq( events.listeners["doThingA"].length, 0, "event type passed as passed as param to OpenLayers.Events constructor correctly set up" );
|
||||
t.eq( events.listeners["doThingB"].length, 0, "event type passed as passed as param to OpenLayers.Events constructor correctly set up" );
|
||||
|
||||
var newEventType = "onFoo";
|
||||
t.ok( events.listeners[newEventType] == null, "event type not yet registered has null entry in listeners array");
|
||||
t.ok( OpenLayers.Util.indexOf(events.eventTypes, newEventType) == -1, "event type not yet registered not in eventTypes array");
|
||||
|
||||
events.addEventType(newEventType);
|
||||
t.eq( events.listeners[newEventType].length, 0, "event type passed to addEventType correctly set up" );
|
||||
t.ok( OpenLayers.Util.indexOf(events.eventTypes, newEventType) != -1, "event type passed to addEventType in eventTypes array");
|
||||
|
||||
var func = function () {};
|
||||
events.register( "doThingA", obj, func );
|
||||
t.eq( events.listeners["doThingA"].length, 1, "listener correctly registered" );
|
||||
|
||||
events.addEventType("doThingsA");
|
||||
t.eq( events.listeners["doThingA"].length, 1, "event type passed to addEventType correctly does nothing if clashes with already defined event type" );
|
||||
}
|
||||
|
||||
/** HACK HACK HACK Deprecated This test should be removed in 3.0 **/
|
||||
function test_Events_globalEventObject(t) {
|
||||
t.plan(1);
|
||||
|
||||
@@ -21,18 +21,13 @@
|
||||
|
||||
|
||||
function test_Layer_Grid_constructor (t) {
|
||||
t.plan( 8 );
|
||||
t.plan( 5 );
|
||||
|
||||
layer = new OpenLayers.Layer.Grid(name, url, params, null);
|
||||
t.ok( layer instanceof OpenLayers.Layer.Grid, "returns OpenLayers.Layer.Grid object" );
|
||||
t.eq( layer.buffer, 0, "buffer default is 0");
|
||||
t.eq( layer.ratio, 1.5, "ratio default is 1.5");
|
||||
t.eq( layer.numLoadingTiles, 0, "numLoadingTiles starts at 0");
|
||||
t.ok( layer.events.listeners["tileloaded"] != null, "'tileloaded' event added to layer's event types");
|
||||
t.ok( OpenLayers.Util.indexOf(layer.events.eventTypes, 'tileloaded') != -1 ,"'tileloaded' event added to layer's event types");
|
||||
|
||||
//regression testing for #1502
|
||||
t.ok( layer.events.listeners['tileloaded'].length == 0, "no listeners for tileloaded preregister");
|
||||
|
||||
var obj = {};
|
||||
var func = function() {};
|
||||
|
||||
@@ -173,7 +173,7 @@
|
||||
var event = {};
|
||||
t.delay_call( 1, function() {
|
||||
t.ok(layer.markers[0].events, "First marker has an events object");
|
||||
t.eq(layer.markers[0].events.listeners['click'].length, 0, "Marker events has one object");
|
||||
t.eq(layer.markers[0].events.listeners['click'], undefined, "Marker events has no object");
|
||||
layer.markers[0].events.triggerEvent('click', event);
|
||||
t.eq(map.popups.length, 0, "no popup on first marker");
|
||||
layer.markers[1].events.triggerEvent('click', event);
|
||||
|
||||
Reference in New Issue
Block a user