2 YUI 3.13.0 (build 508226d)
3 Copyright 2013 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
9 var GLOBAL_ENV = YUI.Env;
11 if (!GLOBAL_ENV._ready) {
12 GLOBAL_ENV._ready = function() {
13 GLOBAL_ENV.DOMReady = true;
14 GLOBAL_ENV.remove(YUI.config.doc, 'DOMContentLoaded', GLOBAL_ENV._ready);
17 GLOBAL_ENV.add(YUI.config.doc, 'DOMContentLoaded', GLOBAL_ENV._ready);
20 YUI.add('event-base', function (Y, NAME) {
23 * DOM event listener abstraction layer
25 * @submodule event-base
29 * The domready event fires at the moment the browser's DOM is
30 * usable. In most cases, this is before images are fully
31 * downloaded, allowing you to provide a more responsive user
34 * In YUI 3, domready subscribers will be notified immediately if
35 * that moment has already passed when the subscription is created.
37 * One exception is if the yui.js file is dynamically injected into
38 * the page. If this is done, you must tell the YUI instance that
39 * you did this in order for DOMReady (and window load events) to
40 * fire normally. That configuration option is 'injected' -- set
41 * it to true if the yui.js script is not included inline.
43 * This method is part of the 'event-ready' module, which is a
44 * submodule of 'event'.
49 Y.publish('domready', {
54 if (YUI.Env.DOMReady) {
57 Y.Do.before(function() { Y.fire('domready'); }, YUI.Env, '_ready');
61 * Custom event engine, DOM event listener abstraction layer, synthetic DOM
64 * @submodule event-base
68 * Wraps a DOM event, properties requiring browser abstraction are
69 * fixed here. Provids a security layer when required.
70 * @class DOMEventFacade
71 * @param ev {Event} the DOM event
72 * @param currentTarget {HTMLElement} the element the listener was attached to
73 * @param wrapper {Event.Custom} the custom event wrapper for this DOM event
81 * webkit key remapping required for Safari < 3.1
82 * @property webkitKeymap
91 63277: 34, // page down
92 25: 9, // SHIFT-TAB (Safari provides a different key code in
93 // this case, even though the shiftKey modifier is set)
100 * Returns a wrapped node. Intended to be used on event targets,
101 * so it will return the node's parent if the target is a text
104 * If accessing a property of the node throws an error, this is
105 * probably the anonymous div wrapper Gecko adds inside text
106 * nodes. This likely will only occur when attempting to access
107 * the relatedTarget. In this case, we now return null because
108 * the anonymous div is completely useless and we do not know
109 * what the related target was because we can't even get to
110 * the element's parent node.
115 resolve = function(n) {
120 if (n && 3 == n.nodeType) {
130 DOMEventFacade = function(ev, currentTarget, wrapper) {
132 this._currentTarget = currentTarget;
133 this._wrapper = wrapper || EMPTY;
139 Y.extend(DOMEventFacade, Object, {
144 overrides = this._wrapper.overrides,
148 currentTarget = this._currentTarget;
150 this.altKey = e.altKey;
151 this.ctrlKey = e.ctrlKey;
152 this.metaKey = e.metaKey;
153 this.shiftKey = e.shiftKey;
154 this.type = (overrides && overrides.type) || e.type;
155 this.clientX = e.clientX;
156 this.clientY = e.clientY;
161 // charCode is unknown in keyup, keydown. keyCode is unknown in keypress.
162 // FF 3.6 - 8+? pass 0 for keyCode in keypress events.
163 // Webkit, FF 3.6-8+?, and IE9+? pass 0 for charCode in keydown, keyup.
164 // Webkit and IE9+? duplicate charCode in keyCode.
165 // Opera never sets charCode, always keyCode (though with the charCode).
166 // IE6-8 don't set charCode or which.
167 // All browsers other than IE6-8 set which=keyCode in keydown, keyup, and
168 // which=charCode in keypress.
170 // Moral of the story: (e.which || e.keyCode) will always return the
171 // known code for that key event phase. e.keyCode is often different in
172 // keypress from keydown and keyup.
173 c = e.keyCode || e.charCode;
175 if (ua.webkit && (c in webkitKeymap)) {
181 // Fill in e.which for IE - implementers should always use this over
182 // e.keyCode or e.charCode.
183 this.which = e.which || e.charCode || c;
184 // this.button = e.button;
185 this.button = this.which;
187 this.target = resolve(e.target);
188 this.currentTarget = resolve(currentTarget);
189 this.relatedTarget = resolve(e.relatedTarget);
191 if (e.type == "mousewheel" || e.type == "DOMMouseScroll") {
192 this.wheelDelta = (e.detail) ? (e.detail * -1) : Math.round(e.wheelDelta / 80) || ((e.wheelDelta < 0) ? -1 : 1);
196 this._touch(e, currentTarget, this._wrapper);
200 stopPropagation: function() {
201 this._event.stopPropagation();
202 this._wrapper.stopped = 1;
206 stopImmediatePropagation: function() {
208 if (e.stopImmediatePropagation) {
209 e.stopImmediatePropagation();
211 this.stopPropagation();
213 this._wrapper.stopped = 2;
217 preventDefault: function(returnValue) {
220 e.returnValue = returnValue || false;
221 this._wrapper.prevented = 1;
225 halt: function(immediate) {
227 this.stopImmediatePropagation();
229 this.stopPropagation();
232 this.preventDefault();
237 DOMEventFacade.resolve = resolve;
238 Y.DOM2EventFacade = DOMEventFacade;
239 Y.DOMEventFacade = DOMEventFacade;
244 * @type {Native DOM Event}
249 The name of the event (e.g. "click")
256 `true` if the "alt" or "option" key is pressed.
263 `true` if the shift key is pressed.
270 `true` if the "Windows" key on a Windows keyboard, "command" key on an
271 Apple keyboard, or "meta" key on other keyboards is pressed.
278 `true` if the "Ctrl" or "control" key is pressed.
285 * The X location of the event on the page (including scroll)
291 * The Y location of the event on the page (including scroll)
297 * The X location of the event in the viewport
303 * The Y location of the event in the viewport
309 * The keyCode for key events. Uses charCode if keyCode is not available
315 * The charCode for key events. Same as keyCode
321 * The button that was pushed. 1 for left click, 2 for middle click, 3 for
322 * right click. This is only reliably populated on `mouseup` events.
328 * The button that was pushed. Same as button.
334 * Node reference for the targeted element
340 * Node reference for the element that the listener was attached to.
341 * @property currentTarget
346 * Node reference to the relatedTarget
347 * @property relatedTarget
352 * Number representing the direction and velocity of the movement of the mousewheel.
353 * Negative is down, the higher the number, the faster. Applies to the mousewheel event.
354 * @property wheelDelta
359 * Stops the propagation to the next bubble target
360 * @method stopPropagation
364 * Stops the propagation to the next bubble target and
365 * prevents any additional listeners from being exectued
366 * on the current target.
367 * @method stopImmediatePropagation
371 * Prevents the event's default behavior
372 * @method preventDefault
373 * @param returnValue {string} sets the returnValue of the event to this value
374 * (rather than the default false value). This can be used to add a customized
375 * confirmation query to the beforeunload event).
379 * Stops the event propagation and prevents the default
382 * @param immediate {boolean} if true additional listeners
383 * on the current target will not be executed
388 * The event utility provides functions to add and remove event listeners,
389 * event cleansing. It also tries to automatically remove listeners it
390 * registers during the unload event.
393 * @submodule event-base
397 * The event utility provides functions to add and remove event listeners,
398 * event cleansing. It also tries to automatically remove listeners it
399 * registers during the unload event.
405 Y.Env.evt.dom_wrappers = {};
406 Y.Env.evt.dom_map = {};
408 var _eventenv = Y.Env.evt,
412 remove = YUI.Env.remove,
414 onLoad = function() {
415 YUI.Env.windowLoaded = true;
417 remove(win, "load", onLoad);
420 onUnload = function() {
424 EVENT_READY = 'domready',
426 COMPAT_ARG = '~yui|2|compat~',
428 shouldIterate = function(o) {
430 // TODO: See if there's a more performant way to return true early on this, for the common case
431 return (o && typeof o !== "string" && Y.Lang.isNumber(o.length) && !o.tagName && !Y.DOM.isWindow(o));
433 Y.log("collection check failure", "warn", "event");
438 // aliases to support DOM event subscription clean up when the last
439 // subscriber is detached. deleteAndClean overrides the DOM event's wrapper
440 // CustomEvent _delete method.
441 _ceProtoDelete = Y.CustomEvent.prototype._delete,
442 _deleteAndClean = function(s) {
443 var ret = _ceProtoDelete.apply(this, arguments);
445 if (!this.hasSubs()) {
446 Y.Event._clean(this);
455 * True after the onload event has fired
456 * @property _loadComplete
461 var _loadComplete = false,
464 * The number of times to poll after window.onload. This number is
465 * increased if additional late-bound handlers are requested after
467 * @property _retryCount
474 * onAvailable listeners
482 * Custom event wrappers for DOM events. Key is
483 * 'event:' + Element uid stamp + event type
484 * @property _wrappers
485 * @type Y.Event.Custom
489 _wrappers = _eventenv.dom_wrappers,
491 _windowLoadKey = null,
494 * Custom event wrapper map DOM events. Key is
495 * Element uid stamp. Each item is a hash of custom event
496 * wrappers as provided in the _wrappers collection. This
497 * provides the infrastructure for getListeners.
498 * @property _el_events
502 _el_events = _eventenv.dom_map;
507 * The number of times we should look for elements that are not
508 * in the DOM at the time the event is requested after the document
509 * has been loaded. The default is 1000@amp;40 ms, so it will poll
510 * for 40 seconds or until all outstanding handlers are bound
511 * (whichever comes first).
512 * @property POLL_RETRYS
520 * The poll interval in milliseconds
521 * @property POLL_INTERVAL
529 * addListener/removeListener can throw errors in unexpected scenarios.
530 * These errors are suppressed, the method returns false, and this property
532 * @property lastError
541 * @property _interval
548 * document readystate poll handle
556 * True when the document is initially usable
564 * @method startInterval
568 startInterval: function() {
569 if (!Event._interval) {
570 Event._interval = setInterval(Event._poll, Event.POLL_INTERVAL);
575 * Executes the supplied callback when the item with the supplied
576 * id is found. This is meant to be used to execute behavior as
577 * soon as possible as the page loads. If you use this after the
578 * initial page load it will poll for a fixed time for the element.
579 * The number of times it will poll and the frequency are
580 * configurable. By default it will poll for 10 seconds.
582 * <p>The callback is executed with a single parameter:
583 * the custom object parameter, if provided.</p>
585 * @method onAvailable
587 * @param {string||string[]} id the id of the element, or an array
588 * of ids to look for.
589 * @param {function} fn what to execute when the element is found.
590 * @param {object} p_obj an optional object to be passed back as
592 * @param {boolean|object} p_override If set to true, fn will execute
593 * in the context of p_obj, if set to an object it
594 * will execute in the context of that object
595 * @param checkContent {boolean} check child node readiness (onContentReady)
597 * @deprecated Use Y.on("available")
599 // @TODO fix arguments
600 onAvailable: function(id, fn, p_obj, p_override, checkContent, compat) {
602 var a = Y.Array(id), i, availHandle;
604 // Y.log('onAvailable registered for: ' + id);
606 for (i=0; i<a.length; i=i+1) {
611 override: p_override,
612 checkReady: checkContent,
616 _retryCount = this.POLL_RETRYS;
618 // We want the first test to be immediate, but async
619 setTimeout(Event._poll, 0);
621 availHandle = new Y.EventHandle({
623 _delete: function() {
624 // set by the event system for lazy DOM listeners
625 if (availHandle.handle) {
626 availHandle.handle.detach();
632 // otherwise try to remove the onAvailable listener(s)
633 for (i = 0; i < a.length; i++) {
634 for (j = 0; j < _avail.length; j++) {
635 if (a[i] === _avail[j].id) {
648 * Works the same way as onAvailable, but additionally checks the
649 * state of sibling elements to determine if the content of the
650 * available element is safe to modify.
652 * <p>The callback is executed with a single parameter:
653 * the custom object parameter, if provided.</p>
655 * @method onContentReady
657 * @param {string} id the id of the element to look for.
658 * @param {function} fn what to execute when the element is ready.
659 * @param {object} obj an optional object to be passed back as
661 * @param {boolean|object} override If set to true, fn will execute
662 * in the context of p_obj. If an object, fn will
663 * exectute in the context of that object
666 * @deprecated Use Y.on("contentready")
668 // @TODO fix arguments
669 onContentReady: function(id, fn, obj, override, compat) {
670 return Event.onAvailable(id, fn, obj, override, true, compat);
674 * Adds an event listener
678 * @param {String} type The type of event to append
679 * @param {Function} fn The method the event invokes
680 * @param {String|HTMLElement|Array|NodeList} el An id, an element
681 * reference, or a collection of ids and/or elements to assign the
683 * @param {Object} context optional context object
684 * @param {Boolean|object} args 0..n arguments to pass to the callback
685 * @return {EventHandle} an object to that can be used to detach the listener
690 attach: function(type, fn, el, context) {
691 return Event._attach(Y.Array(arguments, 0, true));
694 _createWrapper: function (el, type, capture, compat, facade) {
698 key = 'event:' + ek + type;
700 if (false === facade) {
708 cewrapper = _wrappers[key];
713 cewrapper = Y.publish(key, {
717 contextFn: function() {
721 cewrapper.nodeRef = cewrapper.nodeRef || Y.one(cewrapper.el);
722 return cewrapper.nodeRef;
727 cewrapper.overrides = {};
729 // for later removeListener calls
732 cewrapper.domkey = ek;
733 cewrapper.type = type;
734 cewrapper.fn = function(e) {
735 cewrapper.fire(Event.getEvent(e, el, (compat || (false === facade))));
737 cewrapper.capture = capture;
739 if (el == win && type == "load") {
740 // window load happens once
741 cewrapper.fireOnce = true;
742 _windowLoadKey = key;
744 cewrapper._delete = _deleteAndClean;
746 _wrappers[key] = cewrapper;
747 _el_events[ek] = _el_events[ek] || {};
748 _el_events[ek][key] = cewrapper;
750 add(el, type, cewrapper.fn, capture);
757 _attach: function(args, conf) {
760 handles, oEl, cewrapper, context,
761 fireNow = false, ret,
765 facade = conf && conf.facade,
766 capture = conf && conf.capture,
767 overrides = conf && conf.overrides;
769 if (args[args.length-1] === COMPAT_ARG) {
773 if (!fn || !fn.call) {
774 // throw new TypeError(type + " attach call failed, callback undefined");
775 Y.log(type + " attach call failed, invalid callback", "error", "event");
779 // The el argument can be an array of elements or element ids.
780 if (shouldIterate(el)) {
784 Y.each(el, function(v, k) {
786 handles.push(Event._attach(args.slice(), conf));
789 // return (handles.length === 1) ? handles[0] : handles;
790 return new Y.EventHandle(handles);
792 // If the el argument is a string, we assume it is
793 // actually the id of the element. If the page is loaded
794 // we convert el to the actual element, otherwise we
795 // defer attaching the event until the element is
797 } else if (Y.Lang.isString(el)) {
799 // oEl = (compat) ? Y.DOM.byId(el) : Y.Selector.query(el);
802 oEl = Y.DOM.byId(el);
805 oEl = Y.Selector.query(el);
807 switch (oEl.length) {
816 return Event._attach(args, conf);
824 // Not found = defer adding the event until the element is available
827 // Y.log(el + ' not found');
828 ret = Event.onAvailable(el, function() {
829 // Y.log('lazy attach: ' + args);
831 ret.handle = Event._attach(args, conf);
833 }, Event, true, false, compat);
840 // Element should be an html element or node
842 Y.log("unable to attach event " + type, "warn", "event");
846 if (Y.Node && Y.instanceOf(el, Y.Node)) {
847 el = Y.Node.getDOMNode(el);
850 cewrapper = Event._createWrapper(el, type, capture, compat, facade);
852 Y.mix(cewrapper.overrides, overrides);
855 if (el == win && type == "load") {
857 // if the load is complete, fire immediately.
858 // all subscribers, including the current one
860 if (YUI.Env.windowLoaded) {
871 // set context to the Node if not specified
872 // ret = cewrapper.on.apply(cewrapper, trimmedArgs);
873 ret = cewrapper._on(fn, context, (args.length > 4) ? args.slice(4) : null);
884 * Removes an event listener. Supports the signature the event was bound
885 * with, but the preferred way to remove listeners is using the handle
886 * that is returned when using Y.on
890 * @param {String} type the type of event to remove.
891 * @param {Function} fn the method the event invokes. If fn is
892 * undefined, then all event handlers for the type of event are
894 * @param {String|HTMLElement|Array|NodeList|EventHandle} el An
895 * event handle, an id, an element reference, or a collection
896 * of ids and/or elements to remove the listener from.
897 * @return {boolean} true if the unbind was successful, false otherwise.
900 detach: function(type, fn, el, obj) {
902 var args=Y.Array(arguments, 0, true), compat, l, ok, i,
905 if (args[args.length-1] === COMPAT_ARG) {
910 if (type && type.detach) {
911 return type.detach();
914 // The el argument can be a string
915 if (typeof el == "string") {
917 // el = (compat) ? Y.DOM.byId(el) : Y.all(el);
921 el = Y.Selector.query(el);
929 // return Event.detach.apply(Event, args);
938 return el.detach.apply(el, args);
939 // The el argument can be an array of elements or element ids.
940 } else if (shouldIterate(el)) {
942 for (i=0, l=el.length; i<l; ++i) {
944 ok = ( Y.Event.detach.apply(Y.Event, args) && ok );
950 if (!type || !fn || !fn.call) {
951 return Event.purgeElement(el, false, type);
954 id = 'event:' + Y.stamp(el) + type;
958 return ce.detach(fn);
966 * Finds the event in the window object, the caller's arguments, or
967 * in the arguments of another method in the callstack. This is
968 * executed automatically for events registered through the event
969 * manager, so the implementer should not normally need to execute
970 * this function at all.
972 * @param {Event} e the event parameter from the handler
973 * @param {HTMLElement} el the element the listener was attached to
974 * @return {Event} the event
977 getEvent: function(e, el, noFacade) {
978 var ev = e || win.event;
980 return (noFacade) ? ev :
981 new Y.DOMEventFacade(ev, el, _wrappers['event:' + Y.stamp(el) + e.type]);
985 * Generates an unique ID for the element if it does not already
988 * @param el the element to create the id for
989 * @return {string} the resulting id of the element
992 generateId: function(el) {
993 return Y.DOM.generateID(el);
997 * We want to be able to use getElementsByTagName as a collection
998 * to attach a group of events to. Unfortunately, different
999 * browsers return different types of collections. This function
1000 * tests to determine if the object is array-like. It will also
1001 * fail if the object is an array, but is empty.
1002 * @method _isValidCollection
1003 * @param o the object to test
1004 * @return {boolean} true if the object is array-like and populated
1005 * @deprecated was not meant to be used directly
1009 _isValidCollection: shouldIterate,
1012 * hook up any deferred listeners
1017 _load: function(e) {
1018 if (!_loadComplete) {
1019 // Y.log('Load Complete', 'info', 'event');
1020 _loadComplete = true;
1022 // Just in case DOMReady did not go off for some reason
1025 Y.fire(EVENT_READY);
1028 // Available elements may not have been detected before the
1029 // window load event fires. Try to find them now so that the
1030 // the user is more likely to get the onAvailable notifications
1031 // before the window load notification
1037 * Polling function that runs before the onload event fires,
1038 * attempting to attach to DOM Nodes as soon as they are
1049 if (Y.UA.ie && !YUI.Env.DOMReady) {
1050 // Hold off if DOMReady has not fired and check current
1051 // readyState to protect against the IE operation aborted
1053 Event.startInterval();
1057 Event.locked = true;
1059 // Y.log.debug("poll");
1060 // keep trying until after the page is loaded. We need to
1061 // check the page load state prior to trying to bind the
1062 // elements so that we can be certain all elements have been
1063 // tested appropriately
1064 var i, len, item, el, notAvail, executeItem,
1065 tryAgain = !_loadComplete;
1068 tryAgain = (_retryCount > 0);
1074 executeItem = function (el, item) {
1075 var context, ov = item.override;
1078 if (item.override) {
1087 item.fn.call(context, item.obj);
1089 context = item.obj || Y.one(el);
1090 item.fn.apply(context, (Y.Lang.isArray(ov)) ? ov : []);
1093 Y.log("Error in available or contentReady callback", 'error', 'event');
1098 for (i=0,len=_avail.length; i<len; ++i) {
1100 if (item && !item.checkReady) {
1102 // el = (item.compat) ? Y.DOM.byId(item.id) : Y.one(item.id);
1103 el = (item.compat) ? Y.DOM.byId(item.id) : Y.Selector.query(item.id, null, true);
1106 // Y.log('avail: ' + el);
1107 executeItem(el, item);
1110 // Y.log('NOT avail: ' + el);
1111 notAvail.push(item);
1117 for (i=0,len=_avail.length; i<len; ++i) {
1119 if (item && item.checkReady) {
1121 // el = (item.compat) ? Y.DOM.byId(item.id) : Y.one(item.id);
1122 el = (item.compat) ? Y.DOM.byId(item.id) : Y.Selector.query(item.id, null, true);
1125 // The element is available, but not necessarily ready
1126 // @todo should we test parentNode.nextSibling?
1127 if (_loadComplete || (el.get && el.get('nextSibling')) || el.nextSibling) {
1128 executeItem(el, item);
1132 notAvail.push(item);
1137 _retryCount = (notAvail.length === 0) ? 0 : _retryCount - 1;
1140 // we may need to strip the nulled out items here
1141 Event.startInterval();
1143 clearInterval(Event._interval);
1144 Event._interval = null;
1147 Event.locked = false;
1154 * Removes all listeners attached to the given element via addListener.
1155 * Optionally, the node's children can also be purged.
1156 * Optionally, you can specify a specific type of event to remove.
1157 * @method purgeElement
1158 * @param {HTMLElement} el the element to purge
1159 * @param {boolean} recurse recursively purge this element's children
1160 * as well. Use with caution.
1161 * @param {string} type optional type of listener to purge. If
1162 * left out, all listeners will be removed
1165 purgeElement: function(el, recurse, type) {
1166 // var oEl = (Y.Lang.isString(el)) ? Y.one(el) : el,
1167 var oEl = (Y.Lang.isString(el)) ? Y.Selector.query(el, null, true) : el,
1168 lis = Event.getListeners(oEl, type), i, len, children, child;
1170 if (recurse && oEl) {
1172 children = Y.Selector.query('*', oEl);
1173 len = children.length;
1174 for (i = 0; i < len; ++i) {
1175 child = Event.getListeners(children[i], type);
1177 lis = lis.concat(child);
1183 for (i = 0, len = lis.length; i < len; ++i) {
1191 * Removes all object references and the DOM proxy subscription for
1192 * a given event for a DOM node.
1195 * @param wrapper {CustomEvent} Custom event proxy for the DOM
1201 _clean: function (wrapper) {
1202 var key = wrapper.key,
1203 domkey = wrapper.domkey;
1205 remove(wrapper.el, wrapper.type, wrapper.fn, wrapper.capture);
1206 delete _wrappers[key];
1207 delete Y._yuievt.events[key];
1208 if (_el_events[domkey]) {
1209 delete _el_events[domkey][key];
1210 if (!Y.Object.size(_el_events[domkey])) {
1211 delete _el_events[domkey];
1217 * Returns all listeners attached to the given element via addListener.
1218 * Optionally, you can specify a specific type of event to return.
1219 * @method getListeners
1220 * @param el {HTMLElement|string} the element or element id to inspect
1221 * @param type {string} optional type of listener to return. If
1222 * left out, all listeners will be returned
1223 * @return {CustomEvent} the custom event wrapper for the DOM event(s)
1226 getListeners: function(el, type) {
1227 var ek = Y.stamp(el, true), evts = _el_events[ek],
1228 results=[] , key = (type) ? 'event:' + ek + type : null,
1229 adapters = _eventenv.plugins;
1236 // look for synthetic events
1237 if (adapters[type] && adapters[type].eventDef) {
1242 results.push(evts[key]);
1245 // get native events as well
1248 results.push(evts[key]);
1252 Y.each(evts, function(v, k) {
1257 return (results.length) ? results : null;
1261 * Removes all listeners registered by pe.event. Called
1262 * automatically during the unload event.
1267 _unload: function(e) {
1268 Y.each(_wrappers, function(v, k) {
1269 if (v.type == 'unload') {
1274 remove(win, "unload", onUnload);
1278 * Adds a DOM event directly without the caching, cleanup, context adj, etc
1281 * @param {HTMLElement} el the element to bind the handler to
1282 * @param {string} type the type of event handler
1283 * @param {function} fn the callback to invoke
1284 * @param {boolen} capture capture or bubble phase
1291 * Basic remove listener
1293 * @method nativeRemove
1294 * @param {HTMLElement} el the element to bind the handler to
1295 * @param {string} type the type of event handler
1296 * @param {function} fn the callback to invoke
1297 * @param {boolen} capture capture or bubble phase
1301 nativeRemove: remove
1308 if (config.injected || YUI.Env.windowLoaded) {
1311 add(win, "load", onLoad);
1314 // Process onAvailable/onContentReady items when when the DOM is ready in IE
1316 Y.on(EVENT_READY, Event._poll);
1318 // In IE6 and below, detach event handlers when the page is unloaded in
1319 // order to try and prevent cross-page memory leaks. This isn't done in
1320 // other browsers because a) it's not necessary, and b) it breaks the
1321 // back/forward cache.
1324 add(win, "unload", onUnload);
1326 Y.log("Registering unload listener failed.", "warn", "event-base");
1331 Event.Custom = Y.CustomEvent;
1332 Event.Subscriber = Y.Subscriber;
1333 Event.Target = Y.EventTarget;
1334 Event.Handle = Y.EventHandle;
1335 Event.Facade = Y.EventFacade;
1342 * DOM event listener abstraction layer
1344 * @submodule event-base
1348 * Executes the callback as soon as the specified element
1349 * is detected in the DOM. This function expects a selector
1350 * string for the element(s) to detect. If you already have
1351 * an element reference, you don't need this event.
1353 * @param type {string} 'available'
1354 * @param fn {function} the callback function to execute.
1355 * @param el {string} an selector for the element(s) to attach
1356 * @param context optional argument that specifies what 'this' refers to.
1357 * @param args* 0..n additional arguments to pass on to the callback function.
1358 * These arguments will be added after the event object.
1359 * @return {EventHandle} the detach handle
1362 Y.Env.evt.plugins.available = {
1363 on: function(type, fn, id, o) {
1364 var a = arguments.length > 4 ? Y.Array(arguments, 4, true) : null;
1365 return Y.Event.onAvailable.call(Y.Event, id, fn, o, a);
1370 * Executes the callback as soon as the specified element
1371 * is detected in the DOM with a nextSibling property
1372 * (indicating that the element's children are available).
1373 * This function expects a selector
1374 * string for the element(s) to detect. If you already have
1375 * an element reference, you don't need this event.
1376 * @event contentready
1377 * @param type {string} 'contentready'
1378 * @param fn {function} the callback function to execute.
1379 * @param el {string} an selector for the element(s) to attach.
1380 * @param context optional argument that specifies what 'this' refers to.
1381 * @param args* 0..n additional arguments to pass on to the callback function.
1382 * These arguments will be added after the event object.
1383 * @return {EventHandle} the detach handle
1386 Y.Env.evt.plugins.contentready = {
1387 on: function(type, fn, id, o) {
1388 var a = arguments.length > 4 ? Y.Array(arguments, 4, true) : null;
1389 return Y.Event.onContentReady.call(Y.Event, id, fn, o, a);
1394 }, '3.13.0', {"requires": ["event-custom-base"]});