Skip to content

Instantly share code, notes, and snippets.

@alexander-torosh
Created May 25, 2015 13:29
Show Gist options
  • Select an option

  • Save alexander-torosh/f0d64cd2f519af57067e to your computer and use it in GitHub Desktop.

Select an option

Save alexander-torosh/f0d64cd2f519af57067e to your computer and use it in GitHub Desktop.
/**
* $.hoverDelayed()
*/
(function($) {
'use strict';
// Оригінал
var oldHover = $.fn.hover,
// Заміна
newHover = function(handlerIn, handlerOut, delay) {
return this.each(function() {
var timeout,
handler = function(el, fn, e) {
if (timeout) {
timeout = window.clearTimeout(timeout);
} else {
timeout = window.setTimeout(function() {
timeout = undefined;
fn.call(el, e);
}, delay);
}
};
$(this).on('mouseenter mouseleave', function(e) {
handler(this, e.type === 'mouseenter' ? handlerIn : handlerOut, e);
});
});
};
// $.hoverDelayed()
$.fn.hoverDelayed = function() {
var args = Array.prototype.slice.call(arguments);
if (args.length === 3 && typeof args[2] === 'number') {
return newHover.apply(this, args);
} else if (args.length === 2 && typeof args[1] === 'number') {
return newHover.call(this, args[0], args[0], args[1]);
}
return oldHover.apply(this, args);
};
})(window.jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment