From 8fcb2ea41210860ad27d3e0cff191a0b970400b6 Mon Sep 17 00:00:00 2001 From: BlackSheep Date: Thu, 8 Oct 2015 14:37:51 +0200 Subject: [PATCH] Update jquery.switchButton.js When added a callback, in options with ajax request. The ajax for on_callback and off_callback was executed on switch init. After my fix switch inits ok :) and callback are not executed until truely changed the state. --- jquery.switchButton.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/jquery.switchButton.js b/jquery.switchButton.js index d7f49ed..9fdac55 100755 --- a/jquery.switchButton.js +++ b/jquery.switchButton.js @@ -105,7 +105,7 @@ // This will animate all checked switches to the ON position when // loading... this is intentional! this.options.checked = !this.options.checked; - this._toggleSwitch(); + this._toggleSwitch(true); }, _refresh: function() { @@ -246,7 +246,7 @@ this._toggleSwitch(); }, - _toggleSwitch: function() { + _toggleSwitch: function(param) { this.options.checked = !this.options.checked; var newLeft = ""; if (this.options.checked) { @@ -270,7 +270,9 @@ } this.button_bg.addClass("checked"); //execute on state callback if its supplied - if(typeof this.options.on_callback === 'function') this.options.on_callback.call(this); + if(typeof(param) == "undefined") { + if (typeof this.options.on_callback === 'function') this.options.on_callback.call(this); + } } else { // Update the underlying checkbox state @@ -291,7 +293,9 @@ } this.button_bg.removeClass("checked"); //execute off state callback if its supplied - if(typeof this.options.off_callback === 'function') this.options.off_callback.call(this); + if(typeof(param) == "undefined") { + if (typeof this.options.off_callback === 'function') this.options.off_callback.call(this); + } } // Animate the switch this.button.animate({ left: newLeft }, 250, "easeInOutCubic");