2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
8 YUI.add('event-hover', function(Y) {
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>
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");
21 * <p>Additionally, for compatibility with a more typical subscription
22 * signature, the following are also supported:</p>
24 * <pre><code>Y.on("hover", overFn, ".targetSelector", outFn);
25 * Y.delegate("hover", overFn, "#container", outFn, ".filterSelector");
29 * @submodule event-hover
31 var isFunction = Y.Lang.isFunction,
32 noop = function () {},
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;
41 return (isFunction(args[i])) ? args.splice(i,1)[0] : noop;
44 on: function (node, sub, notifier, filter) {
45 sub._detach = node[(filter) ? "delegate" : "on"]({
46 mouseenter: Y.bind(notifier.fire, notifier),
47 mouseleave: sub._extra
51 detach: function (node, sub, notifier) {
52 sub._detacher.detach();
56 conf.delegate = conf.on;
57 conf.detachDelegate = conf.detach;
59 Y.Event.define("hover", conf);
62 }, '3.3.0' ,{requires:['event-mouseenter']});