Last active
April 7, 2016 08:55
-
-
Save ArjunVachhani/96898ef09a869383c87b0b5612aa1de7 to your computer and use it in GitHub Desktop.
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
(function ($) { | |
$.fn.switchery = function (option) { | |
$(this).each(function () { | |
if (typeof option === "string") { | |
var switchery = $(this).data("jquery.switchery"); | |
if (switchery) { | |
if (option.toLowerCase() == "check") { | |
if (!switchery.isChecked()) { | |
$(switchery.switcher).click() | |
} | |
} | |
else if (option.toLowerCase() == "uncheck") { | |
if (switchery.isChecked()) { | |
$(switchery.switcher).click() | |
} | |
} | |
else if (option.toLowerCase() == "disable") { | |
if (!switchery.isDisabled()) | |
switchery.disable(); | |
} | |
else if (option.toLowerCase() == "enable") { | |
if (switchery.isDisabled()) | |
switchery.enable(); | |
} | |
else if (option.toLowerCase() == "destroy") { | |
switchery.destroy(); | |
$(switchery.switcher).remove(); | |
$(this).show(); | |
$(this).removeData("jquery.switchery") | |
$(this).removeAttr("data-switchery") | |
} | |
} | |
} | |
else { | |
if ($(this).attr("data-switchery") != "true") { | |
var switchery = new Switchery(this, option); | |
$(this).data("jquery.switchery", switchery); | |
} | |
} | |
}); | |
return this; | |
}; | |
})(jQuery) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Superb 👍