Created
May 25, 2015 13:29
-
-
Save alexander-torosh/f0d64cd2f519af57067e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * $.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