hover.js revision 15ddc967c5d429ed2983719db23b453794ab0338
a3b15d60042c81a524cebb94370e5a234a19d04bLuke Smith/**
a3b15d60042c81a524cebb94370e5a234a19d04bLuke Smith * Adds support for a "hover" event. The event provides a convenience wrapper
a3b15d60042c81a524cebb94370e5a234a19d04bLuke Smith * for subscribing separately to mouseenter and mouseleave. The signature for
a3b15d60042c81a524cebb94370e5a234a19d04bLuke Smith * subscribing to the event is</p>
a3b15d60042c81a524cebb94370e5a234a19d04bLuke Smith *
a3b15d60042c81a524cebb94370e5a234a19d04bLuke Smith * <pre><code>node.on("hover", overFn, outFn);
a3b15d60042c81a524cebb94370e5a234a19d04bLuke Smith * node.delegate("hover", overFn, outFn, ".filterSelector");
a3b15d60042c81a524cebb94370e5a234a19d04bLuke Smith * Y.on("hover", overFn, outFn, ".targetSelector");
a3b15d60042c81a524cebb94370e5a234a19d04bLuke Smith * Y.delegate("hover", overFn, outFn, "#container", ".filterSelector");
* </code></pre>
*
* <p>Additionally, for compatibility with a more typical subscription
* signature, the following are also supported:</p>
*
* <pre><code>Y.on("hover", overFn, ".targetSelector", outFn);
* Y.delegate("hover", overFn, "#container", outFn, ".filterSelector");
* </code></pre>
*
* @module event
* @submodule event-hover
*/
var isFunction = Y.Lang.isFunction,
noop = function () {},
conf = {
processArgs: function (args) {
// Y.delegate('hover', over, out, '#container', '.filter')
// comes in as ['hover', over, out, '#container', '.filter'], but
// node.delegate('hover', over, out, '.filter')
// comes in as ['hover', over, containerEl, out, '.filter']
var i = isFunction(args[2]) ? 2 : 3;
return (isFunction(args[i])) ? args.splice(i,1)[0] : noop;
},
on: function (node, sub, notifier, filter) {
var args = (sub.args) ? sub.args.slice() : [];
args.unshift(null);
sub._detach = node[(filter) ? "delegate" : "on"]({
mouseenter: function (e) {
e.phase = 'over';
notifier.fire(e);
},
mouseleave: function (e) {
var thisObj = sub.context || this;
args[0] = e;
e.type = 'hover';
e.phase = 'out';
sub._extra.apply(thisObj, args);
}
}, filter);
},
detach: function (node, sub, notifier) {
sub._detach.detach();
}
};
conf.delegate = conf.on;
conf.detachDelegate = conf.detach;
Y.Event.define("hover", conf);