Skip to content

Instantly share code, notes, and snippets.

@smailliwcs
Created September 22, 2020 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smailliwcs/2407fa7600fa95a0fb61b857eea15073 to your computer and use it in GitHub Desktop.
Save smailliwcs/2407fa7600fa95a0fb61b857eea15073 to your computer and use it in GitHub Desktop.
jQuery UI widget: toggler
$.widget("scw.toggler", {
options: {
active: true,
animated: true,
duration: "_default",
cssClass: "toggler-active"
},
_finish: function () {
while (this.element.queue().length > 0) {
this.element.dequeue();
}
this.element.finish(false);
this.element.finish();
},
_refresh: function (immediate) {
this._finish();
var args = [
this.options.cssClass,
Boolean(this.options.active)
];
if (!immediate) {
args.push({
duration: this.options.duration
});
}
$.fn.toggleClass.apply(this.element, args);
},
_create: function () {
this._refresh(true);
},
_setOption: function (key, value) {
this._super(key, value);
if (key === "active") {
this._refresh(!this.options.animated);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment