From 5544bbf134a32f549d45eea3ad2bb41db66d5c26 Mon Sep 17 00:00:00 2001 From: euzuro Date: Tue, 4 Jul 2006 11:25:54 +0000 Subject: [PATCH] adding commenting/readability to initialize() git-svn-id: http://svn.openlayers.org/trunk/openlayers@864 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Events.js | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/lib/OpenLayers/Events.js b/lib/OpenLayers/Events.js index d387d3c72b..040ccc870e 100644 --- a/lib/OpenLayers/Events.js +++ b/lib/OpenLayers/Events.js @@ -28,6 +28,7 @@ OpenLayers.Events.prototype = { /** @type Array: list of support application events */ eventTypes: null, + /** * @constructor * @@ -37,31 +38,41 @@ OpenLayers.Events.prototype = { * @param {Array} eventTypes Array of custom application events */ initialize: function (object, div, eventTypes) { - this.listeners = {}; this.object = object; this.div = div; this.eventTypes = eventTypes; - if (eventTypes) { + this.listeners = new Object(); + + // if eventTypes is specified, create a listeners list for each + // custom application event. + if (eventTypes != null) { + for (var i = 0; i < this.eventTypes.length; i++) { - // create a listener list for every custom application event - this.listeners[ this.eventTypes[i] ] = []; + this.listeners[ this.eventTypes[i] ] = new Array(); } } - for (var i = 0; i < this.BROWSER_EVENTS.length; i++) { - var eventType = this.BROWSER_EVENTS[i]; - // every browser event has a corresponding application event - // (whether it's listened for or not). - this.listeners[ eventType ] = []; + // if a dom element is specified, add a listeners list + // for browser events on the element and register them + if (div != null) { - Event.observe(div, eventType, - this.handleBrowserEvent.bindAsEventListener(this)); + for (var i = 0; i < this.BROWSER_EVENTS.length; i++) { + var eventType = this.BROWSER_EVENTS[i]; + + // every browser event has a corresponding application event + // (whether it's listened for or not). + this.listeners[ eventType ] = new Array(); + + // use Prototype to register the event cross-browser + Event.observe(div, eventType, + this.handleBrowserEvent.bindAsEventListener(this)); + } + + // disable dragstart in IE so that mousedown/move/up works normally + Event.observe(div, "dragstart", Event.stop); } - - // disable dragstart in IE so that mousedown/move/up works normally - Event.observe(div, "dragstart", Event.stop); }, /**