Created
June 30, 2013 14:08
-
-
Save Neolot/5895259 to your computer and use it in GitHub Desktop.
JQUERY Depcecated toggle function
This file contains 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
jQuery.fn.extend({ | |
toggle: function( fn ) { | |
// Save reference to arguments for access in closure | |
var args = arguments, | |
guid = fn.guid || jQuery.guid++, | |
i = 0, | |
toggler = function( event ) { | |
// Figure out which function to execute | |
var lastToggle = ( jQuery.data( this, "lastToggle" + fn.guid ) || 0 ) % i; | |
jQuery.data( this, "lastToggle" + fn.guid, lastToggle + 1 ); | |
// Make sure that clicks stop | |
event.preventDefault(); | |
// and execute the function | |
return args[ lastToggle ].apply( this, arguments ) || false; | |
}; | |
// link all the functions, so any of them can unbind this click handler | |
toggler.guid = guid; | |
while ( i < args.length ) { | |
args[ i++ ].guid = guid; | |
} | |
return this.click( toggler ); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment