event.js revision 6d76a3666eb84ef4bf28d21c54f9df61e42b423f
* DOM event listener abstraction layer * The domready event fires at the moment the browser's DOM is * usable. In most cases, this is before images are fully * downloaded, allowing you to provide a more responsive user * In YUI 3, domready subscribers will be notified immediately if * that moment has already passed when the subscription is created. * One exception is if the yui.js file is dynamically injected into * the page. If this is done, you must tell the YUI instance that * you did this in order for DOMReady (and window load events) to * fire normally. That configuration option is 'injected' -- set * it to true if the yui.js script is not included inline. * This method is part of the 'event-ready' module, which is a * Custom event engine, DOM event listener abstraction layer, synthetic DOM * Wraps a DOM event, properties requiring browser abstraction are * fixed here. Provids a security layer when required. * @param ev {Event} the DOM event * @param currentTarget {HTMLElement} the element the listener was attached to * @param wrapper {Event.Custom} the custom event wrapper for this DOM event * webkit key remapping required for Safari < 3.1 25:
9,
// SHIFT-TAB (Safari provides a different key code in // this case, even though the shiftKey modifier is set) * Returns a wrapped node. Intended to be used on event targets, * so it will return the node's parent if the target is a text * If accessing a property of the node throws an error, this is * probably the anonymous div wrapper Gecko adds inside text * nodes. This likely will only occur when attempting to access * the relatedTarget. In this case, we now return null because * the anonymous div is completely useless and we do not know * what the related target was because we can't even get to * the element's parent node. // this.button = e.button; if (e.
type ==
"mousewheel" || e.
type ==
"DOMMouseScroll") {
* The X location of the event on the page (including scroll) * The Y location of the event on the page (including scroll) * The keyCode for key events. Uses charCode if keyCode is not available * The charCode for key events. Same as keyCode * The button that was pushed. * The button that was pushed. Same as button. * Node reference for the targeted element * Node reference for the element that the listener was attached to. * Node reference to the relatedTarget * Number representing the direction and velocity of the movement of the mousewheel. * Negative is down, the higher the number, the faster. Applies to the mousewheel event. * Stops the propagation to the next bubble target * @method stopPropagation * Stops the propagation to the next bubble target and * prevents any additional listeners from being exectued * @method stopImmediatePropagation * Prevents the event's default behavior * @param returnValue {string} sets the returnValue of the event to this value * (rather than the default false value). This can be used to add a customized * confirmation query to the beforeunload event). * Stops the event propagation and prevents the default * @param immediate {boolean} if true additional listeners * on the current target will not be executed * DOM event listener abstraction layer * The event utility provides functions to add and remove event listeners, * event cleansing. It also tries to automatically remove listeners it * registers during the unload event. // aliases to support DOM event subscription clean up when the last // subscriber is detached. deleteAndClean overrides the DOM event's wrapper // CustomEvent _delete method. * True after the onload event has fired * @property _loadComplete * The number of times to poll after window.onload. This number is * increased if additional late-bound handlers are requested after * Custom event wrappers for DOM events. Key is * 'event:' + Element uid stamp + event type * Custom event wrapper map DOM events. Key is * Element uid stamp. Each item is a hash of custom event * wrappers as provided in the _wrappers collection. This * provides the infrastructure for getListeners. * The number of times we should look for elements that are not * in the DOM at the time the event is requested after the document * has been loaded. The default is 1000@amp;40 ms, so it will poll * for 40 seconds or until all outstanding handlers are bound * (whichever comes first). * The poll interval in milliseconds * @property POLL_INTERVAL * These errors are suppressed, the method returns false, and this property * document readystate poll handle * True when the document is initially usable * Executes the supplied callback when the item with the supplied * id is found. This is meant to be used to execute behavior as * soon as possible as the page loads. If you use this after the * initial page load it will poll for a fixed time for the element. * The number of times it will poll and the frequency are * configurable. By default it will poll for 10 seconds. * <p>The callback is executed with a single parameter: * the custom object parameter, if provided.</p> * @param {string||string[]} id the id of the element, or an array * @param {function} fn what to execute when the element is found. * @param {object} p_obj an optional object to be passed back as * @param {boolean|object} p_override If set to true, fn will execute * in the context of p_obj, if set to an object it * will execute in the context of that object * @param checkContent {boolean} check child node readiness (onContentReady) * @deprecated Use Y.on("available") for (i=
0; i<a.
length; i=i+
1) {
// We want the first test to be immediate, but async // set by the event system for lazy DOM listeners // otherwise try to remove the onAvailable listener(s) for (i =
0; i < a.
length; i++) {
* Works the same way as onAvailable, but additionally checks the * state of sibling elements to determine if the content of the * available element is safe to modify. * <p>The callback is executed with a single parameter: * the custom object parameter, if provided.</p> * @param {string} id the id of the element to look for. * @param {function} fn what to execute when the element is ready. * @param {object} obj an optional object to be passed back as * @param {boolean|object} override If set to true, fn will execute * in the context of p_obj. If an object, fn will * exectute in the context of that object * @deprecated Use Y.on("contentready") * @param {String} type The type of event to append * @param {Function} fn The method the event invokes * @param {String|HTMLElement|Array|NodeList} el An id, an element * reference, or a collection of ids and/or elements to assign the * @param {Object} context optional context object * @param {Boolean|object} args 0..n arguments to pass to the callback * @return {EventHandle} an object to that can be used to detach the listener // for later removeListener calls // window load happens once // throw new TypeError(type + " attach call failed, callback undefined"); // The el argument can be an array of elements or element ids. // return (handles.length === 1) ? handles[0] : handles; // If the el argument is a string, we assume it is // actually the id of the element. If the page is loaded // we convert el to the actual element, otherwise we // defer attaching the event until the element is // oEl = (compat) ? Y.DOM.byId(el) : Y.Selector.query(el); // Not found = defer adding the event until the element is available // Element should be an html element or node // if the load is complete, fire immediately. // all subscribers, including the current one // set context to the Node if not specified // ret = cewrapper.on.apply(cewrapper, trimmedArgs); * Removes an event listener. Supports the signature the event was bound * with, but the preferred way to remove listeners is using the handle * that is returned when using Y.on * @param {String} type the type of event to remove. * @param {Function} fn the method the event invokes. If fn is * undefined, then all event handlers for the type of event are * @param {String|HTMLElement|Array|NodeList|EventHandle} el An * event handle, an id, an element reference, or a collection * of ids and/or elements to remove the listener from. * @return {boolean} true if the unbind was successful, false otherwise. // The el argument can be a string if (
typeof el ==
"string") {
// el = (compat) ? Y.DOM.byId(el) : Y.all(el); // return Event.detach.apply(Event, args); // The el argument can be an array of elements or element ids. * Finds the event in the window object, the caller's arguments, or * in the arguments of another method in the callstack. This is * executed automatically for events registered through the event * manager, so the implementer should not normally need to execute * @param {Event} e the event parameter from the handler * @param {HTMLElement} el the element the listener was attached to * @return {Event} the event * Generates an unique ID for the element if it does not already * @param el the element to create the id for * @return {string} the resulting id of the element * We want to be able to use getElementsByTagName as a collection * to attach a group of events to. Unfortunately, different * browsers return different types of collections. This function * tests to determine if the object is array-like. It will also * fail if the object is an array, but is empty. * @method _isValidCollection * @param o the object to test * @return {boolean} true if the object is array-like and populated * @deprecated was not meant to be used directly * hook up any deferred listeners // Just in case DOMReady did not go off for some reason // Available elements may not have been detected before the // window load event fires. Try to find them now so that the // the user is more likely to get the onAvailable notifications // before the window load notification * Polling function that runs before the onload event fires, * attempting to attach to DOM Nodes as soon as they are // Hold off if DOMReady has not fired and check current // readyState to protect against the IE operation aborted // keep trying until after the page is loaded. We need to // check the page load state prior to trying to bind the // elements so that we can be certain all elements have been // el = (item.compat) ? Y.DOM.byId(item.id) : Y.one(item.id); // el = (item.compat) ? Y.DOM.byId(item.id) : Y.one(item.id); // The element is available, but not necessarily ready // @todo should we test parentNode.nextSibling? // we may need to strip the nulled out items here * Removes all listeners attached to the given element via addListener. * Optionally, the node's children can also be purged. * Optionally, you can specify a specific type of event to remove. * @param {HTMLElement} el the element to purge * @param {boolean} recurse recursively purge this element's children * as well. Use with caution. * @param {string} type optional type of listener to purge. If * left out, all listeners will be removed // var oEl = (Y.Lang.isString(el)) ? Y.one(el) : el, * Removes all object references and the DOM proxy subscription for * a given event for a DOM node. * @param wrapper {CustomEvent} Custom event proxy for the DOM * Returns all listeners attached to the given element via addListener. * Optionally, you can specify a specific type of event to return. * @param el {HTMLElement|string} the element or element id to inspect * @param type {string} optional type of listener to return. If * left out, all listeners will be returned * @return {Y.Custom.Event} the custom event wrapper for the DOM event(s) // look for synthetic events // get native events as well * Removes all listeners registered by pe.event. Called * automatically during the unload event. if (v.
type ==
'unload') {
* Adds a DOM event directly without the caching, cleanup, context adj, etc * @param {HTMLElement} el the element to bind the handler to * @param {string} type the type of event handler * @param {function} fn the callback to invoke * @param {boolen} capture capture or bubble phase * @param {HTMLElement} el the element to bind the handler to * @param {string} type the type of event handler * @param {function} fn the callback to invoke * @param {boolen} capture capture or bubble phase * DOM event listener abstraction layer * Executes the callback as soon as the specified element * is detected in the DOM. This function expects a selector * string for the element(s) to detect. If you already have * an element reference, you don't need this event. * @param type {string} 'available' * @param fn {function} the callback function to execute. * @param el {string} an selector for the element(s) to attach * @param context optional argument that specifies what 'this' refers to. * @param args* 0..n additional arguments to pass on to the callback function. * These arguments will be added after the event object. * @return {EventHandle} the detach handle * Executes the callback as soon as the specified element * is detected in the DOM with a nextSibling property * (indicating that the element's children are available). * This function expects a selector * string for the element(s) to detect. If you already have * an element reference, you don't need this event. * @param type {string} 'contentready' * @param fn {function} the callback function to execute. * @param el {string} an selector for the element(s) to attach. * @param context optional argument that specifies what 'this' refers to. * @param args* 0..n additional arguments to pass on to the callback function. * These arguments will be added after the event object. * @return {EventHandle} the detach handle },
'@VERSION@' ,{
requires:[
'event-custom-base']});
YUI.
add(
'event-delegate',
function(Y) {
* Adds event delegation support to the library. * @submodule event-delegate * <p>Sets up event delegation on a container element. The delegated event * will use a supplied selector or filtering function to test if the event * references at least one node that should trigger the subscription * <p>Selector string filters will trigger the callback if the event originated * from a node that matches it or is contained in a node that matches it. * Function filters are called for each Node up the parent axis to the * subscribing container node, and receive at each level the Node and the event * object. The function should return true (or a truthy value) if that Node * should trigger the subscription callback. Note, it is possible for filters * to match multiple Nodes for a single event. In this case, the delegate * callback will be executed for each matching Node.</p> * <p>For each matching Node, the callback will be executed with its 'this' * object set to the Node matched by the filter (unless a specific context was * provided during subscription), and the provided event's * <code>currentTarget</code> will also be set to the matching Node. The * containing Node from which the subscription was originally made can be * referenced as <code>e.container</code>. * @param type {String} the event type to delegate * @param fn {Function} the callback function to execute. This function * will be provided the event object for the delegated event. * @param el {String|node} the element that is the delegation container * @param spec {string|Function} a selector that must match the target of the * event or a function to test target and its parents for a match * @param context optional argument that specifies what 'this' refers to. * @param args* 0..n additional arguments to pass on to the callback function. * These arguments will be added after the event object. * @return {EventHandle} the detach handle // Support Y.delegate({ click: fnA, key: fnB }, context, filter, ...); // and Y.delegate(['click', 'key'], fn, context, filter, ...); // Y.delegate({'click', fn}, context, filter) => // Y.delegate('click', fn, context, filter) args.
unshift(
null);
// one arg becomes two; need to make space handle = Y.
on(
'available',
function () {
* Overrides the <code>_notify</code> method on the normal DOM subscription to * inject the filtering logic and only proceed in the case of a match. * @method delegate.notifySub * @param thisObj {Object} default 'this' object for the callback * @param args {Array} arguments passed to the event's <code>fire()</code> * @param ce {CustomEvent} the custom event managing the DOM subscriptions for * the subscribed event on the subscribing node. * @return {Boolean} false if the event was stopped // Preserve args for other subscribers // Only notify subs if the event occurred on a targeted element //container = e.currentTarget, // Support multiple matches up the the container subtree // The second arg is the currentTarget, but we'll be reusing this // facade, replacing the currentTarget for each use, so it doesn't // matter what element we seed it with. if (
ret ===
false) {
// stop further notifications * <p>Compiles a selector string into a filter function to identify whether * Nodes along the parent axis of an event's target should trigger event * <p>This function is memoized, so previously compiled filter functions are * returned if the same selector string is provided.</p> * <p>This function may be useful when defining synthetic events for delegate * @method delegate.compileFilter * @param selector {String} the selector string to base the filtration on * Walks up the parent axis of an event's target, and tests each element * against a supplied filter function. If any Nodes, including the container, * satisfy the filter, the delegated callback will be triggered for each. * @method delegate._applyFilter * @param filter {Function} boolean function to test for inclusion in event * @param args {Array} the arguments that would be passed to subscribers * @param ce {CustomEvent} the DOM event wrapper * @return {Node|Node[]|undefined} The Node or Nodes that satisfy the filter container =
ce.
el,
// facadeless events in IE, have no e.currentTarget // Resolve text nodes to their containing element // passing target as the first arg rather than leaving well enough alone // making 'this' in the filter function refer to the target. This is to // support bound filter functions. // filter functions are implementer code and should receive wrappers // filter(target, e, extra args...) - this === target args[
1] = e;
// restore the raw DOM event * Sets up event delegation on a container element. The delegated event * will use a supplied filter to test if the callback should be executed. * This filter can be either a selector string or a function that returns * a Node to use as the currentTarget for the event. * The event object for the delegated event is supplied to the callback * function. It is modified slightly in order to support all properties * that may be needed for event delegation. 'currentTarget' is set to * the element that matched the selector string filter or the Node returned * from the filter function. 'container' is set to the element that the * listener is delegated from (this normally would be the 'currentTarget'). * Filter functions will be called with the arguments that would be passed to * the callback function, including the event object as the first parameter. * The function should return false (or a falsey value) if the success criteria * aren't met, and the Node to use as the event's currentTarget and 'this' * @param type {string} the event type to delegate * @param fn {function} the callback function to execute. This function * will be provided the event object for the delegated event. * @param el {string|node} the element that is the delegation container * @param filter {string|function} a selector that must match the target of the * event or a function that returns a Node or false. * @param context optional argument that specifies what 'this' refers to. * @param args* 0..n additional arguments to pass on to the callback function. * These arguments will be added after the event object. * @return {EventHandle} the detach handle },
'@VERSION@' ,{
requires:[
'node-base']});
YUI.
add(
'event-synthetic',
function(Y) {
* Define new DOM events that can be subscribed to from Nodes. * @submodule event-synthetic * <p>The triggering mechanism used by SyntheticEvents.</p> * <p>Implementers should not instantiate these directly. Use the Notifier * provided to the event's implemented <code>on(node, sub, notifier)</code> or * <code>delegate(node, sub, notifier, filter)</code> methods.</p> * @class SyntheticEvent.Notifier * @param handle {EventHandle} the detach handle for the subscription to an * internal custom event used to execute the callback passed to * @param emitFacade {Boolean} take steps to ensure the first arg received by * the subscription callback is an event facade * <p>Executes the subscription callback, passing the firing arguments as the * first parameters to that callback. For events that are configured with * emitFacade=true, it is common practice to pass the triggering DOMEventFacade * as the first parameter. Barring a proper DOMEventFacade or EventFacade * (from a CustomEvent), a new EventFacade will be generated. In that case, if * fire() is called with a simple object, it will be mixed into the facade. * Otherwise, the facade will be prepended to the callback parameters.</p> * <p>For notifiers provided to delegate logic, the first argument should be an * object with a "currentTarget" property to identify what object to * default as 'this' in the callback. Typically this is gleaned from the * DOMEventFacade or EventFacade, but if configured with emitFacade=false, an * object must be provided. In that case, the object will be removed from the * callback parameters.</p> * <p>Additional arguments passed during event subscription will be * automatically added after those passed to fire().</p> * @param e {EventFacade|DOMEventFacade|Object|any} (see description) * @param arg* {any} additional arguments received by all subscriptions // first arg to delegate notifier should be an object with currentTarget // to capture callbacks that return false to stopPropagation. // Useful for delegate implementations * Manager object for synthetic event subscriptions to aggregate multiple synths on the same node without colliding with actual DOM subscription entries in the global map of DOM subscriptions. Also facilitates proper cleanup on page unload. * @param el {HTMLElement} the DOM element * @param yuid {String} the yuid stamp for the element * @param key {String} the generated id token used to identify an event type + * element in the global DOM subscription map. // A few object properties to fake the CustomEvent interface for page // unload cleanup. DON'T TOUCH! * Adds a subscription from the Notifier registry. * @param handle {EventHandle} the subscription * Removes the subscription from the Notifier registry. * @param sub {Subscription} the subscription // Clean up left over objects when there are no more subscribers. * Used by the event system's unload cleanup process. When navigating * away from the page, the event system iterates the global map of element * subscriptions and detaches everything using detachAll(). Normally, * the map is populated with custom events, so this object needs to * at least support the detachAll method to duck type its way to * <p>Wrapper class for the integration of new events into the YUI event * infrastructure. Don't instantiate this object directly, use * <code>Y.Event.define(type, config)</code>. See that method for details.</p> * <p>Properties that MAY or SHOULD be specified in the configuration are noted * below and in the description of <code>Y.Event.define</code>.</p> * @param cfg {Object} Implementation pieces and configuration * Returns the array of subscription handles for a node for the given event * type. Passing true as the third argument will create a registry entry * in the event system's DOM map to host the array if one doesn't yet exist. * @param node {Node} the node * @param type {String} the event * @param create {Boolean} create a registration entry to host a new array * Alternate <code>_delete()</code> method for the CustomEvent object * created to manage SyntheticEvent subscriptions. * @param sub {Subscription} the subscription to clean up * Construction logic for the event. // The notification mechanism handles facade creation * <p>Implementers MAY provide this method definition.</p> * <p>Implement this function if the event supports a different * subscription signature. This function is used by both * <code>on()</code> and <code>delegate()</code>. The second parameter * indicates that the event is being subscribed via * <code>delegate()</code>.</p> * <p>Implementations must remove extra arguments from the args list * before returning. The required args for <code>on()</code> * <pre><code>[type, callback, target, context, argN...]</code></pre> * <p>The required args for <code>delegate()</code> * <pre><code>[type, callback, target, filter, context, argN...]</code></pre> * <p>The return value from this function will be stored on the * subscription in the '_extra' property for reference elsewhere.</p> * @param args {Array} parmeters passed to Y.on(..) or Y.delegate(..) * @param delegate {Boolean} true if the subscription is from Y.delegate * <p>Implementers MAY override this property.</p> * <p>Whether to prevent multiple subscriptions to this event that are * classified as being the same. By default, this means the subscribed * callback is the same function. See the <code>subMatch</code> * method. Setting this to true will impact performance for high volume * <p>Implementers SHOULD provide this method definition.</p> * Implementation logic for subscriptions done via <code>node.on(type, * fn)</code> or <code>Y.on(type, fn, target)</code>. This * function should set up the monitor(s) that will eventually fire the * event. Typically this involves subscribing to at least one DOM * event. It is recommended to store detach handles from any DOM * subscriptions to make for easy cleanup in the <code>detach</code> * method. Typically these handles are added to the <code>sub</code> * object. Also for SyntheticEvents that leverage a single DOM * subscription under the hood, it is recommended to pass the DOM event * object to <code>notifier.fire(e)</code>. (The event name on the * object will be updated). * @param node {Node} the node the subscription is being applied to * @param sub {Subscription} the object to track this subscription * @param notifier {SyntheticEvent.Notifier} call notifier.fire(..) to * trigger the execution of the subscribers * <p>Implementers SHOULD provide this method definition.</p> * <p>Implementation logic for detaching subscriptions done via * <code>node.on(type, fn)</code>. This function should clean up any * subscriptions made in the <code>on()</code> phase.</p> * @param node {Node} the node the subscription was applied to * @param sub {Subscription} the object tracking this subscription * @param notifier {SyntheticEvent.Notifier} the Notifier used to * trigger the execution of the subscribers * <p>Implementers SHOULD provide this method definition.</p> * <p>Implementation logic for subscriptions done via * <code>node.delegate(type, fn, filter)</code> or * <code>Y.delegate(type, fn, container, filter)</code>. Like with * <code>on()</code> above, this function should monitor the environment * for the event being fired, and trigger subscription execution by * calling <code>notifier.fire(e)</code>.</p> * <p>This function receives a fourth argument, which is the filter * used to identify which Node's are of interest to the subscription. * The filter will be either a boolean function that accepts a target * Node for each hierarchy level as the event bubbles, or a selector * string. To translate selector strings into filter functions, use * <code>Y.delegate.compileFilter(filter)</code>.</p> * @param node {Node} the node the subscription is being applied to * @param sub {Subscription} the object to track this subscription * @param notifier {SyntheticEvent.Notifier} call notifier.fire(..) to * trigger the execution of the subscribers * @param filter {String|Function} Selector string or function that * accepts an event object and returns null, a Node, or an * array of Nodes matching the criteria for processing. * <p>Implementers SHOULD provide this method definition.</p> * <p>Implementation logic for detaching subscriptions done via * <code>node.delegate(type, fn, filter)</code> or * <code>Y.delegate(type, fn, container, filter)</code>. This function * should clean up any subscriptions made in the * <code>delegate()</code> phase.</p> * @param node {Node} the node the subscription was applied to * @param sub {Subscription} the object tracking this subscription * @param notifier {SyntheticEvent.Notifier} the Notifier used to * trigger the execution of the subscribers * @param filter {String|Function} Selector string or function that * accepts an event object and returns null, a Node, or an * array of Nodes matching the criteria for processing. * Sets up the boilerplate for detaching the event and facilitating the * execution of subscriber callbacks. * @param args {Array} array of arguments passed to * <code>Y.on(...)</code> or <code>Y.delegate(...)</code> * @param delegate {Boolean} true if called from * <code>Y.delegate(...)</code> * @return {EventHandle} the detach handle for this subscription // Can't just use Y.all because it doesn't support window (yet?) handle = Y.
on(
'available',
function () {
// (type, fn, el, thisObj, ...) => (fn, thisObj, ...) * Creates a new Notifier object for use by this event's * <code>on(...)</code> or <code>delegate(...)</code> implementation * and register the custom event proxy in the DOM system for cleanup. * @param node {Node} the Node hosting the event * @param method {String} "on" or "delegate" * @param args {Array} the subscription arguments passed to either * <code>Y.on(...)</code> or <code>Y.delegate(...)</code> * after running through <code>processArgs(args)</code> to * normalize the argument signature * @param extra {any} Extra data parsed from * <code>processArgs(args)</code> * @param filter {String|Function} the selector string or function * filter passed to <code>Y.delegate(...)</code> (not * present when called from <code>Y.on(...)</code>) host :
node,
// I forget what this is for // Call the implementation's "on" or "delegate" method * <p>Implementers MAY provide this method definition.</p> * <p>Implement this function if you want extra data extracted during * processArgs to be propagated to subscriptions on a per-node basis. * That is to say, if you call <code>Y.on('xyz', fn, xtra, 'div')</code> * the data returned from processArgs will be shared * across the subscription objects for all the divs. If you want each * subscription to receive unique information, do that processing * <p>The default implementation adds the data extracted by processArgs * to the subscription object as <code>sub._extra</code>.</p> * @param extra {any} Any extra data extracted from processArgs * @param sub {Subscription} the individual subscription * Removes the subscription(s) from the internal subscription dispatch * mechanism. See <code>SyntheticEvent._deleteSub</code>. * @param args {Array} The arguments passed to * <code>node.detach(...)</code> // Can't use Y.all because it doesn't support window (yet?) // TODO: Does Y.all support window now? // (type, fn, el, context, filter?) => (type, fn, context, filter?) * Returns the detach handles of subscriptions on a node that satisfy a * search/filter function. By default, the filter used is the * <code>subMatch</code> method. * @param node {Node} the node hosting the event * @param args {Array} the array of original subscription args passed * to <code>Y.on(...)</code> (before * <code>processArgs</code> * @param filter {Function} function used to identify a subscription * for inclusion in the returned array * @param first {Boolean} stop after the first match (used to check for * duplicate subscriptions) * @return {EventHandle[]} detach handles for the matching subscriptions * <p>Implementers MAY override this to define what constitutes a * "same" subscription. Override implementations should * consider the lack of a comparator as a match, so calling * <code>getSubs()</code> with no arguments will return all subs.</p> * <p>Compares a set of subscription arguments against a Subscription * object to determine if they match. The default implementation * compares the callback function against the second argument passed to * <code>Y.on(...)</code> or <code>node.detach(...)</code> etc.</p> * @param sub {Subscription} the existing subscription * @param args {Array} the calling arguments passed to * <code>Y.on(...)</code> etc. * @return {Boolean} true if the sub can be described by the args // Default detach cares only about the callback matching * <p>Defines a new event in the DOM event system. Implementers are * responsible for monitoring for a scenario whereby the event is fired. A * notifier object is provided to the functions identified below. When the * criteria defining the event are met, call notifier.fire( [args] ); to * execute event subscribers.</p> * <p>The first parameter is the name of the event. The second parameter is a * configuration object which define the behavior of the event system when the * new event is subscribed to or detached from. The methods that should be * defined in this configuration object are <code>on</code>, * <code>detach</code>, <code>delegate</code>, and <code>detachDelegate</code>. * You are free to define any other methods or properties needed to define your * event. Be aware, however, that since the object is used to subclass * SyntheticEvent, you should avoid method names used by SyntheticEvent unless * your intention is to override the default behavior.</p> * <p>This is a list of properties and methods that you can or should specify * in the configuration object:</p> * <dt><code>on</code></dt> * <dd><code>function (node, subscription, notifier)</code> The * implementation logic for subscription. Any special setup you need to * do to create the environment for the event being fired--E.g. native * DOM event subscriptions. Store subscription related objects and * state on the <code>subscription</code> object. When the * criteria have been met to fire the synthetic event, call * <code>notifier.fire(e)</code>. See Notifier's <code>fire()</code> * method for details about what to pass as parameters.</dd> * <dt><code>detach</code></dt> * <dd><code>function (node, subscription, notifier)</code> The * implementation logic for cleaning up a detached subscription. E.g. * detach any DOM subscriptions added in <code>on</code>.</dd> * <dt><code>delegate</code></dt> * <dd><code>function (node, subscription, notifier, filter)</code> The * implementation logic for subscription via <code>Y.delegate</code> or * <code>node.delegate</code>. The filter is typically either a selector * string or a function. You can use * <code>Y.delegate.compileFilter(selectorString)</code> to create a * filter function from a selector string if needed. The filter function * expects an event object as input and should output either null, a * matching Node, or an array of matching Nodes. Otherwise, this acts * like <code>on</code> DOM event subscriptions. Store subscription * related objects and information on the <code>subscription</code> * object. When the criteria have been met to fire the synthetic event, * call <code>notifier.fire(e)</code> as noted above.</dd> * <dt><code>detachDelegate</code></dt> * <dd><code>function (node, subscription, notifier)</code> The * implementation logic for cleaning up a detached delegate subscription. * E.g. detach any DOM delegate subscriptions added in * <code>delegate</code>.</dd> * <dt><code>publishConfig</code></dt> * <dd>(Object) The configuration object that will be used to instantiate * the underlying CustomEvent. See Notifier's <code>fire</code> method * <dt><code>processArgs</code></dt * <p><code>function (argArray, fromDelegate)</code> Optional method * to extract any additional arguments from the subscription * signature. Using this allows <code>on</code> or * <code>delegate</code> signatures like * <code>node.on("hover", overCallback, * outCallback)</code>.</p> * <p>When processing an atypical argument signature, make sure the * args array is returned to the normal signature before returning * from the function. For example, in the "hover" example * above, the <code>outCallback</code> needs to be <code>splice</code>d * out of the array. The expected signature of the args array for * <code>on()</code> subscriptions is:</p> * <code>[type, callback, target, contextOverride, argN...]</code> * <p>And for <code>delegate()</code>:</p> * <code>[type, callback, target, filter, contextOverride, argN...]</code> * <p>where <code>target</code> is the node the event is being * subscribed for. You can see these signatures documented for * <code>Y.on()</code> and <code>Y.delegate()</code> respectively.</p> * <p>Whatever gets returned from the function will be stored on the * <code>subscription</code> object under * <code>subscription._extra</code>.</p></dd> * <dt><code>subMatch</code></dt> * <p><code>function (sub, args)</code> Compares a set of * subscription arguments against a Subscription object to determine * if they match. The default implementation compares the callback * function against the second argument passed to * <code>Y.on(...)</code> or <code>node.detach(...)</code> etc.</p> * @param type {String} the name of the event * @param config {Object} the prototype definition for the new event (see above) * @param force {Boolean} override an existing event (use with caution) * @return {SyntheticEvent} the subclass implementation instance created to * handle event subscriptions of this type },
'@VERSION@' ,{
requires:[
'node-base',
'event-custom']});
YUI.
add(
'event-mousewheel',
function(Y) {
* Adds mousewheel event support * @submodule event-mousewheel * Mousewheel event. This listener is automatically attached to the * correct target, so one should not be supplied. Mouse wheel * direction and velocity is stored in the 'mouseDelta' field. * @param type {string} 'mousewheel' * @param fn {function} the callback to execute * @param context optional context object * @param args 0..n additional arguments to provide to the listener. * @return {EventHandle} the detach handle },
'@VERSION@' ,{
requires:[
'node-base']});
YUI.
add(
'event-mouseenter',
function(Y) {
* <p>Adds subscription and delegation support for mouseenter and mouseleave * events. Unlike mouseover and mouseout, these events aren't fired from child * elements of a subscribed node.</p> * <p>This avoids receiving three mouseover notifications from a setup like</p> * <pre><code>div#container > p > a[href]</code></pre> * <pre><code>Y.one('#container').on('mouseover', callback)</code></pre> * <p>When the mouse moves over the link, one mouseover event is fired from * #container, then when the mouse moves over the p, another mouseover event is * fired and bubbles to #container, causing a second notification, and finally * when the mouse moves over the link, a third mouseover event is fired and * bubbles to #container for a third notification.</p> * <p>By contrast, using mouseenter instead of mouseover, the callback would be * executed only once when the mouse moves over #container.</p> * @submodule event-mouseenter // node.on(this.proxyType, notify, null, notifier); // TODO: where is notifier? args? this.notifier? },
'@VERSION@' ,{
requires:[
'event-synthetic']});
YUI.
add(
'event-key',
function(Y) {
* Functionality to listen for one or more specific key combinations. // Y.delegate('key', fn, spec, '#container', '.filter') // comes in as ['key', fn, spec, '#container', '.filter'], but // node.delegate('key', fn, spec, '.filter') // comes in as ['key', fn, containerEl, spec, '.filter'] // FIXME: need to support '65,esc' => keypress, keydown // non-numerics are single characters or key names // FIXME: '65,enter' defaults to keydown for both // FIXME: possibly stupid assumption that // the keycode of the lower case == the // charcode of the upper case // a (key:65,char:97), A (key:65,char:65) // upper case chars get +shift free // Pass through to a plain old key(up|down|press) // Note: this is horribly inefficient, but I can't abort this // subscription for a simple Y.on('keypress', ...); * <p>Add a key listener. The listener will only be notified if the * keystroke detected meets the supplied specification. The * specification is a string that is defined as:</p> * <dd><code>[{type}:]{code}[,{code}]*</dd> * <dd><code>"down", "up", or "press"</code></dd> * <dd><code>{keyCode|character|keyName}[+{modifier}]*</code></dd> * <dd><code>"shift", "ctrl", "alt", or "meta"</code></dd> * <dd><code>"enter", "backspace", "esc", "tab", "pageup", or "pagedown"</code></dd> * <li><code>Y.on("key", callback, "press:12,65+shift+ctrl", "#my-input");</code></li> * <li><code>Y.delegate("key", preventSubmit, "enter", "#forms", "input[type=text]");</code></li> * <li><code>Y.one("doc").on("key", viNav, "j,k,l,;");</code></li> * @param type {string} 'key' * @param fn {function} the function to execute * @param id {string|HTMLElement|collection} the element(s) to bind * @param spec {string} the keyCode and modifier specification * @param o optional context object * @param args 0..n additional arguments to provide to the listener. * @return {Event.Handle} the detach handle },
'@VERSION@' ,{
requires:[
'event-synthetic']});
YUI.
add(
'event-focus',
function(Y) {
* Adds bubbling and delegation support to DOM events focus and blur. // Maintain a list to handle subscriptions from nested // containers div#a>div#b>input #a.on(focus..) #b.on(focus..), // use one focus or blur subscription that fires notifiers from // #b then #a to emulate bubble sequence. // only subscribe to the element's focus if the target is // not the current target ( // document.get('ownerDocument') returns null // Walk up the parent axis until the origin node, // clear the notifications list (mainly for delegation) // For IE, we need to defer to focusin rather than focus because // `el.focus(); doSomething();` executes el.onbeforeactivate, el.onactivate, // el.onfocusin, doSomething, then el.onfocus. All others support capture // phase focus, which executes before doSomething. To guarantee consistent // behavior for this use case, IE's direct subscriptions are made against // focusin so subscribers will be notified before js following el.focus() is // name capture phase direct subscription define(
"focus",
"beforeactivate",
"focusin");
define(
"blur",
"beforedeactivate",
"focusout");
define(
"focus",
"focus",
"focus");
define(
"blur",
"blur",
"blur");
},
'@VERSION@' ,{
requires:[
'event-synthetic']});
YUI.
add(
'event-resize',
function(Y) {
* Adds a window resize event that has its behavior normalized to fire at the * end of the resize rather than constantly during the resize. * @submodule event-resize * Firefox fires the window resize event once when the resize action * finishes, other browsers fire the event periodically during the * resize. This code uses timeout logic to simulate the Firefox * behavior in other browsers. // check for single window listener and add if needed },
'@VERSION@' ,{
requires:[
'node-base']});
YUI.
add(
'event-hover',
function(Y) {
* Adds support for a "hover" event. The event provides a convenience wrapper * for subscribing separately to mouseenter and mouseleave. The signature for * subscribing to the event is</p> * <pre><code>node.on("hover", overFn, outFn); * node.delegate("hover", overFn, outFn, ".filterSelector"); * Y.on("hover", overFn, outFn, ".targetSelector"); * Y.delegate("hover", overFn, outFn, "#container", ".filterSelector"); * <p>Additionally, for compatibility with a more typical subscription * signature, the following are also supported:</p> * <pre><code>Y.on("hover", overFn, ".targetSelector", outFn); * Y.delegate("hover", overFn, "#container", outFn, ".filterSelector"); // Y.delegate('hover', over, out, '#container', '.filter') // comes in as ['hover', over, out, '#container', '.filter'], but // node.delegate('hover', over, out, '.filter') // comes in as ['hover', over, containerEl, out, '.filter'] },
'@VERSION@' ,{
requires:[
'event-mouseenter']});
YUI.
add(
'event',
function(Y){},
'@VERSION@' ,{
use:[
'event-base',
'event-delegate',
'event-synthetic',
'event-mousewheel',
'event-mouseenter',
'event-key',
'event-focus',
'event-resize',
'event-hover']});