Made Events class more generic; the Events constructor now takes a list of supported application event types. Added tests for the Events class.
git-svn-id: http://svn.openlayers.org/trunk/openlayers@61 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
@@ -1,41 +1,46 @@
|
||||
OpenLayers.Events = Class.create();
|
||||
|
||||
OpenLayers.Events.prototype = {
|
||||
// hash of Array(Function)
|
||||
listeners: null,
|
||||
|
||||
// OpenLayers.Map
|
||||
map: null,
|
||||
|
||||
// DOMElement
|
||||
div: null,
|
||||
|
||||
// supported events
|
||||
// Array: supported events
|
||||
BROWSER_EVENTS: [
|
||||
"mouseover", "mouseout",
|
||||
"mousedown", "mouseup", "mousemove",
|
||||
"click", "dblclick"
|
||||
],
|
||||
MAP_EVENTS: [
|
||||
"mouseover", "mouseout",
|
||||
"mousedown", "mouseup", "mousemove",
|
||||
"click", "dblclick"
|
||||
],
|
||||
|
||||
// hash of Array(Function): events listener functions
|
||||
listeners: null,
|
||||
|
||||
// Object: the code object issuing application events
|
||||
object: null,
|
||||
|
||||
// DOMElement: the DOM element receiving browser events
|
||||
div: null,
|
||||
|
||||
// Array: list of support application events
|
||||
eventTypes: null,
|
||||
|
||||
/**
|
||||
* @param {OpenLayers.Map} map
|
||||
* @param {DOMElement} div
|
||||
*/
|
||||
initialize: function (map, div) {
|
||||
this.listeners = {};
|
||||
this.map = map;
|
||||
this.div = div;
|
||||
for (var i = 0; i < this.MAP_EVENTS.length; i++) {
|
||||
this.listeners[ this.MAP_EVENTS[i] ] = [];
|
||||
initialize: function (object, div, eventTypes) {
|
||||
this.listeners = {};
|
||||
this.object = object;
|
||||
this.div = div;
|
||||
this.eventTypes = eventTypes;
|
||||
for (var i = 0; i < this.eventTypes.length; i++) {
|
||||
// create a listener list for every custom application event
|
||||
this.listeners[ this.eventTypes[i] ] = [];
|
||||
}
|
||||
for (var i = 0; i < this.BROWSER_EVENTS.length; i++) {
|
||||
var eventName = this.BROWSER_EVENTS[i];
|
||||
Event.observe(div, eventName,
|
||||
var eventType = this.BROWSER_EVENTS[i];
|
||||
|
||||
// every browser event has a corresponding application event
|
||||
// (whether it's listened for or not).
|
||||
this.listeners[ eventType ] = [];
|
||||
|
||||
Event.observe(div, eventType,
|
||||
this.handleBrowserEvent.bindAsEventListener(this));
|
||||
}
|
||||
},
|
||||
@@ -55,7 +60,7 @@ OpenLayers.Events.prototype = {
|
||||
*/
|
||||
handleBrowserEvent: function (evt) {
|
||||
evt.xy = this.getMousePosition(evt);
|
||||
this.triggerMapEvent(evt.type, evt)
|
||||
this.triggerEvent(evt.type, evt)
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -74,8 +79,11 @@ OpenLayers.Events.prototype = {
|
||||
* @param {str} type
|
||||
* @param {event} evt
|
||||
*/
|
||||
triggerMapEvent: function (type, evt) {
|
||||
evt.map = this.map;
|
||||
triggerEvent: function (type, evt) {
|
||||
if (evt == null) {
|
||||
evt = {};
|
||||
}
|
||||
evt.object = this.object;
|
||||
|
||||
var listeners = this.listeners[type];
|
||||
for (var i = 0; i < listeners.length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user