|
0
|
1 |
/* |
|
|
2 |
Copyright (c) 2009, Yahoo! Inc. All rights reserved. |
|
|
3 |
Code licensed under the BSD License: |
|
|
4 |
http://developer.yahoo.net/yui/license.txt |
|
|
5 |
version: 3.0.0 |
|
|
6 |
build: 1549 |
|
|
7 |
*/ |
|
|
8 |
YUI.add('event-focus', function(Y) { |
|
|
9 |
|
|
|
10 |
/** |
|
|
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. |
|
|
14 |
* |
|
|
15 |
* @module event |
|
|
16 |
* @submodule event-focus |
|
|
17 |
*/ |
|
|
18 |
(function() { |
|
|
19 |
|
|
|
20 |
var UA = Y.UA, |
|
|
21 |
Event = Y.Event, |
|
|
22 |
plugins = Y.Env.evt.plugins, |
|
|
23 |
ie = UA.ie, |
|
|
24 |
bUseMutation = (UA.opera || UA.webkit), |
|
|
25 |
eventNames = { |
|
|
26 |
focus: (ie ? 'focusin' : (bUseMutation ? 'DOMFocusIn' : 'focus')), |
|
|
27 |
blur: (ie ? 'focusout' : (bUseMutation ? 'DOMFocusOut' : 'blur')) |
|
|
28 |
}, |
|
|
29 |
|
|
|
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) }, |
|
|
33 |
|
|
|
34 |
|
|
|
35 |
attach = function (args, config) { |
|
|
36 |
|
|
|
37 |
var a = Y.Array(args, 0, true); |
|
|
38 |
a[0] = eventNames[a[0]]; |
|
|
39 |
return Event._attach(a, config); |
|
|
40 |
|
|
|
41 |
}, |
|
|
42 |
|
|
|
43 |
eventAdapter = { |
|
|
44 |
|
|
|
45 |
on: function () { |
|
|
46 |
return attach(arguments, CAPTURE_CONFIG); |
|
|
47 |
} |
|
|
48 |
|
|
|
49 |
}; |
|
|
50 |
|
|
|
51 |
|
|
|
52 |
Event._attachFocus = attach; |
|
|
53 |
Event._attachBlur = attach; |
|
|
54 |
|
|
|
55 |
/** |
|
|
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. |
|
|
59 |
* |
|
|
60 |
* @for YUI |
|
|
61 |
* @event focus |
|
|
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 |
|
|
68 |
*/ |
|
|
69 |
plugins.focus = eventAdapter; |
|
|
70 |
|
|
|
71 |
/** |
|
|
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. |
|
|
75 |
* |
|
|
76 |
* @for YUI |
|
|
77 |
* @event blur |
|
|
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 |
|
|
84 |
*/ |
|
|
85 |
plugins.blur = eventAdapter; |
|
|
86 |
|
|
|
87 |
})(); |
|
|
88 |
|
|
|
89 |
|
|
|
90 |
}, '3.0.0' ,{requires:['node-base']}); |