Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions jquery.switchButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,17 @@
this._toggleSwitch();
},

_toggleSwitch: function() {
_toggleSwitch: function(skipChangeEvent) {
this.options.checked = !this.options.checked;
var newLeft = "";
if (this.options.checked) {
// Update the underlying checkbox state
this.element.prop("checked", true);
this.element.change();

// Trigger change event unless toggle is silent
if (!skipChangeEvent == true) {
this.element.change();
}

var dLeft = this.options.width - this.options.button_width;
newLeft = "+=" + dLeft;
Expand All @@ -275,7 +279,11 @@
else {
// Update the underlying checkbox state
this.element.prop("checked", false);
this.element.change();

// Trigger change event unless toggle is silent
if (!skipChangeEvent == true) {
this.element.change();
}
newLeft = "-1px";

// Update labels states
Expand All @@ -295,8 +303,18 @@
}
// Animate the switch
this.button.animate({ left: newLeft }, 250, "easeInOutCubic");
},
silentToggle: function() {
this._toggleSwitch(true);
},
toggle: function() {
this._toggleSwitch(false);
},
redraw: function() {
if (!this.element.prop("checked") == this.button_bg.hasClass("checked")) {
this._toggleSwitch(true);
}
}

});

})(jQuery);