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