From cc00dc941a404ce932112c59a9596cca4f5a29ab Mon Sep 17 00:00:00 2001 From: Ed Lomonaco Date: Mon, 6 Feb 2017 13:14:03 -0500 Subject: [PATCH] Fixed a bug that affects FireFox users [Issue #1] --- dist/jquery.btnswitch.min.js | 2 +- jquery.btnswitch.js | 8 ++++---- package.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dist/jquery.btnswitch.min.js b/dist/jquery.btnswitch.min.js index 2cc9bfd..013c093 100644 --- a/dist/jquery.btnswitch.min.js +++ b/dist/jquery.btnswitch.min.js @@ -1 +1 @@ -if("undefined"==typeof jQuery)throw alert("jQuery Switch Button requires jQuery"),new Error("jQuery Switch Button requires jQuery");if(jQuery.fn.jquery<"2.0")throw alert("Incompatible version of jQuery detected, please upgrade to at least 2.0"),new Error("Incompatible version of jQuery detected, please upgrade to at least 2.0");!function(t){t.fn.btnSwitch=function(a){var e=function(a,e){e==n.OnValue?(t('button[data-toggle="'+a+'"][data-title="'+n.OnValue+'"]').removeClass("button-default").addClass("button-on"),t('button[data-toggle="'+a+'"][data-title="'+n.OffValue+'"]').removeClass("button-off").addClass("button-default"),t.isFunction(n.OnCallback)&&n.OnCallback(e)):(t('button[data-toggle="'+a+'"][data-title="'+n.OnValue+'"]').removeClass("button-on").addClass("button-default"),t('button[data-toggle="'+a+'"][data-title="'+n.OffValue+'"]').removeClass("button-default").addClass("button-off"),t.isFunction(n.OffCallback)&&n.OffCallback(e)),t('button[data-toggle="'+a+'"]').not('[data-title="'+e+'"]').prop("disabled",!1).removeClass("active").addClass("notActive"),t('button[data-toggle="'+a+'"][data-title="'+e+'"]').prop("disabled",!0).removeClass("notActive").addClass("active")},l=function(a,e,l,i){l?(t("#light-"+e).removeClass("tgl-sw-light-checked tgl-sw-active"),a.data("state",!1),t.isFunction(n.OffCallback)&&n.OffCallback(i)):(t("#light-"+e).addClass("tgl-sw-light-checked tgl-sw-active"),a.data("state",!0),t.isFunction(n.OnCallback)&&n.OnCallback(i))},i=function(a,e,l,i){l?(t("#swipe-"+e).removeClass("tgl-sw-swipe-checked tgl-sw-active"),a.data("state",!1),t.isFunction(n.OffCallback)&&n.OffCallback(i)):(t("#swipe-"+e).addClass("tgl-sw-swipe-checked tgl-sw-active"),a.data("state",!0),t.isFunction(n.OnCallback)&&n.OnCallback(i))},d=function(a,e,l,i){l?(t("#ios-"+e).removeClass("tgl-sw-ios-checked tgl-sw-active"),a.data("state",!1),t.isFunction(n.OffCallback)&&n.OffCallback(i)):(t("#ios-"+e).addClass("tgl-sw-ios-checked tgl-sw-active"),a.data("state",!0),t.isFunction(n.OnCallback)&&n.OnCallback(i))},s=function(a,e,l,i){l?(t("#android-"+e).removeClass("tgl-sw-android-checked tgl-sw-active"),a.data("state",!1),t.isFunction(n.OffCallback)&&n.OffCallback(i)):(t("#android-"+e).addClass("tgl-sw-android-checked tgl-sw-active"),a.data("state",!0),t.isFunction(n.OnCallback)&&n.OnCallback(i))},n=t.extend({Theme:"Button",OnText:"On",OffText:"Off",OnValue:!0,OffValue:!1,OnCallback:null,OffCallback:null,ToggleState:!1,ConfirmChanges:!1,ConfirmText:"Are you sure?",HiddenInputId:!1},a);return this.each(function(){var a,o,c=Math.floor(1e6*Math.random()+1),u=t(this),r=this.id;switch(n.Theme){case"Button":default:a='
',o='
',u.html(n.ToggleState==n.OnValue?a:o),t("#bsh-"+r+" button").on("click",function(){var a=t(this).data("title");n.ConfirmChanges?confirm(n.ConfirmText)&&(0!=n.HiddenInputId&&t("#"+n.HiddenInputId).prop("value",a),e(c,a)):(0!=n.HiddenInputId&&t("#"+n.HiddenInputId).prop("value",a),e(c,a))});break;case"Light":a='
',o='
',u.html(n.ToggleState==n.OnValue?a:o),t("#sw-light-"+c).on("click",function(){var a=t(this).data("state"),e=a?n.OffValue:n.OnValue;n.ConfirmChanges?confirm(n.ConfirmText)&&(0!=n.HiddenInputId&&t("#"+n.HiddenInputId).prop("value",e),l(t(this),r,a,e)):(0!=n.HiddenInputId&&t("#"+n.HiddenInputId).prop("value",e),l(t(this),r,a,e))});break;case"Swipe":a='
',o='
',u.html(n.ToggleState==n.OnValue?a:o),t("#sw-swipe-"+c).on("click",function(){var a=t(this).data("state"),e=a?n.OffValue:n.OnValue,l=t("#swipe-"+r);n.ConfirmChanges?confirm(n.ConfirmText)?(0!=n.HiddenInputId&&t("#"+n.HiddenInputId).prop("value",e),i(t(this),r,a,e)):l.is(":checked")?l.prop("checked",!1):l.attr("checked",!0):(0!=n.HiddenInputId&&t("#"+n.HiddenInputId).prop("value",e),i(t(this),r,a,e))});break;case"iOS":a='
',o='
',u.html(n.ToggleState==n.OnValue?a:o),t("#sw-ios-"+c).on("click",function(){var a=t(this).data("state"),e=a?n.OffValue:n.OnValue;n.ConfirmChanges?confirm(n.ConfirmText)&&(0!=n.HiddenInputId&&t("#"+n.HiddenInputId).prop("value",e),d(t(this),r,a,e)):(0!=n.HiddenInputId&&t("#"+n.HiddenInputId).prop("value",e),d(t(this),r,a,e))});break;case"Android":a='
',o='
',u.html(n.ToggleState==n.OnValue?a:o),t("#sw-android-"+c).on("click",function(){var a=t(this).data("state"),e=a?n.OffValue:n.OnValue;n.ConfirmChanges?confirm(n.ConfirmText)&&(0!=n.HiddenInputId&&t("#"+n.HiddenInputId).prop("value",e),s(t(this),r,a,e)):(0!=n.HiddenInputId&&t("#"+n.HiddenInputId).prop("value",e),s(t(this),r,a,e))})}})}}(jQuery); \ No newline at end of file +if("undefined"==typeof jQuery)throw alert("jQuery Switch Button requires jQuery"),new Error("jQuery Switch Button requires jQuery");if(jQuery.fn.jquery<"2.0")throw alert("Incompatible version of jQuery detected, please upgrade to at least 2.0"),new Error("Incompatible version of jQuery detected, please upgrade to at least 2.0");!function(t){t.fn.btnSwitch=function(e){var a=function(e,a){a==n.OnValue?(t('button[data-toggle="'+e+'"][data-title="'+n.OnValue+'"]').removeClass("button-default").addClass("button-on"),t('button[data-toggle="'+e+'"][data-title="'+n.OffValue+'"]').removeClass("button-off").addClass("button-default"),t.isFunction(n.OnCallback)&&n.OnCallback(a)):(t('button[data-toggle="'+e+'"][data-title="'+n.OnValue+'"]').removeClass("button-on").addClass("button-default"),t('button[data-toggle="'+e+'"][data-title="'+n.OffValue+'"]').removeClass("button-default").addClass("button-off"),t.isFunction(n.OffCallback)&&n.OffCallback(a)),t('button[data-toggle="'+e+'"]').not('[data-title="'+a+'"]').prop("disabled",!1).removeClass("active").addClass("notActive"),t('button[data-toggle="'+e+'"][data-title="'+a+'"]').prop("disabled",!0).removeClass("notActive").addClass("active")},l=function(e,a,l,i){l?(t("#light-"+a).removeClass("tgl-sw-light-checked tgl-sw-active"),e.data("state",!1),t.isFunction(n.OffCallback)&&n.OffCallback(i)):(t("#light-"+a).addClass("tgl-sw-light-checked tgl-sw-active"),e.data("state",!0),t.isFunction(n.OnCallback)&&n.OnCallback(i))},i=function(e,a,l,i){l?(t("#swipe-"+a).removeClass("tgl-sw-swipe-checked tgl-sw-active"),e.data("state",!1),t.isFunction(n.OffCallback)&&n.OffCallback(i)):(t("#swipe-"+a).addClass("tgl-sw-swipe-checked tgl-sw-active"),e.data("state",!0),t.isFunction(n.OnCallback)&&n.OnCallback(i))},d=function(e,a,l,i){l?(t("#ios-"+a).removeClass("tgl-sw-ios-checked tgl-sw-active"),e.data("state",!1),t.isFunction(n.OffCallback)&&n.OffCallback(i)):(t("#ios-"+a).addClass("tgl-sw-ios-checked tgl-sw-active"),e.data("state",!0),t.isFunction(n.OnCallback)&&n.OnCallback(i))},s=function(e,a,l,i){l?(t("#android-"+a).removeClass("tgl-sw-android-checked tgl-sw-active"),e.data("state",!1),t.isFunction(n.OffCallback)&&n.OffCallback(i)):(t("#android-"+a).addClass("tgl-sw-android-checked tgl-sw-active"),e.data("state",!0),t.isFunction(n.OnCallback)&&n.OnCallback(i))},n=t.extend({Theme:"Button",OnText:"On",OffText:"Off",OnValue:!0,OffValue:!1,OnCallback:null,OffCallback:null,ToggleState:!1,ConfirmChanges:!1,ConfirmText:"Are you sure?",HiddenInputId:!1},e);return this.each(function(){var e,o,c=Math.floor(1e6*Math.random()+1),u=t(this),r=this.id;switch(n.Theme){case"Button":default:e='
',o='
',u.html(n.ToggleState==n.OnValue?e:o),t("#bsh-"+r+" button").on("click",function(){var e=t(this).data("title");n.ConfirmChanges?confirm(n.ConfirmText)&&(0!=n.HiddenInputId&&t("#"+n.HiddenInputId).prop("value",e),a(c,e)):(0!=n.HiddenInputId&&t("#"+n.HiddenInputId).prop("value",e),a(c,e))});break;case"Light":e='
',o='
',u.html(n.ToggleState==n.OnValue?e:o),t("#sw-light-"+c).on("click",function(){var e=t(this).data("state"),a=e?n.OffValue:n.OnValue;n.ConfirmChanges?confirm(n.ConfirmText)&&(0!=n.HiddenInputId&&t("#"+n.HiddenInputId).prop("value",a),l(t(this),r,e,a)):(0!=n.HiddenInputId&&t("#"+n.HiddenInputId).prop("value",a),l(t(this),r,e,a))});break;case"Swipe":e='
',o='
',u.html(n.ToggleState==n.OnValue?e:o),t("#sw-swipe-"+c).on("click",function(){var e=t(this).data("state"),a=e?n.OffValue:n.OnValue,l=t("#swipe-"+r);n.ConfirmChanges?confirm(n.ConfirmText)?(0!=n.HiddenInputId&&t("#"+n.HiddenInputId).prop("value",a),i(t(this),r,e,a)):l.is(":checked")?l.prop("checked",!1):l.attr("checked",!0):(0!=n.HiddenInputId&&t("#"+n.HiddenInputId).prop("value",a),i(t(this),r,e,a))});break;case"iOS":e='
',o='
',u.html(n.ToggleState==n.OnValue?e:o),t("#sw-ios-"+c).on("click",function(){var e=t(this).data("state"),a=e?n.OffValue:n.OnValue;n.ConfirmChanges?confirm(n.ConfirmText)&&(0!=n.HiddenInputId&&t("#"+n.HiddenInputId).prop("value",a),d(t(this),r,e,a)):(0!=n.HiddenInputId&&t("#"+n.HiddenInputId).prop("value",a),d(t(this),r,e,a))});break;case"Android":e='
',o='
',u.html(n.ToggleState==n.OnValue?e:o),t("#sw-android-"+c).on("click",function(){var e=t(this).data("state"),a=e?n.OffValue:n.OnValue;n.ConfirmChanges?confirm(n.ConfirmText)&&(0!=n.HiddenInputId&&t("#"+n.HiddenInputId).prop("value",a),s(t(this),r,e,a)):(0!=n.HiddenInputId&&t("#"+n.HiddenInputId).prop("value",a),s(t(this),r,e,a))})}})}}(jQuery); \ No newline at end of file diff --git a/jquery.btnswitch.js b/jquery.btnswitch.js index 521e559..f333542 100644 --- a/jquery.btnswitch.js +++ b/jquery.btnswitch.js @@ -179,14 +179,14 @@ if(jQuery.fn.jquery < "2.0") { case 'Button': default: switchOnTpl = '
' + - '' + - '' + + '' + + '' + '
' + '
'; switchOffTpl = '
' + - '' + - '' + + '' + + '' + '
' + '
'; diff --git a/package.json b/package.json index 68f2e1d..db32714 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jquery-btnswitch", - "version": "1.0.0", + "version": "1.0.1", "description": "A simple way to create button switches", "main": "dist/jquery.btnswitch.min.js", "files": [