events cleanup: fix tabs

git-svn-id: http://svn.openlayers.org/trunk/openlayers@2982 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
euzuro
2007-04-02 23:00:55 +00:00
parent dfa4441646
commit ed0fca9157
+135 -135
View File
@@ -10,144 +10,144 @@
*/ */
OpenLayers.Event = { OpenLayers.Event = {
/** @final @type int */ /** @final @type int */
KEY_BACKSPACE: 8, KEY_BACKSPACE: 8,
/** @final @type int */ /** @final @type int */
KEY_TAB: 9, KEY_TAB: 9,
/** @final @type int */ /** @final @type int */
KEY_RETURN: 13, KEY_RETURN: 13,
/** @final @type int */ /** @final @type int */
KEY_ESC: 27, KEY_ESC: 27,
/** @final @type int */ /** @final @type int */
KEY_LEFT: 37, KEY_LEFT: 37,
/** @final @type int */ /** @final @type int */
KEY_UP: 38, KEY_UP: 38,
/** @final @type int */ /** @final @type int */
KEY_RIGHT: 39, KEY_RIGHT: 39,
/** @final @type int */ /** @final @type int */
KEY_DOWN: 40, KEY_DOWN: 40,
/** @final @type int */ /** @final @type int */
KEY_DELETE: 46, KEY_DELETE: 46,
/** /**
* @param {Event} event * @param {Event} event
* *
* @returns The element that caused the alert * @returns The element that caused the alert
* @type DOMElement * @type DOMElement
*/ */
element: function(event) { element: function(event) {
return event.target || event.srcElement; return event.target || event.srcElement;
}, },
/** /**
* @param {Event} event * @param {Event} event
* *
* @returns Whether or not the event was the result of a left click * @returns Whether or not the event was the result of a left click
* @type boolean * @type boolean
*/ */
isLeftClick: function(event) { isLeftClick: function(event) {
return (((event.which) && (event.which == 1)) || return (((event.which) && (event.which == 1)) ||
((event.button) && (event.button == 1))); ((event.button) && (event.button == 1)));
}, },
/** /**
* @param {Event} event * @param {Event} event
* *
* @returns * @returns
* @type int * @type int
*/ */
pointerX: function(event) { pointerX: function(event) {
return event.pageX || (event.clientX + return event.pageX || (event.clientX +
(document.documentElement.scrollLeft || document.body.scrollLeft)); (document.documentElement.scrollLeft || document.body.scrollLeft));
}, },
/** /**
* @param {Event} event * @param {Event} event
* *
* @returns * @returns
* @type int * @type int
*/ */
pointerY: function(event) { pointerY: function(event) {
return event.pageY || (event.clientY + return event.pageY || (event.clientY +
(document.documentElement.scrollTop || document.body.scrollTop)); (document.documentElement.scrollTop || document.body.scrollTop));
}, },
/** Stops an event from propagating. If the event's 'preventDefault' /** Stops an event from propagating. If the event's 'preventDefault'
* property is set, then we prevent the default browser behaviour * property is set, then we prevent the default browser behaviour
* (such as text selection, radio-button clicking, etc) from occurring * (such as text selection, radio-button clicking, etc) from occurring
* *
* @param {Event} event * @param {Event} event
*/ */
stop: function(event) { stop: function(event) {
if (event.preventDefault) { if (event.preventDefault) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
} else { } else {
event.returnValue = false; event.returnValue = false;
event.cancelBubble = true; event.cancelBubble = true;
} }
}, },
/** /**
* @param {Event} event * @param {Event} event
* @param {String} tagName * @param {String} tagName
* *
* @returns The first node with the given tagName, starting from the node * @returns The first node with the given tagName, starting from the node
* the event was triggered on and traversing the DOM upwards * the event was triggered on and traversing the DOM upwards
* @type DOMElement * @type DOMElement
*/ */
findElement: function(event, tagName) { findElement: function(event, tagName) {
var element = OpenLayers.Event.element(event); var element = OpenLayers.Event.element(event);
while (element.parentNode && (!element.tagName || while (element.parentNode && (!element.tagName ||
(element.tagName.toUpperCase() != tagName.toUpperCase()))) (element.tagName.toUpperCase() != tagName.toUpperCase())))
element = element.parentNode; element = element.parentNode;
return element; return element;
}, },
/** A hashtable cache of the event observers, keyed by element.id /** A hashtable cache of the event observers, keyed by element.id
* *
* @type Object * @type Object
*/ */
observers: false, observers: false,
/** /**
* @param {DOMElement} element * @param {DOMElement} element
* @param {String} name * @param {String} name
* @param {function} observer * @param {function} observer
* @param {Boolean} useCapture * @param {Boolean} useCapture
* *
*/ */
_observeAndCache: function(element, name, observer, useCapture) { _observeAndCache: function(element, name, observer, useCapture) {
if (!this.observers) this.observers = new Object(); if (!this.observers) this.observers = new Object();
//if there is not yet a hash entry for this element, add one //if there is not yet a hash entry for this element, add one
if (!this.observers[element.id]) { if (!this.observers[element.id]) {
this.observers[element.id] = new Array(); this.observers[element.id] = new Array();
} }
//add a new observer to this element's list //add a new observer to this element's list
this.observers[element.id].push({ this.observers[element.id].push({
'element': element, 'element': element,
'name': name, 'name': name,
'observer': observer, 'observer': observer,
'useCapture': useCapture 'useCapture': useCapture
}); });
//add the actual browser event listener //add the actual browser event listener
if (element.addEventListener) { if (element.addEventListener) {
element.addEventListener(name, observer, useCapture); element.addEventListener(name, observer, useCapture);
} else if (element.attachEvent) { } else if (element.attachEvent) {
element.attachEvent('on' + name, observer); element.attachEvent('on' + name, observer);
} }
}, },
/** Given the id of an element to stop observing, cycle through the /** Given the id of an element to stop observing, cycle through the
* element's cached observers, calling stopObserving on each one, * element's cached observers, calling stopObserving on each one,
@@ -188,24 +188,24 @@ OpenLayers.Event = {
OpenLayers.Event.observers = false; OpenLayers.Event.observers = false;
}, },
/** /**
* @param {DOMElement || String} elementParam * @param {DOMElement || String} elementParam
* @param {String} name * @param {String} name
* @param {function} observer * @param {function} observer
* @param {Boolean} useCapture * @param {Boolean} useCapture
* *
*/ */
observe: function(elementParam, name, observer, useCapture) { observe: function(elementParam, name, observer, useCapture) {
var element = OpenLayers.Util.getElement(elementParam); var element = OpenLayers.Util.getElement(elementParam);
useCapture = useCapture || false; useCapture = useCapture || false;
if (name == 'keypress' && if (name == 'keypress' &&
(navigator.appVersion.match(/Konqueror|Safari|KHTML/) (navigator.appVersion.match(/Konqueror|Safari|KHTML/)
|| element.attachEvent)) || element.attachEvent))
name = 'keydown'; name = 'keydown';
this._observeAndCache(element, name, observer, useCapture); this._observeAndCache(element, name, observer, useCapture);
}, },
/** /**
* @param {DOMElement || String} elementParam * @param {DOMElement || String} elementParam