Skip to content

Instantly share code, notes, and snippets.

@ArjunVachhani
Last active April 7, 2016 08:55
Show Gist options
  • Save ArjunVachhani/96898ef09a869383c87b0b5612aa1de7 to your computer and use it in GitHub Desktop.
Save ArjunVachhani/96898ef09a869383c87b0b5612aa1de7 to your computer and use it in GitHub Desktop.
(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)
@NikhilPrajapati
Copy link

Superb 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment