2 Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.net/yui/license.txt
8 YUI.add('event-focus', function(Y) {
11 * Adds focus and blur event listener support. These events normally
12 * do not bubble, so this adds support for that so these events
13 * can be used in event delegation scenarios.
16 * @submodule event-focus
22 plugins = Y.Env.evt.plugins,
24 bUseMutation = (UA.opera || UA.webkit),
26 focus: (ie ? 'focusin' : (bUseMutation ? 'DOMFocusIn' : 'focus')),
27 blur: (ie ? 'focusout' : (bUseMutation ? 'DOMFocusOut' : 'blur'))
30 // Only need to use capture phase for Gecko since it doesn't support
31 // focusin, focusout, DOMFocusIn, or DOMFocusOut
32 CAPTURE_CONFIG = { capture: (UA.gecko ? true : false) },
35 attach = function (args, config) {
37 var a = Y.Array(args, 0, true);
38 a[0] = eventNames[a[0]];
39 return Event._attach(a, config);
46 return attach(arguments, CAPTURE_CONFIG);
52 Event._attachFocus = attach;
53 Event._attachBlur = attach;
56 * Adds a DOM focus listener. Uses the focusin event in IE,
57 * DOMFocusIn for Opera and Webkit, and the capture phase for Gecko so that
58 * the event propagates in a way that enables event delegation.
62 * @param type {string} 'focus'
63 * @param fn {function} the callback function to execute
64 * @param o {string|HTMLElement|collection} the element(s) to bind
65 * @param context optional context object
66 * @param args 0..n additional arguments to provide to the listener.
67 * @return {EventHandle} the detach handle
69 plugins.focus = eventAdapter;
72 * Adds a DOM blur listener. Uses the focusout event in IE,
73 * DOMFocusOut for Opera and Webkit, and the capture phase for Gecko so that
74 * the event propagates in a way that enables event delegation.
78 * @param type {string} 'blur'
79 * @param fn {function} the callback function to execute
80 * @param o {string|HTMLElement|collection} the element(s) to bind
81 * @param context optional context object
82 * @param args 0..n additional arguments to provide to the listener.
83 * @return {EventHandle} the detach handle
85 plugins.blur = eventAdapter;
90 }, '3.0.0' ,{requires:['node-base']});