Created
November 21, 2013 21:10
-
-
Save Canx/7589680 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
(function ($) { | |
$.fn.extend({ | |
enable: function (func) { | |
if (func == undefined) { | |
$(this).css("opacity", "1"); | |
} else { | |
func(); | |
} | |
restoreEvents($(this)); | |
function restoreEvents(obj) { | |
if (obj.data("listEvents") == undefined) return; | |
var objThis = obj; | |
var events = obj.data("listEvents"); | |
$.each(events, function (i, item) { | |
objThis.on(item.event, null, null, item.func); | |
}); | |
} | |
} | |
, disable: function (func) { | |
var objThis = $(this); | |
if (func == undefined) { | |
$(this).css("opacity", "0.3"); | |
} else { | |
func(); | |
} | |
storeEvents(objThis); | |
var events = objThis.data("listEvents"); | |
if (events == undefined) return; | |
$.each(events, function (i, item) { | |
objThis.off(item.event); | |
}); | |
function storeEvents(obj) { | |
if (obj.data("events") == null) { return; } | |
var list = []; | |
$.each(obj.data("events"), function (i, event) { | |
$.each(event, function (j, h) { | |
list.push({ event: h.type, func: h.handler }); | |
}); | |
}); | |
obj.data("listEvents", list); | |
} | |
} | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment