Merge all changes from the naturaldocs sandbox. This brings all the work that
has been done in the NaturalDocs branch back to trunk. Thanks to everyone who helped out in making this happen. (I could list people, but the list would be long, and I'm already mentally on vacation.) git-svn-id: http://svn.openlayers.org/trunk/openlayers@3545 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
+226
-127
@@ -2,74 +2,115 @@
|
||||
* See http://svn.openlayers.org/trunk/openlayers/repository-license.txt
|
||||
* for the full text of the license. */
|
||||
|
||||
|
||||
/**
|
||||
* @requires OpenLayers/Util.js
|
||||
*
|
||||
* @class (Not really a class, but kind of)
|
||||
*
|
||||
*
|
||||
* Title: OpenLayers.Events
|
||||
*
|
||||
* Class: OpenLayers.Event
|
||||
* Utility functions for event handling.
|
||||
*/
|
||||
OpenLayers.Event = {
|
||||
|
||||
/** A hashtable cache of the event observers.
|
||||
* Keyed by element._eventCacheID
|
||||
*
|
||||
* @type Object
|
||||
*/
|
||||
observers: false,
|
||||
/**
|
||||
* Property: observers
|
||||
* {Object} A hashtable cache of the event observers. Keyed by
|
||||
* element._eventCacheID
|
||||
*/
|
||||
observers: false,
|
||||
|
||||
/** @final @type int */
|
||||
KEY_BACKSPACE: 8,
|
||||
/**
|
||||
* Constant: KEY_BACKSPACE
|
||||
* {int}
|
||||
*/
|
||||
KEY_BACKSPACE: 8,
|
||||
|
||||
/** @final @type int */
|
||||
KEY_TAB: 9,
|
||||
/**
|
||||
* Constant: KEY_TAB
|
||||
* {int}
|
||||
*/
|
||||
KEY_TAB: 9,
|
||||
|
||||
/** @final @type int */
|
||||
KEY_RETURN: 13,
|
||||
/**
|
||||
* Constant: KEY_RETURN
|
||||
* {int}
|
||||
*/
|
||||
KEY_RETURN: 13,
|
||||
|
||||
/** @final @type int */
|
||||
KEY_ESC: 27,
|
||||
/**
|
||||
* Constant: KEY_ESC
|
||||
* {int}
|
||||
*/
|
||||
KEY_ESC: 27,
|
||||
|
||||
/** @final @type int */
|
||||
KEY_LEFT: 37,
|
||||
/**
|
||||
* Constant: KEY_LEFT
|
||||
* {int}
|
||||
*/
|
||||
KEY_LEFT: 37,
|
||||
|
||||
/** @final @type int */
|
||||
KEY_UP: 38,
|
||||
/**
|
||||
* Constant: KEY_UP
|
||||
* {int}
|
||||
*/
|
||||
KEY_UP: 38,
|
||||
|
||||
/** @final @type int */
|
||||
KEY_RIGHT: 39,
|
||||
/**
|
||||
* Constant: KEY_RIGHT
|
||||
* {int}
|
||||
*/
|
||||
KEY_RIGHT: 39,
|
||||
|
||||
/** @final @type int */
|
||||
KEY_DOWN: 40,
|
||||
/**
|
||||
* Constant: KEY_DOWN
|
||||
* {int}
|
||||
*/
|
||||
KEY_DOWN: 40,
|
||||
|
||||
/** @final @type int */
|
||||
KEY_DELETE: 46,
|
||||
/**
|
||||
* Constant: KEY_DELETE
|
||||
* {int}
|
||||
*/
|
||||
KEY_DELETE: 46,
|
||||
|
||||
|
||||
/**
|
||||
* @param {Event} event
|
||||
* Method: element
|
||||
* Cross browser event element detection.
|
||||
*
|
||||
* @returns The element that caused the alert
|
||||
* @type DOMElement
|
||||
* Parameters:
|
||||
* event - {Event}
|
||||
*
|
||||
* Returns:
|
||||
* {DOMElement} The element that caused the event
|
||||
*/
|
||||
element: function(event) {
|
||||
return event.target || event.srcElement;
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Event} event
|
||||
* Method: isLeftClick
|
||||
* Determine whether event was caused by a left click.
|
||||
*
|
||||
* Parameters:
|
||||
* event - {Event}
|
||||
*
|
||||
* @returns Whether or not the event was the result of a left click
|
||||
* @type boolean
|
||||
* Returns:
|
||||
* {Boolean}
|
||||
*/
|
||||
isLeftClick: function(event) {
|
||||
return (((event.which) && (event.which == 1)) ||
|
||||
((event.button) && (event.button == 1)));
|
||||
},
|
||||
|
||||
/** Stops an event from propagating.
|
||||
*
|
||||
* @param {Event} event
|
||||
* @param {Boolean} allowDefault If true, we stop the event chain but
|
||||
/**
|
||||
* Method: stop
|
||||
* Stops an event from propagating.
|
||||
*
|
||||
* Parameters:
|
||||
* event - {Event}
|
||||
* allowDefault - {Boolean} If true, we stop the event chain but
|
||||
* still allow the default browser
|
||||
* behaviour (text selection, radio-button
|
||||
* clicking, etc)
|
||||
@@ -93,12 +134,15 @@ OpenLayers.Event = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {Event} event
|
||||
* @param {String} tagName
|
||||
* Method: findElement
|
||||
*
|
||||
* @returns The first node with the given tagName, starting from the node
|
||||
* the event was triggered on and traversing the DOM upwards
|
||||
* @type DOMElement
|
||||
* Parameters:
|
||||
* event - {Event}
|
||||
* tagName - {String}
|
||||
*
|
||||
* Return:
|
||||
* {DOMElement} The first node with the given tagName, starting from the
|
||||
* node the event was triggered on and traversing the DOM upwards
|
||||
*/
|
||||
findElement: function(event, tagName) {
|
||||
var element = OpenLayers.Event.element(event);
|
||||
@@ -109,11 +153,13 @@ OpenLayers.Event = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {DOMElement || String} elementParam
|
||||
* @param {String} name
|
||||
* @param {function} observer
|
||||
* @param {Boolean} useCapture
|
||||
* Method: observe
|
||||
*
|
||||
* Parameters:
|
||||
* elementParam - {DOMElement || String}
|
||||
* name - {String}
|
||||
* observer - {function}
|
||||
* useCapture - {Boolean}
|
||||
*/
|
||||
observe: function(elementParam, name, observer, useCapture) {
|
||||
var element = OpenLayers.Util.getElement(elementParam);
|
||||
@@ -162,11 +208,14 @@ OpenLayers.Event = {
|
||||
}
|
||||
},
|
||||
|
||||
/** Given the id of an element to stop observing, cycle through the
|
||||
/**
|
||||
* Method: stopObservingElement
|
||||
* Given the id of an element to stop observing, cycle through the
|
||||
* element's cached observers, calling stopObserving on each one,
|
||||
* skipping those entries which can no longer be removed.
|
||||
*
|
||||
* @param {DOMElement || String} elementParam
|
||||
* parameters:
|
||||
* elementParam - {DOMElement || String}
|
||||
*/
|
||||
stopObservingElement: function(elementParam) {
|
||||
var element = OpenLayers.Util.getElement(elementParam);
|
||||
@@ -176,9 +225,11 @@ OpenLayers.Event = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
*
|
||||
* @param {Array(Object)} elementObservers Array of (element, name,
|
||||
* Method: _removeElementObservers
|
||||
* *Private*.
|
||||
*
|
||||
* Parameters:
|
||||
* elementObservers - {Array(Object)} Array of (element, name,
|
||||
* observer, usecapture) objects,
|
||||
* taken directly from hashtable
|
||||
*/
|
||||
@@ -196,13 +247,16 @@ OpenLayers.Event = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {DOMElement || String} elementParam
|
||||
* @param {String} name
|
||||
* @param {function} observer
|
||||
* @param {Boolean} useCapture
|
||||
* Method: stopObserving
|
||||
*
|
||||
* @returns Whether or not the event observer was removed
|
||||
* @type Boolean
|
||||
* Parameters:
|
||||
* elementParam - {DOMElement || String}
|
||||
* name - {String}
|
||||
* observer - {function}
|
||||
* useCapture - {Boolean}
|
||||
*
|
||||
* Return:
|
||||
* {Boolean} Whether or not the event observer was removed
|
||||
*/
|
||||
stopObserving: function(elementParam, name, observer, useCapture) {
|
||||
useCapture = useCapture || false;
|
||||
@@ -251,7 +305,9 @@ OpenLayers.Event = {
|
||||
return foundEntry;
|
||||
},
|
||||
|
||||
/** Cycle through all the element entries in the events cache and call
|
||||
/**
|
||||
* Method: unloadCache
|
||||
* Cycle through all the element entries in the events cache and call
|
||||
* stopObservingElement on each.
|
||||
*/
|
||||
unloadCache: function() {
|
||||
@@ -279,12 +335,15 @@ if (window.Event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @class
|
||||
* Class: OpenLayers.Events
|
||||
*/
|
||||
OpenLayers.Events = OpenLayers.Class.create();
|
||||
OpenLayers.Events.prototype = {
|
||||
|
||||
/** @final @type Array: supported events */
|
||||
/**
|
||||
* Constant: BROWSER_EVENTS
|
||||
* {Array} supported events
|
||||
*/
|
||||
BROWSER_EVENTS: [
|
||||
"mouseover", "mouseout",
|
||||
"mousedown", "mouseup", "mousemove",
|
||||
@@ -292,37 +351,52 @@ OpenLayers.Events.prototype = {
|
||||
"resize", "focus", "blur"
|
||||
],
|
||||
|
||||
/** Hashtable of Array(Function): events listener functions
|
||||
* @type Object */
|
||||
listeners: null,
|
||||
/**
|
||||
* Property: listeners
|
||||
* {Object} Hashtable of Array(Function): events listener functions
|
||||
*/
|
||||
listeners: null,
|
||||
|
||||
/** @type Object: the code object issuing application events */
|
||||
object: null,
|
||||
/**
|
||||
* Property: object
|
||||
* {Object} the code object issuing application events
|
||||
*/
|
||||
object: null,
|
||||
|
||||
/** @type DOMElement: the DOM element receiving browser events */
|
||||
element: null,
|
||||
/**
|
||||
* Property: element
|
||||
* {DOMElement} the DOM element receiving browser events
|
||||
*/
|
||||
element: null,
|
||||
|
||||
/** @type Array: list of support application events */
|
||||
eventTypes: null,
|
||||
/**
|
||||
* Property: eventTypes
|
||||
* {Array} list of support application events
|
||||
*/
|
||||
eventTypes: null,
|
||||
|
||||
/**
|
||||
* Property: eventHandler
|
||||
* {Function} bound event handler attached to elements
|
||||
*/
|
||||
eventHandler: null,
|
||||
|
||||
/**
|
||||
* Property: fallThrough
|
||||
* {Boolean}
|
||||
*/
|
||||
fallThrough: null,
|
||||
|
||||
/**
|
||||
* @type Function: bound event handler attached to elements
|
||||
* @private
|
||||
*/
|
||||
eventHandler: null,
|
||||
|
||||
/** @type Boolean */
|
||||
fallThrough: null,
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @param {OpenLayers.Map} object The js object to which this Events object
|
||||
* is being added
|
||||
* @param {DOMElement} element A dom element to respond to browser events
|
||||
* @param {Array} eventTypes Array of custom application events
|
||||
* @param {Boolean} fallThrough Allow events to fall through after these
|
||||
* have been handled?
|
||||
* Constructor: OpenLayers.Events
|
||||
* Construct an OpenLayers.Events object.
|
||||
*
|
||||
* 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} Array of custom application events
|
||||
* fallThrough - {Boolean} Allow events to fall through after these have
|
||||
* been handled?
|
||||
*/
|
||||
initialize: function (object, element, eventTypes, fallThrough) {
|
||||
this.object = object;
|
||||
@@ -351,7 +425,7 @@ OpenLayers.Events.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* Method: destroy
|
||||
*/
|
||||
destroy: function () {
|
||||
if (this.element) {
|
||||
@@ -367,7 +441,10 @@ OpenLayers.Events.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {HTMLDOMElement} element a DOM element to attach browser events to
|
||||
* Method: attachToElement
|
||||
*
|
||||
* Parameters:
|
||||
* element - {HTMLDOMElement} a DOM element to attach browser events to
|
||||
*/
|
||||
attachToElement: function (element) {
|
||||
for (var i = 0; i < this.BROWSER_EVENTS.length; i++) {
|
||||
@@ -387,26 +464,30 @@ OpenLayers.Events.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {String} type Name of the event to register
|
||||
* @param {Object} obj The object to bind the context to for the callback#.
|
||||
* If no object is specified, default is the Events's
|
||||
* 'object' property.
|
||||
* @param {Function} func The callback function. If no callback is
|
||||
* specified, this function does nothing.
|
||||
*
|
||||
* #When the event is triggered, the 'func' function will be called, in the
|
||||
* context of 'obj'. Imagine we were to register an event, specifying an
|
||||
* OpenLayers.Bounds Object as 'obj'. When the event is triggered, the
|
||||
* context in the callback function will be our Bounds object. This means
|
||||
* that within our callback function, we can access the properties and
|
||||
* methods of the Bounds object through the "this" variable. So our
|
||||
* callback could execute something like:
|
||||
*
|
||||
* leftStr = "Left: " + this.left;
|
||||
* Method: register
|
||||
* Register an event on the events object.
|
||||
*
|
||||
* When the event is triggered, the 'func' function will be called, in the
|
||||
* context of 'obj'. Imagine we were to register an event, specifying an
|
||||
* OpenLayers.Bounds Object as 'obj'. When the event is triggered, the
|
||||
* context in the callback function will be our Bounds object. This means
|
||||
* that within our callback function, we can access the properties and
|
||||
* methods of the Bounds object through the "this" variable. So our
|
||||
* callback could execute something like:
|
||||
* : leftStr = "Left: " + this.left;
|
||||
*
|
||||
* or
|
||||
*
|
||||
* centerStr = "Center: " + this.getCenterLonLat();
|
||||
* : centerStr = "Center: " + this.getCenterLonLat();
|
||||
*
|
||||
* Parameters:
|
||||
* type - {String} Name of the event to register
|
||||
* obj - {Object} The object to bind the context to for the callback#.
|
||||
* If no object is specified, default is the Events's
|
||||
* 'object' property.
|
||||
* func - {Function} The callback function. If no callback is
|
||||
* specified, this function does nothing.
|
||||
*
|
||||
*
|
||||
*/
|
||||
register: function (type, obj, func) {
|
||||
@@ -425,12 +506,15 @@ OpenLayers.Events.prototype = {
|
||||
/**
|
||||
* TODO: get rid of this in 3.0 - Decide whether listeners should be
|
||||
* called in the order they were registered or in reverse order.
|
||||
*
|
||||
* @param {String} type Name of the event to register
|
||||
* @param {Object} obj The object to bind the context to for the callback#.
|
||||
*
|
||||
* Method: registerPriority
|
||||
*
|
||||
* Parameters:
|
||||
* type - {String} Name of the event to register
|
||||
* obj - {Object} The object to bind the context to for the callback#.
|
||||
* If no object is specified, default is the Events's
|
||||
* 'object' property.
|
||||
* @param {Function} func The callback function. If no callback is
|
||||
* func - {Function} The callback function. If no callback is
|
||||
* specified, this function does nothing.
|
||||
*/
|
||||
registerPriority: function (type, obj, func) {
|
||||
@@ -447,9 +531,12 @@ OpenLayers.Events.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {String} type
|
||||
* @param {Object} obj If none specified, defaults to this.object
|
||||
* @param {Function} func
|
||||
* Method: unregister
|
||||
*
|
||||
* Parameters:
|
||||
* type - {String}
|
||||
* obj - {Object} If none specified, defaults to this.object
|
||||
* func - {Function}
|
||||
*/
|
||||
unregister: function (type, obj, func) {
|
||||
if (obj == null) {
|
||||
@@ -466,10 +553,13 @@ OpenLayers.Events.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
/** Remove all listeners for a given event type. If type is not registered,
|
||||
/**
|
||||
* Method: remove
|
||||
* Remove all listeners for a given event type. If type is not registered,
|
||||
* does nothing.
|
||||
*
|
||||
* @param {String} type
|
||||
*
|
||||
* Parameters:
|
||||
* type - {String}
|
||||
*/
|
||||
remove: function(type) {
|
||||
if (this.listeners[type] != null) {
|
||||
@@ -477,10 +567,13 @@ OpenLayers.Events.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
/** Trigger a specified registered event
|
||||
/**
|
||||
* Method: triggerEvent
|
||||
* Trigger a specified registered event
|
||||
*
|
||||
* @param {String} type
|
||||
* @param {Event} evt
|
||||
* Parameters:
|
||||
* type - {String}
|
||||
* evt - {Event}
|
||||
*/
|
||||
triggerEvent: function (type, evt) {
|
||||
|
||||
@@ -519,13 +612,16 @@ OpenLayers.Events.prototype = {
|
||||
}
|
||||
},
|
||||
|
||||
/** Basically just a wrapper to the triggerEvent() function, but takes
|
||||
/**
|
||||
* Method: handleBrowserEvent
|
||||
* Basically just a wrapper to the triggerEvent() function, but takes
|
||||
* care to set a property 'xy' on the event with the current mouse
|
||||
* position.
|
||||
*
|
||||
* @private
|
||||
*
|
||||
* @param {Event} evt
|
||||
*
|
||||
* Private function.
|
||||
*
|
||||
* Parameters:
|
||||
* evt - {Event}
|
||||
*/
|
||||
handleBrowserEvent: function (evt) {
|
||||
evt.xy = this.getMousePosition(evt);
|
||||
@@ -533,12 +629,15 @@ OpenLayers.Events.prototype = {
|
||||
},
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Method: getMousePosition
|
||||
* *Private*
|
||||
*
|
||||
* @param {Event} evt
|
||||
* Parameters:
|
||||
* evt - {Event}
|
||||
*
|
||||
* @returns The current xy coordinate of the mouse, adjusted for offsets
|
||||
* @type OpenLayers.Pixel
|
||||
* Returns
|
||||
* {<OpenLayers.Pixel>} The current xy coordinate of the mouse, adjusted
|
||||
* for offsets
|
||||
*/
|
||||
getMousePosition: function (evt) {
|
||||
if (!this.element.offsets) {
|
||||
|
||||
Reference in New Issue
Block a user