Skip to content

Instantly share code, notes, and snippets.

@matthewmorrone
Last active August 29, 2015 14:10
Show Gist options
  • Save matthewmorrone/1eb7d7ab31f86cbae404 to your computer and use it in GitHub Desktop.
Save matthewmorrone/1eb7d7ab31f86cbae404 to your computer and use it in GitHub Desktop.
All my friends are deprecated =[
$.fn.extend({
toggle: function (fn) {
var args = arguments,
guid = fn.guid || $.guid++,
i = 0,
toggler = function (event) {
var lastToggle = ($._data(this, "lastToggle" + fn.guid) || 0) % i;
$._data(this, "lastToggle" + fn.guid, lastToggle + 1);
event.preventDefault();
return args[lastToggle].apply(this, arguments) || false;
};
toggler.guid = guid;
while (i < args.length) {
args[i++].guid = guid;
}
return this.click(toggler);
},
dbltoggle: function (fn) {
var args = arguments,
guid = fn.guid || $.guid++,
i = 0,
dblToggler = function (event) {
var lastDblToggle = ($._data(this, "lastDblToggle" + fn.guid) || 0) % i;
$._data(this, "lastDblToggle" + fn.guid, lastDblToggle + 1);
event.preventDefault();
return args[lastDblToggle].apply(this, arguments) || false;
};
dblToggler.guid = guid;
while (i < args.length) {
args[i++].guid = guid;
}
return this.dblclick(dblToggler);
},
hover: function (fnOver, fnOut) {
return this.mouseenter(fnOver).mouseleave(fnOut || fnOver);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment