3
Copyright 2012 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('event-hover', function(Y) {
10
* Adds support for a "hover" event. The event provides a convenience wrapper
11
* for subscribing separately to mouseenter and mouseleave. The signature for
12
* subscribing to the event is</p>
14
* <pre><code>node.on("hover", overFn, outFn);
15
* node.delegate("hover", overFn, outFn, ".filterSelector");
16
* Y.on("hover", overFn, outFn, ".targetSelector");
17
* Y.delegate("hover", overFn, outFn, "#container", ".filterSelector");
20
* <p>Additionally, for compatibility with a more typical subscription
21
* signature, the following are also supported:</p>
23
* <pre><code>Y.on("hover", overFn, ".targetSelector", outFn);
24
* Y.delegate("hover", overFn, "#container", outFn, ".filterSelector");
28
* @submodule event-hover
30
var isFunction = Y.Lang.isFunction,
31
noop = function () {},
33
processArgs: function (args) {
34
// Y.delegate('hover', over, out, '#container', '.filter')
35
// comes in as ['hover', over, out, '#container', '.filter'], but
36
// node.delegate('hover', over, out, '.filter')
37
// comes in as ['hover', over, containerEl, out, '.filter']
38
var i = isFunction(args[2]) ? 2 : 3;
40
return (isFunction(args[i])) ? args.splice(i,1)[0] : noop;
43
on: function (node, sub, notifier, filter) {
44
var args = (sub.args) ? sub.args.slice() : [];
48
sub._detach = node[(filter) ? "delegate" : "on"]({
49
mouseenter: function (e) {
53
mouseleave: function (e) {
54
var thisObj = sub.context || this;
60
sub._extra.apply(thisObj, args);
65
detach: function (node, sub, notifier) {
70
conf.delegate = conf.on;
71
conf.detachDelegate = conf.detach;
73
Y.Event.define("hover", conf);
76
}, '3.5.1' ,{requires:['event-mouseenter']});