2 Copyright (c) 2008, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.net/yui/license.txt
9 * The CustomEvent class lets you define events for your application
10 * that can be subscribed to by one or more independent component.
12 * @param {String} type The type of event, which is passed to the callback
13 * when the event fires
14 * @param {Object} oScope The context the event will fire from. "this" will
15 * refer to this object in the callback. Default value:
16 * the window object. The listener can override this.
17 * @param {boolean} silent pass true to prevent the event from writing to
19 * @param {int} signature the signature that the custom event subscriber
20 * will receive. YAHOO.util.CustomEvent.LIST or
21 * YAHOO.util.CustomEvent.FLAT. The default is
22 * YAHOO.util.CustomEvent.LIST.
23 * @namespace YAHOO.util
27 YAHOO.util.CustomEvent = function(type, oScope, silent, signature) {
30 * The type of event, returned to subscribers when the event fires
37 * The scope the the event will fire from by default. Defaults to the window
42 this.scope = oScope || window;
45 * By default all custom events are logged in the debug build, set silent
46 * to true to disable debug outpu for this event.
53 * Custom events support two styles of arguments provided to the event
56 * <li>YAHOO.util.CustomEvent.LIST:
58 * <li>param1: event name</li>
59 * <li>param2: array of arguments sent to fire</li>
60 * <li>param3: <optional> a custom object supplied by the subscriber</li>
63 * <li>YAHOO.util.CustomEvent.FLAT
65 * <li>param1: the first argument passed to fire. If you need to
66 * pass multiple parameters, use and array or object literal</li>
67 * <li>param2: <optional> a custom object supplied by the subscriber</li>
74 this.signature = signature || YAHOO.util.CustomEvent.LIST;
77 * The subscribers to this event
78 * @property subscribers
81 this.subscribers = [];
84 YAHOO.log( "Creating " + this, "info", "Event" );
87 var onsubscribeType = "_YUICEOnSubscribe";
89 // Only add subscribe events for events that are not generated by
91 if (type !== onsubscribeType) {
94 * Custom events provide a custom event that fires whenever there is
95 * a new subscriber to the event. This provides an opportunity to
96 * handle the case where there is a non-repeating event that has
97 * already fired has a new subscriber.
99 * @event subscribeEvent
100 * @type YAHOO.util.CustomEvent
101 * @param {Function} fn The function to execute
102 * @param {Object} obj An object to be passed along when the event
104 * @param {boolean|Object} override If true, the obj passed in becomes
105 * the execution scope of the listener.
106 * if an object, that object becomes the
107 * the execution scope.
109 this.subscribeEvent =
110 new YAHOO.util.CustomEvent(onsubscribeType, this, true);
116 * In order to make it possible to execute the rest of the subscriber
117 * stack when one thows an exception, the subscribers exceptions are
118 * caught. The most recent exception is stored in this property
119 * @property lastError
122 this.lastError = null;
126 * Subscriber listener sigature constant. The LIST type returns three
127 * parameters: the event type, the array of args passed to fire, and
128 * the optional custom object
129 * @property YAHOO.util.CustomEvent.LIST
133 YAHOO.util.CustomEvent.LIST = 0;
136 * Subscriber listener sigature constant. The FLAT type returns two
137 * parameters: the first argument passed to fire and the optional
139 * @property YAHOO.util.CustomEvent.FLAT
143 YAHOO.util.CustomEvent.FLAT = 1;
145 YAHOO.util.CustomEvent.prototype = {
148 * Subscribes the caller to this event
150 * @param {Function} fn The function to execute
151 * @param {Object} obj An object to be passed along when the event
153 * @param {boolean|Object} override If true, the obj passed in becomes
154 * the execution scope of the listener.
155 * if an object, that object becomes the
156 * the execution scope.
158 subscribe: function(fn, obj, override) {
161 throw new Error("Invalid callback for subscriber to '" + this.type + "'");
164 if (this.subscribeEvent) {
165 this.subscribeEvent.fire(fn, obj, override);
168 this.subscribers.push( new YAHOO.util.Subscriber(fn, obj, override) );
172 * Unsubscribes subscribers.
173 * @method unsubscribe
174 * @param {Function} fn The subscribed function to remove, if not supplied
175 * all will be removed
176 * @param {Object} obj The custom object passed to subscribe. This is
177 * optional, but if supplied will be used to
178 * disambiguate multiple listeners that are the same
179 * (e.g., you subscribe many object using a function
180 * that lives on the prototype)
181 * @return {boolean} True if the subscriber was found and detached.
183 unsubscribe: function(fn, obj) {
186 return this.unsubscribeAll();
190 for (var i=0, len=this.subscribers.length; i<len; ++i) {
191 var s = this.subscribers[i];
192 if (s && s.contains(fn, obj)) {
202 * Notifies the subscribers. The callback functions will be executed
203 * from the scope specified when the event was created, and with the
204 * following parameters:
206 * <li>The type of event</li>
207 * <li>All of the arguments fire() was executed with as an array</li>
208 * <li>The custom object (if any) that was passed into the subscribe()
212 * @param {Object*} arguments an arbitrary set of parameters to pass to
214 * @return {boolean} false if one of the subscribers returned false,
219 this.lastError = null;
222 len=this.subscribers.length;
224 if (!len && this.silent) {
225 //YAHOO.log('DEBUG no subscribers');
229 var args=[].slice.call(arguments, 0), ret=true, i, rebuild=false;
232 YAHOO.log( "Firing " + this + ", " +
233 "args: " + args + ", " +
234 "subscribers: " + len,
238 // make a copy of the subscribers so that there are
239 // no index problems if one subscriber removes another.
240 var subs = this.subscribers.slice(), throwErrors = YAHOO.util.Event.throwErrors;
242 for (i=0; i<len; ++i) {
245 //YAHOO.log('DEBUG rebuilding array');
249 YAHOO.log( this.type + "->" + (i+1) + ": " + s, "info", "Event" );
252 var scope = s.getScope(this.scope);
254 if (this.signature == YAHOO.util.CustomEvent.FLAT) {
256 if (args.length > 0) {
261 ret = s.fn.call(scope, param, s.obj);
265 YAHOO.log(this + " subscriber exception: " + e, "error", "Event");
272 ret = s.fn.call(scope, this.type, args, s.obj);
275 YAHOO.log(this + " subscriber exception: " + ex, "error", "Event");
284 YAHOO.log("Event stopped, sub " + i + " of " + len, "info", "Event");
293 return (ret !== false);
297 * Removes all listeners
298 * @method unsubscribeAll
299 * @return {int} The number of listeners unsubscribed
301 unsubscribeAll: function() {
302 for (var i=this.subscribers.length-1; i>-1; i--) {
315 _delete: function(index) {
316 var s = this.subscribers[index];
322 // this.subscribers[index]=null;
323 this.subscribers.splice(index, 1);
329 toString: function() {
330 return "CustomEvent: " + "'" + this.type + "', " +
331 "scope: " + this.scope;
336 /////////////////////////////////////////////////////////////////////
339 * Stores the subscriber information to be used when the event fires.
340 * @param {Function} fn The function to execute
341 * @param {Object} obj An object to be passed along when the event fires
342 * @param {boolean} override If true, the obj passed in becomes the execution
343 * scope of the listener
347 YAHOO.util.Subscriber = function(fn, obj, override) {
350 * The callback that will be execute when the event fires
357 * An optional custom object that will passed to the callback when
362 this.obj = YAHOO.lang.isUndefined(obj) ? null : obj;
365 * The default execution scope for the event listener is defined when the
366 * event is created (usually the object which contains the event).
367 * By setting override to true, the execution scope becomes the custom
368 * object passed in by the subscriber. If override is an object, that
369 * object becomes the scope.
371 * @type boolean|object
373 this.override = override;
378 * Returns the execution scope for this listener. If override was set to true
379 * the custom obj will be the scope. If override is an object, that is the
380 * scope, otherwise the default scope will be used.
382 * @param {Object} defaultScope the scope to use if this listener does not
385 YAHOO.util.Subscriber.prototype.getScope = function(defaultScope) {
387 if (this.override === true) {
390 return this.override;
397 * Returns true if the fn and obj match this objects properties.
398 * Used by the unsubscribe method to match the right subscriber.
401 * @param {Function} fn the function to execute
402 * @param {Object} obj an object to be passed along when the event fires
403 * @return {boolean} true if the supplied arguments match this
404 * subscriber's signature.
406 YAHOO.util.Subscriber.prototype.contains = function(fn, obj) {
408 return (this.fn == fn && this.obj == obj);
410 return (this.fn == fn);
417 YAHOO.util.Subscriber.prototype.toString = function() {
418 return "Subscriber { obj: " + this.obj +
419 ", override: " + (this.override || "no") + " }";
423 * The Event Utility provides utilities for managing DOM Events and tools
424 * for building event systems
427 * @title Event Utility
428 * @namespace YAHOO.util
432 // The first instance of Event will win if it is loaded more than once.
433 // @TODO this needs to be changed so that only the state data that needs to
434 // be preserved is kept, while methods are overwritten/added as needed.
435 // This means that the module pattern can't be used.
436 if (!YAHOO.util.Event) {
439 * The event utility provides functions to add and remove event listeners,
440 * event cleansing. It also tries to automatically remove listeners it
441 * registers during the unload event.
446 YAHOO.util.Event = function() {
449 * True after the onload event has fired
450 * @property loadComplete
455 var loadComplete = false;
458 * Cache of wrapped listeners
459 * @property listeners
467 * User-defined unload function that will be fired before all events
469 * @property unloadListeners
474 var unloadListeners = [];
477 * Cache of DOM0 event handlers to work around issues with DOM2 events
479 * @property legacyEvents
483 var legacyEvents = [];
486 * Listener stack for DOM0 events
487 * @property legacyHandlers
491 var legacyHandlers = [];
494 * The number of times to poll after window.onload. This number is
495 * increased if additional late-bound handlers are requested after
497 * @property retryCount
504 * onAvailable listeners
505 * @property onAvailStack
509 var onAvailStack = [];
512 * Lookup table for legacy events
513 * @property legacyMap
520 * Counter for auto id generation
528 * Normalized keycodes for webkit/safari
529 * @property webkitKeymap
540 63276: 33, // page up
541 63277: 34, // page down
542 25: 9 // SHIFT-TAB (Safari provides a different key code in
543 // this case, even though the shiftKey modifier is set)
549 * The number of times we should look for elements that are not
550 * in the DOM at the time the event is requested after the document
551 * has been loaded. The default is 2000@amp;20 ms, so it will poll
552 * for 40 seconds or until all outstanding handlers are bound
553 * (whichever comes first).
554 * @property POLL_RETRYS
562 * The poll interval in milliseconds
563 * @property POLL_INTERVAL
571 * Element to bind, int constant
580 * Type of event, int constant
589 * Function to execute, int constant
598 * Function wrapped for scope correction and cleanup, int constant
607 * Object passed in by the user that will be returned as a
608 * parameter to the callback, int constant. Specific to
618 * Adjusted scope, either the element we are registering the event
619 * on or the custom object passed in by the listener, int constant
620 * @property ADJ_SCOPE
628 * The original obj passed into addListener
637 * The original scope parameter passed into addListener
646 * addListener/removeListener can throw errors in unexpected scenarios.
647 * These errors are suppressed, the method returns false, and this property
649 * @property lastError
660 * @deprecated use YAHOO.env.ua.webkit
662 isSafari: YAHOO.env.ua.webkit,
670 * @deprecated use YAHOO.env.ua.webkit
672 webkit: YAHOO.env.ua.webkit,
679 * @deprecated use YAHOO.env.ua.ie
681 isIE: YAHOO.env.ua.ie,
685 * @property _interval
692 * document readystate poll handle
700 * True when the document is initially usable
708 * Errors thrown by subscribers of custom events are caught
709 * and the error message is written to the debug console. If
710 * this property is set to true, it will also re-throw the
712 * @property throwErrors
719 * @method startInterval
723 startInterval: function() {
724 if (!this._interval) {
726 var callback = function() { self._tryPreloadAttach(); };
727 this._interval = setInterval(callback, this.POLL_INTERVAL);
732 * Executes the supplied callback when the item with the supplied
733 * id is found. This is meant to be used to execute behavior as
734 * soon as possible as the page loads. If you use this after the
735 * initial page load it will poll for a fixed time for the element.
736 * The number of times it will poll and the frequency are
737 * configurable. By default it will poll for 10 seconds.
739 * <p>The callback is executed with a single parameter:
740 * the custom object parameter, if provided.</p>
742 * @method onAvailable
744 * @param {string||string[]} p_id the id of the element, or an array
745 * of ids to look for.
746 * @param {function} p_fn what to execute when the element is found.
747 * @param {object} p_obj an optional object to be passed back as
748 * a parameter to p_fn.
749 * @param {boolean|object} p_override If set to true, p_fn will execute
750 * in the scope of p_obj, if set to an object it
751 * will execute in the scope of that object
752 * @param checkContent {boolean} check child node readiness (onContentReady)
755 onAvailable: function(p_id, p_fn, p_obj, p_override, checkContent) {
757 var a = (YAHOO.lang.isString(p_id)) ? [p_id] : p_id;
759 for (var i=0; i<a.length; i=i+1) {
760 onAvailStack.push({id: a[i],
763 override: p_override,
764 checkReady: checkContent });
767 retryCount = this.POLL_RETRYS;
769 this.startInterval();
773 * Works the same way as onAvailable, but additionally checks the
774 * state of sibling elements to determine if the content of the
775 * available element is safe to modify.
777 * <p>The callback is executed with a single parameter:
778 * the custom object parameter, if provided.</p>
780 * @method onContentReady
782 * @param {string} p_id the id of the element to look for.
783 * @param {function} p_fn what to execute when the element is ready.
784 * @param {object} p_obj an optional object to be passed back as
785 * a parameter to p_fn.
786 * @param {boolean|object} p_override If set to true, p_fn will execute
787 * in the scope of p_obj. If an object, p_fn will
788 * exectute in the scope of that object
792 onContentReady: function(p_id, p_fn, p_obj, p_override) {
793 this.onAvailable(p_id, p_fn, p_obj, p_override, true);
797 * Executes the supplied callback when the DOM is first usable. This
798 * will execute immediately if called after the DOMReady event has
799 * fired. @todo the DOMContentReady event does not fire when the
800 * script is dynamically injected into the page. This means the
801 * DOMReady custom event will never fire in FireFox or Opera when the
802 * library is injected. It _will_ fire in Safari, and the IE
803 * implementation would allow for us to fire it if the defered script
804 * is not available. We want this to behave the same in all browsers.
805 * Is there a way to identify when the script has been injected
806 * instead of included inline? Is there a way to know whether the
807 * window onload event has fired without having had a listener attached
808 * to it when it did so?
810 * <p>The callback is a CustomEvent, so the signature is:</p>
811 * <p>type <string>, args <array>, customobject <object></p>
812 * <p>For DOMReady events, there are no fire argments, so the
814 * <p>"DOMReady", [], obj</p>
819 * @param {function} p_fn what to execute when the element is found.
820 * @param {object} p_obj an optional object to be passed back as
821 * a parameter to p_fn.
822 * @param {boolean|object} p_scope If set to true, p_fn will execute
823 * in the scope of p_obj, if set to an object it
824 * will execute in the scope of that object
828 onDOMReady: function(p_fn, p_obj, p_override) {
830 setTimeout(function() {
833 if (p_override === true) {
839 p_fn.call(s, "DOMReady", [], p_obj);
842 this.DOMReadyEvent.subscribe(p_fn, p_obj, p_override);
847 * Appends an event handler
849 * @method addListener
851 * @param {String|HTMLElement|Array|NodeList} el An id, an element
852 * reference, or a collection of ids and/or elements to assign the
854 * @param {String} sType The type of event to append
855 * @param {Function} fn The method the event invokes
856 * @param {Object} obj An arbitrary object that will be
857 * passed as a parameter to the handler
858 * @param {Boolean|object} override If true, the obj passed in becomes
859 * the execution scope of the listener. If an
860 * object, this object becomes the execution
862 * @return {Boolean} True if the action was successful or defered,
863 * false if one or more of the elements
864 * could not have the listener attached,
865 * or if the operation throws an exception.
868 addListener: function(el, sType, fn, obj, override) {
870 if (!fn || !fn.call) {
871 YAHOO.log(sType + " addListener failed, invalid callback", "error", "Event");
875 // The el argument can be an array of elements or element ids.
876 if ( this._isValidCollection(el)) {
878 for (var i=0,len=el.length; i<len; ++i) {
887 } else if (YAHOO.lang.isString(el)) {
888 var oEl = this.getEl(el);
889 // If the el argument is a string, we assume it is
890 // actually the id of the element. If the page is loaded
891 // we convert el to the actual element, otherwise we
892 // defer attaching the event until onload event fires
894 // check to see if we need to delay hooking up the event
895 // until after the page loads.
899 // defer adding the event until the element is available
900 this.onAvailable(el, function() {
901 YAHOO.util.Event.on(el, sType, fn, obj, override);
908 // Element should be an html element or an array if we get
911 // this.logger.debug("unable to attach event " + sType);
915 // we need to make sure we fire registered unload events
916 // prior to automatically unhooking them. So we hang on to
917 // these instead of attaching them to the window and fire the
918 // handles explicitly during our one unload event.
919 if ("unload" == sType && obj !== this) {
920 unloadListeners[unloadListeners.length] =
921 [el, sType, fn, obj, override];
925 // this.logger.debug("Adding handler: " + el + ", " + sType);
927 // if the user chooses to override the scope, we use the custom
928 // object passed in, otherwise the executing scope will be the
929 // HTML element that the event is registered on
932 if (override === true) {
939 // wrap the function so we can return the obj object when
941 var wrappedFn = function(e) {
942 return fn.call(scope, YAHOO.util.Event.getEvent(e, el),
946 var li = [el, sType, fn, wrappedFn, scope, obj, override];
947 var index = listeners.length;
948 // cache the listener so we can try to automatically unload
949 listeners[index] = li;
951 if (this.useLegacyEvent(el, sType)) {
952 var legacyIndex = this.getLegacyIndex(el, sType);
954 // Add a new dom0 wrapper if one is not detected for this
956 if ( legacyIndex == -1 ||
957 el != legacyEvents[legacyIndex][0] ) {
959 legacyIndex = legacyEvents.length;
960 legacyMap[el.id + sType] = legacyIndex;
962 // cache the signature for the DOM0 event, and
963 // include the existing handler for the event, if any
964 legacyEvents[legacyIndex] =
965 [el, sType, el["on" + sType]];
966 legacyHandlers[legacyIndex] = [];
970 YAHOO.util.Event.fireLegacyEvent(
971 YAHOO.util.Event.getEvent(e), legacyIndex);
975 // add a reference to the wrapped listener to our custom
977 //legacyHandlers[legacyIndex].push(index);
978 legacyHandlers[legacyIndex].push(li);
982 this._simpleAdd(el, sType, wrappedFn, false);
984 // handle an error trying to attach an event. If it fails
985 // we need to clean up the cache
987 this.removeListener(el, sType, fn);
997 * When using legacy events, the handler is routed to this object
998 * so we can fire our custom listener stack.
999 * @method fireLegacyEvent
1003 fireLegacyEvent: function(e, legacyIndex) {
1004 // this.logger.debug("fireLegacyEvent " + legacyIndex);
1005 var ok=true, le, lh, li, scope, ret;
1007 lh = legacyHandlers[legacyIndex].slice();
1008 for (var i=0, len=lh.length; i<len; ++i) {
1009 // for (var i in lh.length) {
1011 if ( li && li[this.WFN] ) {
1012 scope = li[this.ADJ_SCOPE];
1013 ret = li[this.WFN].call(scope, e);
1018 // Fire the original handler if we replaced one. We fire this
1019 // after the other events to keep stopPropagation/preventDefault
1020 // that happened in the DOM0 handler from touching our DOM2
1022 le = legacyEvents[legacyIndex];
1031 * Returns the legacy event index that matches the supplied
1033 * @method getLegacyIndex
1037 getLegacyIndex: function(el, sType) {
1038 var key = this.generateId(el) + sType;
1039 if (typeof legacyMap[key] == "undefined") {
1042 return legacyMap[key];
1047 * Logic that determines when we should automatically use legacy
1048 * events instead of DOM2 events. Currently this is limited to old
1049 * Safari browsers with a broken preventDefault
1050 * @method useLegacyEvent
1054 useLegacyEvent: function(el, sType) {
1055 if (this.webkit && ("click"==sType || "dblclick"==sType)) {
1056 var v = parseInt(this.webkit, 10);
1057 if (!isNaN(v) && v<418) {
1065 * Removes an event listener
1067 * @method removeListener
1069 * @param {String|HTMLElement|Array|NodeList} el An id, an element
1070 * reference, or a collection of ids and/or elements to remove
1071 * the listener from.
1072 * @param {String} sType the type of event to remove.
1073 * @param {Function} fn the method the event invokes. If fn is
1074 * undefined, then all event handlers for the type of event are
1076 * @return {boolean} true if the unbind was successful, false
1080 removeListener: function(el, sType, fn) {
1083 // The el argument can be a string
1084 if (typeof el == "string") {
1085 el = this.getEl(el);
1086 // The el argument can be an array of elements or element ids.
1087 } else if ( this._isValidCollection(el)) {
1089 for (i=el.length-1; i>-1; i--) {
1090 ok = ( this.removeListener(el[i], sType, fn) && ok );
1095 if (!fn || !fn.call) {
1096 // this.logger.debug("Error, function is not valid " + fn);
1098 return this.purgeElement(el, false, sType);
1101 if ("unload" == sType) {
1103 for (i=unloadListeners.length-1; i>-1; i--) {
1104 li = unloadListeners[i];
1109 unloadListeners.splice(i, 1);
1110 // unloadListeners[i]=null;
1118 var cacheItem = null;
1120 // The index is a hidden parameter; needed to remove it from
1121 // the method signature because it was tempting users to
1122 // try and take advantage of it, which is not possible.
1123 var index = arguments[3];
1125 if ("undefined" === typeof index) {
1126 index = this._getCacheIndex(el, sType, fn);
1130 cacheItem = listeners[index];
1133 if (!el || !cacheItem) {
1134 // this.logger.debug("cached listener not found");
1138 // this.logger.debug("Removing handler: " + el + ", " + sType);
1140 if (this.useLegacyEvent(el, sType)) {
1141 var legacyIndex = this.getLegacyIndex(el, sType);
1142 var llist = legacyHandlers[legacyIndex];
1144 for (i=0, len=llist.length; i<len; ++i) {
1145 // for (i in llist.length) {
1148 li[this.EL] == el &&
1149 li[this.TYPE] == sType &&
1150 li[this.FN] == fn) {
1160 this._simpleRemove(el, sType, cacheItem[this.WFN], false);
1162 this.lastError = ex;
1167 // removed the wrapped handler
1168 delete listeners[index][this.WFN];
1169 delete listeners[index][this.FN];
1170 listeners.splice(index, 1);
1171 // listeners[index]=null;
1178 * Returns the event's target element. Safari sometimes provides
1179 * a text node, and this is automatically resolved to the text
1180 * node's parent so that it behaves like other browsers.
1182 * @param {Event} ev the event
1183 * @param {boolean} resolveTextNode when set to true the target's
1184 * parent will be returned if the target is a
1185 * text node. @deprecated, the text node is
1186 * now resolved automatically
1187 * @return {HTMLElement} the event's target
1190 getTarget: function(ev, resolveTextNode) {
1191 var t = ev.target || ev.srcElement;
1192 return this.resolveTextNode(t);
1196 * In some cases, some browsers will return a text node inside
1197 * the actual element that was targeted. This normalizes the
1198 * return value for getTarget and getRelatedTarget.
1199 * @method resolveTextNode
1200 * @param {HTMLElement} node node to resolve
1201 * @return {HTMLElement} the normized node
1204 resolveTextNode: function(n) {
1206 if (n && 3 == n.nodeType) {
1207 return n.parentNode;
1215 * Returns the event's pageX
1217 * @param {Event} ev the event
1218 * @return {int} the event's pageX
1221 getPageX: function(ev) {
1223 if (!x && 0 !== x) {
1224 x = ev.clientX || 0;
1227 x += this._getScrollLeft();
1235 * Returns the event's pageY
1237 * @param {Event} ev the event
1238 * @return {int} the event's pageY
1241 getPageY: function(ev) {
1243 if (!y && 0 !== y) {
1244 y = ev.clientY || 0;
1247 y += this._getScrollTop();
1256 * Returns the pageX and pageY properties as an indexed array.
1258 * @param {Event} ev the event
1259 * @return {[x, y]} the pageX and pageY properties of the event
1262 getXY: function(ev) {
1263 return [this.getPageX(ev), this.getPageY(ev)];
1267 * Returns the event's related target
1268 * @method getRelatedTarget
1269 * @param {Event} ev the event
1270 * @return {HTMLElement} the event's relatedTarget
1273 getRelatedTarget: function(ev) {
1274 var t = ev.relatedTarget;
1276 if (ev.type == "mouseout") {
1278 } else if (ev.type == "mouseover") {
1283 return this.resolveTextNode(t);
1287 * Returns the time of the event. If the time is not included, the
1288 * event is modified using the current time.
1290 * @param {Event} ev the event
1291 * @return {Date} the time of the event
1294 getTime: function(ev) {
1296 var t = new Date().getTime();
1300 this.lastError = ex;
1309 * Convenience method for stopPropagation + preventDefault
1311 * @param {Event} ev the event
1314 stopEvent: function(ev) {
1315 this.stopPropagation(ev);
1316 this.preventDefault(ev);
1320 * Stops event propagation
1321 * @method stopPropagation
1322 * @param {Event} ev the event
1325 stopPropagation: function(ev) {
1326 if (ev.stopPropagation) {
1327 ev.stopPropagation();
1329 ev.cancelBubble = true;
1334 * Prevents the default behavior of the event
1335 * @method preventDefault
1336 * @param {Event} ev the event
1339 preventDefault: function(ev) {
1340 if (ev.preventDefault) {
1341 ev.preventDefault();
1343 ev.returnValue = false;
1348 * Finds the event in the window object, the caller's arguments, or
1349 * in the arguments of another method in the callstack. This is
1350 * executed automatically for events registered through the event
1351 * manager, so the implementer should not normally need to execute
1352 * this function at all.
1354 * @param {Event} e the event parameter from the handler
1355 * @param {HTMLElement} boundEl the element the listener is attached to
1356 * @return {Event} the event
1359 getEvent: function(e, boundEl) {
1360 var ev = e || window.event;
1363 var c = this.getEvent.caller;
1365 ev = c.arguments[0];
1366 if (ev && Event == ev.constructor) {
1377 * Returns the charcode for an event
1378 * @method getCharCode
1379 * @param {Event} ev the event
1380 * @return {int} the event's charCode
1383 getCharCode: function(ev) {
1384 var code = ev.keyCode || ev.charCode || 0;
1386 // webkit key normalization
1387 if (YAHOO.env.ua.webkit && (code in webkitKeymap)) {
1388 code = webkitKeymap[code];
1394 * Locating the saved event handler data by function ref
1396 * @method _getCacheIndex
1400 _getCacheIndex: function(el, sType, fn) {
1401 for (var i=0, l=listeners.length; i<l; i=i+1) {
1402 var li = listeners[i];
1404 li[this.FN] == fn &&
1405 li[this.EL] == el &&
1406 li[this.TYPE] == sType ) {
1415 * Generates an unique ID for the element if it does not already
1417 * @method generateId
1418 * @param el the element to create the id for
1419 * @return {string} the resulting id of the element
1422 generateId: function(el) {
1426 id = "yuievtautoid-" + counter;
1436 * We want to be able to use getElementsByTagName as a collection
1437 * to attach a group of events to. Unfortunately, different
1438 * browsers return different types of collections. This function
1439 * tests to determine if the object is array-like. It will also
1440 * fail if the object is an array, but is empty.
1441 * @method _isValidCollection
1442 * @param o the object to test
1443 * @return {boolean} true if the object is array-like and populated
1447 _isValidCollection: function(o) {
1449 return ( o && // o is something
1450 typeof o !== "string" && // o is not a string
1451 o.length && // o is indexed
1452 !o.tagName && // o is not an HTML element
1453 !o.alert && // o is not a window
1454 typeof o[0] !== "undefined" );
1456 YAHOO.log("node access error (xframe?)", "warn");
1467 * @deprecated Elements are not cached due to issues that arise when
1468 * elements are removed and re-added
1473 * We cache elements bound by id because when the unload event
1474 * fires, we can no longer use document.getElementById
1478 * @deprecated Elements are not cached any longer
1480 getEl: function(id) {
1481 return (typeof id === "string") ? document.getElementById(id) : id;
1485 * Clears the element cache
1486 * @deprecated Elements are not cached any longer
1487 * @method clearCache
1491 clearCache: function() { },
1494 * Custom event the fires when the dom is initially usable
1495 * @event DOMReadyEvent
1497 DOMReadyEvent: new YAHOO.util.CustomEvent("DOMReady", this),
1500 * hook up any deferred listeners
1505 _load: function(e) {
1507 if (!loadComplete) {
1508 loadComplete = true;
1509 var EU = YAHOO.util.Event;
1511 // Just in case DOMReady did not go off for some reason
1514 // Available elements may not have been detected before the
1515 // window load event fires. Try to find them now so that the
1516 // the user is more likely to get the onAvailable notifications
1517 // before the window load notification
1518 EU._tryPreloadAttach();
1524 * Fires the DOMReady event listeners the first time the document is
1530 _ready: function(e) {
1531 var EU = YAHOO.util.Event;
1535 // Fire the content ready custom event
1536 EU.DOMReadyEvent.fire();
1538 // Remove the DOMContentLoaded (FF/Opera)
1539 EU._simpleRemove(document, "DOMContentLoaded", EU._ready);
1544 * Polling function that runs before the onload event fires,
1545 * attempting to attach to DOM Nodes as soon as they are
1547 * @method _tryPreloadAttach
1551 _tryPreloadAttach: function() {
1553 if (onAvailStack.length === 0) {
1555 clearInterval(this._interval);
1556 this._interval = null;
1565 // Hold off if DOMReady has not fired and check current
1566 // readyState to protect against the IE operation aborted
1568 if (!this.DOMReady) {
1569 this.startInterval();
1576 // this.logger.debug("tryPreloadAttach");
1578 // keep trying until after the page is loaded. We need to
1579 // check the page load state prior to trying to bind the
1580 // elements so that we can be certain all elements have been
1581 // tested appropriately
1582 var tryAgain = !loadComplete;
1584 tryAgain = (retryCount > 0 && onAvailStack.length > 0);
1590 var executeItem = function (el, item) {
1592 if (item.override) {
1593 if (item.override === true) {
1596 scope = item.override;
1599 item.fn.call(scope, item.obj);
1602 var i, len, item, el, ready=[];
1604 // onAvailable onContentReady
1605 for (i=0, len=onAvailStack.length; i<len; i=i+1) {
1606 item = onAvailStack[i];
1608 el = this.getEl(item.id);
1610 if (item.checkReady) {
1611 if (loadComplete || el.nextSibling || !tryAgain) {
1613 onAvailStack[i] = null;
1616 executeItem(el, item);
1617 onAvailStack[i] = null;
1620 notAvail.push(item);
1625 // make sure onContentReady fires after onAvailable
1626 for (i=0, len=ready.length; i<len; i=i+1) {
1628 executeItem(this.getEl(item.id), item);
1635 for (i=onAvailStack.length-1; i>-1; i--) {
1636 item = onAvailStack[i];
1637 if (!item || !item.id) {
1638 onAvailStack.splice(i, 1);
1642 this.startInterval();
1644 clearInterval(this._interval);
1645 this._interval = null;
1648 this.locked = false;
1653 * Removes all listeners attached to the given element via addListener.
1654 * Optionally, the node's children can also be purged.
1655 * Optionally, you can specify a specific type of event to remove.
1656 * @method purgeElement
1657 * @param {HTMLElement} el the element to purge
1658 * @param {boolean} recurse recursively purge this element's children
1659 * as well. Use with caution.
1660 * @param {string} sType optional type of listener to purge. If
1661 * left out, all listeners will be removed
1664 purgeElement: function(el, recurse, sType) {
1665 var oEl = (YAHOO.lang.isString(el)) ? this.getEl(el) : el;
1666 var elListeners = this.getListeners(oEl, sType), i, len;
1668 for (i=elListeners.length-1; i>-1; i--) {
1669 var l = elListeners[i];
1670 this.removeListener(oEl, l.type, l.fn);
1674 if (recurse && oEl && oEl.childNodes) {
1675 for (i=0,len=oEl.childNodes.length; i<len ; ++i) {
1676 this.purgeElement(oEl.childNodes[i], recurse, sType);
1682 * Returns all listeners attached to the given element via addListener.
1683 * Optionally, you can specify a specific type of event to return.
1684 * @method getListeners
1685 * @param el {HTMLElement|string} the element or element id to inspect
1686 * @param sType {string} optional type of listener to return. If
1687 * left out, all listeners will be returned
1688 * @return {Object} the listener. Contains the following fields:
1689 * type: (string) the type of event
1690 * fn: (function) the callback supplied to addListener
1691 * obj: (object) the custom object supplied to addListener
1692 * adjust: (boolean|object) whether or not to adjust the default scope
1693 * scope: (boolean) the derived scope based on the adjust parameter
1694 * index: (int) its position in the Event util listener cache
1697 getListeners: function(el, sType) {
1698 var results=[], searchLists;
1700 searchLists = [listeners, unloadListeners];
1701 } else if (sType === "unload") {
1702 searchLists = [unloadListeners];
1704 searchLists = [listeners];
1707 var oEl = (YAHOO.lang.isString(el)) ? this.getEl(el) : el;
1709 for (var j=0;j<searchLists.length; j=j+1) {
1710 var searchList = searchLists[j];
1712 for (var i=0,len=searchList.length; i<len ; ++i) {
1713 var l = searchList[i];
1714 if ( l && l[this.EL] === oEl &&
1715 (!sType || sType === l[this.TYPE]) ) {
1720 adjust: l[this.OVERRIDE],
1721 scope: l[this.ADJ_SCOPE],
1729 return (results.length) ? results : null;
1733 * Removes all listeners registered by pe.event. Called
1734 * automatically during the unload event.
1739 _unload: function(e) {
1741 var EU = YAHOO.util.Event, i, j, l, len, index,
1742 ul = unloadListeners.slice();
1744 // execute and clear stored unload listeners
1745 for (i=0,len=unloadListeners.length; i<len; ++i) {
1749 if (l[EU.ADJ_SCOPE]) {
1750 if (l[EU.ADJ_SCOPE] === true) {
1751 scope = l[EU.UNLOAD_OBJ];
1753 scope = l[EU.ADJ_SCOPE];
1756 l[EU.FN].call(scope, EU.getEvent(e, l[EU.EL]), l[EU.UNLOAD_OBJ] );
1763 unloadListeners = null;
1765 // Remove listeners to handle IE memory leaks
1766 //if (YAHOO.env.ua.ie && listeners && listeners.length > 0) {
1768 // 2.5.0 listeners are removed for all browsers again. FireFox preserves
1769 // at least some listeners between page refreshes, potentially causing
1770 // errors during page load (mouseover listeners firing before they
1771 // should if the user moves the mouse at the correct moment).
1773 for (j=listeners.length-1; j>-1; j--) {
1776 EU.removeListener(l[EU.EL], l[EU.TYPE], l[EU.FN], j);
1782 legacyEvents = null;
1784 EU._simpleRemove(window, "unload", EU._unload);
1789 * Returns scrollLeft
1790 * @method _getScrollLeft
1794 _getScrollLeft: function() {
1795 return this._getScroll()[1];
1800 * @method _getScrollTop
1804 _getScrollTop: function() {
1805 return this._getScroll()[0];
1809 * Returns the scrollTop and scrollLeft. Used to calculate the
1810 * pageX and pageY in Internet Explorer
1811 * @method _getScroll
1815 _getScroll: function() {
1816 var dd = document.documentElement, db = document.body;
1817 if (dd && (dd.scrollTop || dd.scrollLeft)) {
1818 return [dd.scrollTop, dd.scrollLeft];
1820 return [db.scrollTop, db.scrollLeft];
1827 * Used by old versions of CustomEvent, restored for backwards
1832 * @deprecated still here for backwards compatibility
1839 * Adds a DOM event directly without the caching, cleanup, scope adj, etc
1841 * @method _simpleAdd
1842 * @param {HTMLElement} el the element to bind the handler to
1843 * @param {string} sType the type of event handler
1844 * @param {function} fn the callback to invoke
1845 * @param {boolen} capture capture or bubble phase
1849 _simpleAdd: function () {
1850 if (window.addEventListener) {
1851 return function(el, sType, fn, capture) {
1852 el.addEventListener(sType, fn, (capture));
1854 } else if (window.attachEvent) {
1855 return function(el, sType, fn, capture) {
1856 el.attachEvent("on" + sType, fn);
1859 return function(){};
1864 * Basic remove listener
1866 * @method _simpleRemove
1867 * @param {HTMLElement} el the element to bind the handler to
1868 * @param {string} sType the type of event handler
1869 * @param {function} fn the callback to invoke
1870 * @param {boolen} capture capture or bubble phase
1874 _simpleRemove: function() {
1875 if (window.removeEventListener) {
1876 return function (el, sType, fn, capture) {
1877 el.removeEventListener(sType, fn, (capture));
1879 } else if (window.detachEvent) {
1880 return function (el, sType, fn) {
1881 el.detachEvent("on" + sType, fn);
1884 return function(){};
1892 var EU = YAHOO.util.Event;
1895 * YAHOO.util.Event.on is an alias for addListener
1900 EU.on = EU.addListener;
1902 /*! DOMReady: based on work by: Dean Edwards/John Resig/Matthias Miller */
1904 // Internet Explorer: use the readyState of a defered script.
1905 // This isolates what appears to be a safe moment to manipulate
1906 // the DOM prior to when the document's readyState suggests
1907 // it is safe to do so.
1910 // Process onAvailable/onContentReady items when the
1912 YAHOO.util.Event.onDOMReady(
1913 YAHOO.util.Event._tryPreloadAttach,
1914 YAHOO.util.Event, true);
1916 var n = document.createElement('p');
1918 EU._dri = setInterval(function() {
1920 // throws an error if doc is not ready
1922 clearInterval(EU._dri);
1928 }, EU.POLL_INTERVAL);
1931 // The document's readyState in Safari currently will
1932 // change to loaded/complete before images are loaded.
1933 } else if (EU.webkit && EU.webkit < 525) {
1935 EU._dri = setInterval(function() {
1936 var rs=document.readyState;
1937 if ("loaded" == rs || "complete" == rs) {
1938 clearInterval(EU._dri);
1942 }, EU.POLL_INTERVAL);
1944 // FireFox and Opera: These browsers provide a event for this
1945 // moment. The latest WebKit releases now support this event.
1948 EU._simpleAdd(document, "DOMContentLoaded", EU._ready);
1951 /////////////////////////////////////////////////////////////
1954 EU._simpleAdd(window, "load", EU._load);
1955 EU._simpleAdd(window, "unload", EU._unload);
1956 EU._tryPreloadAttach();
1961 * EventProvider is designed to be used with YAHOO.augment to wrap
1962 * CustomEvents in an interface that allows events to be subscribed to
1963 * and fired by name. This makes it possible for implementing code to
1964 * subscribe to an event that either has not been created yet, or will
1965 * not be created at all.
1967 * @Class EventProvider
1969 YAHOO.util.EventProvider = function() { };
1971 YAHOO.util.EventProvider.prototype = {
1974 * Private storage of custom events
1975 * @property __yui_events
1982 * Private storage of custom event subscribers
1983 * @property __yui_subscribers
1987 __yui_subscribers: null,
1990 * Subscribe to a CustomEvent by event type
1993 * @param p_type {string} the type, or name of the event
1994 * @param p_fn {function} the function to exectute when the event fires
1995 * @param p_obj {Object} An object to be passed along when the event
1997 * @param p_override {boolean} If true, the obj passed in becomes the
1998 * execution scope of the listener
2000 subscribe: function(p_type, p_fn, p_obj, p_override) {
2002 this.__yui_events = this.__yui_events || {};
2003 var ce = this.__yui_events[p_type];
2006 ce.subscribe(p_fn, p_obj, p_override);
2008 this.__yui_subscribers = this.__yui_subscribers || {};
2009 var subs = this.__yui_subscribers;
2010 if (!subs[p_type]) {
2014 { fn: p_fn, obj: p_obj, override: p_override } );
2019 * Unsubscribes one or more listeners the from the specified event
2020 * @method unsubscribe
2021 * @param p_type {string} The type, or name of the event. If the type
2022 * is not specified, it will attempt to remove
2023 * the listener from all hosted events.
2024 * @param p_fn {Function} The subscribed function to unsubscribe, if not
2025 * supplied, all subscribers will be removed.
2026 * @param p_obj {Object} The custom object passed to subscribe. This is
2027 * optional, but if supplied will be used to
2028 * disambiguate multiple listeners that are the same
2029 * (e.g., you subscribe many object using a function
2030 * that lives on the prototype)
2031 * @return {boolean} true if the subscriber was found and detached.
2033 unsubscribe: function(p_type, p_fn, p_obj) {
2034 this.__yui_events = this.__yui_events || {};
2035 var evts = this.__yui_events;
2037 var ce = evts[p_type];
2039 return ce.unsubscribe(p_fn, p_obj);
2043 for (var i in evts) {
2044 if (YAHOO.lang.hasOwnProperty(evts, i)) {
2045 ret = ret && evts[i].unsubscribe(p_fn, p_obj);
2055 * Removes all listeners from the specified event. If the event type
2056 * is not specified, all listeners from all hosted custom events will
2058 * @method unsubscribeAll
2059 * @param p_type {string} The type, or name of the event
2061 unsubscribeAll: function(p_type) {
2062 return this.unsubscribe(p_type);
2066 * Creates a new custom event of the specified type. If a custom event
2067 * by that name already exists, it will not be re-created. In either
2068 * case the custom event is returned.
2070 * @method createEvent
2072 * @param p_type {string} the type, or name of the event
2073 * @param p_config {object} optional config params. Valid properties are:
2077 * scope: defines the default execution scope. If not defined
2078 * the default scope will be this instance.
2081 * silent: if true, the custom event will not generate log messages.
2082 * This is false by default.
2085 * onSubscribeCallback: specifies a callback to execute when the
2086 * event has a new subscriber. This will fire immediately for
2087 * each queued subscriber if any exist prior to the creation of
2092 * @return {CustomEvent} the custom event
2095 createEvent: function(p_type, p_config) {
2097 this.__yui_events = this.__yui_events || {};
2098 var opts = p_config || {};
2099 var events = this.__yui_events;
2101 if (events[p_type]) {
2102 YAHOO.log("EventProvider createEvent skipped: '"+p_type+"' already exists");
2105 var scope = opts.scope || this;
2106 var silent = (opts.silent);
2108 var ce = new YAHOO.util.CustomEvent(p_type, scope, silent,
2109 YAHOO.util.CustomEvent.FLAT);
2110 events[p_type] = ce;
2112 if (opts.onSubscribeCallback) {
2113 ce.subscribeEvent.subscribe(opts.onSubscribeCallback);
2116 this.__yui_subscribers = this.__yui_subscribers || {};
2117 var qs = this.__yui_subscribers[p_type];
2120 for (var i=0; i<qs.length; ++i) {
2121 ce.subscribe(qs[i].fn, qs[i].obj, qs[i].override);
2126 return events[p_type];
2131 * Fire a custom event by name. The callback functions will be executed
2132 * from the scope specified when the event was created, and with the
2133 * following parameters:
2135 * <li>The first argument fire() was executed with</li>
2136 * <li>The custom object (if any) that was passed into the subscribe()
2140 * @param p_type {string} the type, or name of the event
2141 * @param arguments {Object*} an arbitrary set of parameters to pass to
2143 * @return {boolean} the return value from CustomEvent.fire
2146 fireEvent: function(p_type, arg1, arg2, etc) {
2148 this.__yui_events = this.__yui_events || {};
2149 var ce = this.__yui_events[p_type];
2152 YAHOO.log(p_type + "event fired before it was created.");
2157 for (var i=1; i<arguments.length; ++i) {
2158 args.push(arguments[i]);
2160 return ce.fire.apply(ce, args);
2164 * Returns true if the custom event of the provided type has been created
2167 * @param type {string} the type, or name of the event
2169 hasEvent: function(type) {
2170 if (this.__yui_events) {
2171 if (this.__yui_events[type]) {
2181 * KeyListener is a utility that provides an easy interface for listening for
2182 * keydown/keyup events fired against DOM elements.
2183 * @namespace YAHOO.util
2184 * @class KeyListener
2186 * @param {HTMLElement} attachTo The element or element ID to which the key
2187 * event should be attached
2188 * @param {String} attachTo The element or element ID to which the key
2189 * event should be attached
2190 * @param {Object} keyData The object literal representing the key(s)
2191 * to detect. Possible attributes are
2192 * shift(boolean), alt(boolean), ctrl(boolean)
2193 * and keys(either an int or an array of ints
2194 * representing keycodes).
2195 * @param {Function} handler The CustomEvent handler to fire when the
2196 * key event is detected
2197 * @param {Object} handler An object literal representing the handler.
2198 * @param {String} event Optional. The event (keydown or keyup) to
2199 * listen for. Defaults automatically to keydown.
2201 * @knownissue the "keypress" event is completely broken in Safari 2.x and below.
2202 * the workaround is use "keydown" for key listening. However, if
2203 * it is desired to prevent the default behavior of the keystroke,
2204 * that can only be done on the keypress event. This makes key
2205 * handling quite ugly.
2206 * @knownissue keydown is also broken in Safari 2.x and below for the ESC key.
2207 * There currently is no workaround other than choosing another
2208 * key to listen for.
2210 YAHOO.util.KeyListener = function(attachTo, keyData, handler, event) {
2212 YAHOO.log("No attachTo element specified", "error");
2213 } else if (!keyData) {
2214 YAHOO.log("No keyData specified", "error");
2215 } else if (!handler) {
2216 YAHOO.log("No handler specified", "error");
2220 event = YAHOO.util.KeyListener.KEYDOWN;
2224 * The CustomEvent fired internally when a key is pressed
2227 * @param {Object} keyData The object literal representing the key(s) to
2228 * detect. Possible attributes are shift(boolean),
2229 * alt(boolean), ctrl(boolean) and keys(either an
2230 * int or an array of ints representing keycodes).
2232 var keyEvent = new YAHOO.util.CustomEvent("keyPressed");
2235 * The CustomEvent fired when the KeyListener is enabled via the enable()
2237 * @event enabledEvent
2238 * @param {Object} keyData The object literal representing the key(s) to
2239 * detect. Possible attributes are shift(boolean),
2240 * alt(boolean), ctrl(boolean) and keys(either an
2241 * int or an array of ints representing keycodes).
2243 this.enabledEvent = new YAHOO.util.CustomEvent("enabled");
2246 * The CustomEvent fired when the KeyListener is disabled via the
2247 * disable() function
2248 * @event disabledEvent
2249 * @param {Object} keyData The object literal representing the key(s) to
2250 * detect. Possible attributes are shift(boolean),
2251 * alt(boolean), ctrl(boolean) and keys(either an
2252 * int or an array of ints representing keycodes).
2254 this.disabledEvent = new YAHOO.util.CustomEvent("disabled");
2256 if (typeof attachTo == 'string') {
2257 attachTo = document.getElementById(attachTo);
2260 if (typeof handler == 'function') {
2261 keyEvent.subscribe(handler);
2263 keyEvent.subscribe(handler.fn, handler.scope, handler.correctScope);
2267 * Handles the key event when a key is pressed.
2268 * @method handleKeyPress
2269 * @param {DOMEvent} e The keypress DOM event
2270 * @param {Object} obj The DOM event scope object
2273 function handleKeyPress(e, obj) {
2274 if (! keyData.shift) {
2275 keyData.shift = false;
2277 if (! keyData.alt) {
2278 keyData.alt = false;
2280 if (! keyData.ctrl) {
2281 keyData.ctrl = false;
2284 // check held down modifying keys first
2285 if (e.shiftKey == keyData.shift &&
2286 e.altKey == keyData.alt &&
2287 e.ctrlKey == keyData.ctrl) { // if we pass this, all modifiers match
2291 if (keyData.keys instanceof Array) {
2292 for (var i=0;i<keyData.keys.length;i++) {
2293 dataItem = keyData.keys[i];
2295 if (dataItem == e.charCode ) {
2296 keyEvent.fire(e.charCode, e);
2298 } else if (dataItem == e.keyCode) {
2299 keyEvent.fire(e.keyCode, e);
2304 dataItem = keyData.keys;
2305 if (dataItem == e.charCode ) {
2306 keyEvent.fire(e.charCode, e);
2307 } else if (dataItem == e.keyCode) {
2308 keyEvent.fire(e.keyCode, e);
2315 * Enables the KeyListener by attaching the DOM event listeners to the
2316 * target DOM element
2319 this.enable = function() {
2320 if (! this.enabled) {
2321 YAHOO.util.Event.addListener(attachTo, event, handleKeyPress);
2322 this.enabledEvent.fire(keyData);
2325 * Boolean indicating the enabled/disabled state of the Tooltip
2329 this.enabled = true;
2333 * Disables the KeyListener by removing the DOM event listeners from the
2334 * target DOM element
2337 this.disable = function() {
2339 YAHOO.util.Event.removeListener(attachTo, event, handleKeyPress);
2340 this.disabledEvent.fire(keyData);
2342 this.enabled = false;
2346 * Returns a String representation of the object.
2348 * @return {String} The string representation of the KeyListener
2350 this.toString = function() {
2351 return "KeyListener [" + keyData.keys + "] " + attachTo.tagName +
2352 (attachTo.id ? "[" + attachTo.id + "]" : "");
2358 * Constant representing the DOM "keydown" event.
2359 * @property YAHOO.util.KeyListener.KEYDOWN
2364 YAHOO.util.KeyListener.KEYDOWN = "keydown";
2367 * Constant representing the DOM "keyup" event.
2368 * @property YAHOO.util.KeyListener.KEYUP
2373 YAHOO.util.KeyListener.KEYUP = "keyup";
2376 * keycode constants for a subset of the special keys
2381 YAHOO.util.KeyListener.KEY = {
2406 YAHOO.register("event", YAHOO.util.Event, {version: "2.5.2", build: "1076"});