|
1 YUI.add('event-hover', function (Y, NAME) { |
|
2 |
|
3 /** |
|
4 * Adds support for a "hover" event. The event provides a convenience wrapper |
|
5 * for subscribing separately to mouseenter and mouseleave. The signature for |
|
6 * subscribing to the event is</p> |
|
7 * |
|
8 * <pre><code>node.on("hover", overFn, outFn); |
|
9 * node.delegate("hover", overFn, outFn, ".filterSelector"); |
|
10 * Y.on("hover", overFn, outFn, ".targetSelector"); |
|
11 * Y.delegate("hover", overFn, outFn, "#container", ".filterSelector"); |
|
12 * </code></pre> |
|
13 * |
|
14 * <p>Additionally, for compatibility with a more typical subscription |
|
15 * signature, the following are also supported:</p> |
|
16 * |
|
17 * <pre><code>Y.on("hover", overFn, ".targetSelector", outFn); |
|
18 * Y.delegate("hover", overFn, "#container", outFn, ".filterSelector"); |
|
19 * </code></pre> |
|
20 * |
|
21 * @module event |
|
22 * @submodule event-hover |
|
23 */ |
|
24 var isFunction = Y.Lang.isFunction, |
|
25 noop = function () {}, |
|
26 conf = { |
|
27 processArgs: function (args) { |
|
28 // Y.delegate('hover', over, out, '#container', '.filter') |
|
29 // comes in as ['hover', over, out, '#container', '.filter'], but |
|
30 // node.delegate('hover', over, out, '.filter') |
|
31 // comes in as ['hover', over, containerEl, out, '.filter'] |
|
32 var i = isFunction(args[2]) ? 2 : 3; |
|
33 |
|
34 return (isFunction(args[i])) ? args.splice(i,1)[0] : noop; |
|
35 }, |
|
36 |
|
37 on: function (node, sub, notifier, filter) { |
|
38 var args = (sub.args) ? sub.args.slice() : []; |
|
39 |
|
40 args.unshift(null); |
|
41 |
|
42 sub._detach = node[(filter) ? "delegate" : "on"]({ |
|
43 mouseenter: function (e) { |
|
44 e.phase = 'over'; |
|
45 notifier.fire(e); |
|
46 }, |
|
47 mouseleave: function (e) { |
|
48 var thisObj = sub.context || this; |
|
49 |
|
50 args[0] = e; |
|
51 |
|
52 e.type = 'hover'; |
|
53 e.phase = 'out'; |
|
54 sub._extra.apply(thisObj, args); |
|
55 } |
|
56 }, filter); |
|
57 }, |
|
58 |
|
59 detach: function (node, sub, notifier) { |
|
60 sub._detach.detach(); |
|
61 } |
|
62 }; |
|
63 |
|
64 conf.delegate = conf.on; |
|
65 conf.detachDelegate = conf.detach; |
|
66 |
|
67 Y.Event.define("hover", conf); |
|
68 |
|
69 |
|
70 }, '@VERSION@', {"requires": ["event-mouseenter"]}); |