diff --git a/README.md b/README.md index 5156883..60cc174 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -jquery.switcher v1.2.3 +jquery.switcher v1.2.4 =============== Custom checkbox / radio button in jquery diff --git a/bower.json b/bower.json index 5430d16..ba34d44 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jquery.switcher", - "version": "1.2.3", + "version": "1.2.4", "homepage": "http://djanix.github.io/jquery.switcher/", "docs": "http://amsul.github.io/pickadate.js", "authors": [ diff --git a/dist/switcher.css b/dist/switcher.css index b0f69ce..791d71b 100644 --- a/dist/switcher.css +++ b/dist/switcher.css @@ -1,5 +1,6 @@ -/* jquery.switcher - 1.2.3 -* Copyright (c) 2014-09-03 Janic Beauchemin - https://github.com/djanix/ */ +/* jquery.switcher - 1.2.4 +* https://github.com/djanix/jquery-switcher +* Copyright (c) 2014-09-17 - */ .switcher { @@ -29,7 +30,7 @@ } .switcher.default { - background-color: white; + background-color: #fff; border: 1px solid #dfdfdf; border-radius: 4px; line-height: 26px; @@ -42,9 +43,8 @@ display: none; } .switcher.default .slider { - background-color: white; + background-color: #fff; border-radius: 4px; - -webkit-box-shadow: 0 0 2px 1px #dfdfdf; box-shadow: 0 0 2px 1px #dfdfdf; height: 26px; left: 0; @@ -65,7 +65,7 @@ *zoom: 1; } .switcher.default .textYes { - color: white; + color: #fff; float: left; } .switcher.default .textNo { @@ -91,7 +91,7 @@ display: none; } .switcher.short .content { - border: 1px solid #aaaaaa; + border: 1px solid #aaa; border-radius: 50%; height: 18px; padding: 0; @@ -116,3 +116,5 @@ -ms-transform: scale(1); transform: scale(1); } + +/*# sourceMappingURL=switcher.css.map */ \ No newline at end of file diff --git a/dist/switcher.js b/dist/switcher.js index 69fbbe4..89c3692 100644 --- a/dist/switcher.js +++ b/dist/switcher.js @@ -1,11 +1,11 @@ -/* jquery.switcher - 1.2.3 +/* jquery.switcher - 1.2.4 * Copyright (c) 2014-09-03 Janic Beauchemin - https://github.com/djanix/ */ ;(function ($, undefined) { var pluginName = "switcher"; var defaults = { - class: "switcher", + className: "switcher", selected: null, language: "en", disabled: null, @@ -41,7 +41,7 @@ var self = this; var $input = $(input); - $input.wrap('
'); + $input.wrap('
'); $input.after( '
' + '
' + @@ -50,7 +50,7 @@ '
' ); - this.container = $($input).parent('.' + settings.class)[0]; + this.container = $($input).parent('.' + settings.className)[0]; self.setLanguage(settings.language); self.setValue(settings.selected); @@ -110,7 +110,7 @@ if ($input.attr('type') == 'radio') { var name = $input.attr('name'); var $inputGroup = $('input[name="' + name + '"]'); - var $containerGroup = $inputGroup.parent('.' + self.settings.class); + var $containerGroup = $inputGroup.parent('.' + self.settings.className); if (val === true) { $containerGroup.removeClass('is-active'); diff --git a/dist/switcher.min.css b/dist/switcher.min.css index 61d5b16..2603a32 100644 --- a/dist/switcher.min.css +++ b/dist/switcher.min.css @@ -1,5 +1,8 @@ -/* jquery.switcher - 1.2.3 -* Copyright (c) 2014-09-03 Janic Beauchemin - https://github.com/djanix/ */ +/* jquery.switcher - 1.2.4 +* https://github.com/djanix/jquery-switcher +* Copyright (c) 2014-09-17 - */ -.switcher{cursor:pointer;font-family:"Lucida Sans Unicode","Lucida Grande",sans-serif;font-size:12px;text-transform:uppercase;display:inline-block;*display:inline;*zoom:1}.switcher .content{position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.switcher .text{display:none;overflow:hidden;text-align:center;white-space:nowrap}.switcher.is-disabled{opacity:0.4}.switcher.default{background-color:#fff;border:1px solid #dfdfdf;border-radius:4px;line-height:26px;min-width:80px;padding:2px;-webkit-transition:background-color 0.3s;transition:background-color 0.3s}.switcher.default input{display:none}.switcher.default .slider{background-color:#fff;border-radius:4px;-webkit-box-shadow:0 0 2px 1px #dfdfdf;box-shadow:0 0 2px 1px #dfdfdf;height:26px;left:0;position:absolute;top:0;-webkit-transform:translateX(0%);-ms-transform:translateX(0%);transform:translateX(0%);-webkit-transition:-webkit-transform 0.3s;transition:transform 0.3s;width:50%;z-index:2}.switcher.default .text{width:50%;display:inline-block;*display:inline;*zoom:1}.switcher.default .textYes{color:#fff;float:left}.switcher.default .textNo{color:#9f9f9f;float:right}.switcher.default.is-active{background-color:#519b20}.switcher.default.is-active .slider{-webkit-transform:translateX(100%);-ms-transform:translateX(100%);transform:translateX(100%)}.switcher.short{cursor:pointer;display:inline-block;margin-right:5px;vertical-align:middle}.switcher.short input{display:none}.switcher.short .content{border:1px solid #aaa;border-radius:50%;height:18px;padding:0;width:18px}.switcher.short .slider{background-color:#519b20;border-radius:50%;height:12px;margin:3px;opacity:0;-webkit-transform:scale(0);-ms-transform:scale(0);transform:scale(0);-webkit-transition:all 0.2s;transition:all 0.2s;width:12px}.switcher.short.is-active .slider{opacity:1;-webkit-transform:scale(1);-ms-transform:scale(1);transform:scale(1)} +.switcher{cursor:pointer;font-family:"Lucida Sans Unicode","Lucida Grande",sans-serif;font-size:12px;text-transform:uppercase;display:inline-block;*display:inline;*zoom:1}.switcher .content{position:relative;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.switcher .text{display:none;overflow:hidden;text-align:center;white-space:nowrap}.switcher.is-disabled{opacity:0.4}.switcher.default{background-color:#fff;border:1px solid #dfdfdf;border-radius:4px;line-height:26px;min-width:80px;padding:2px;-webkit-transition:background-color 0.3s;transition:background-color 0.3s}.switcher.default input{display:none}.switcher.default .slider{background-color:#fff;border-radius:4px;box-shadow:0 0 2px 1px #dfdfdf;height:26px;left:0;position:absolute;top:0;-webkit-transform:translateX(0%);-ms-transform:translateX(0%);transform:translateX(0%);-webkit-transition:-webkit-transform 0.3s;transition:transform 0.3s;width:50%;z-index:2}.switcher.default .text{width:50%;display:inline-block;*display:inline;*zoom:1}.switcher.default .textYes{color:#fff;float:left}.switcher.default .textNo{color:#9f9f9f;float:right}.switcher.default.is-active{background-color:#519b20}.switcher.default.is-active .slider{-webkit-transform:translateX(100%);-ms-transform:translateX(100%);transform:translateX(100%)}.switcher.short{cursor:pointer;display:inline-block;margin-right:5px;vertical-align:middle}.switcher.short input{display:none}.switcher.short .content{border:1px solid #aaa;border-radius:50%;height:18px;padding:0;width:18px}.switcher.short .slider{background-color:#519b20;border-radius:50%;height:12px;margin:3px;opacity:0;-webkit-transform:scale(0);-ms-transform:scale(0);transform:scale(0);-webkit-transition:all 0.2s;transition:all 0.2s;width:12px}.switcher.short.is-active .slider{opacity:1;-webkit-transform:scale(1);-ms-transform:scale(1);transform:scale(1)} + +/*# sourceMappingURL=switcher.min.css.map */ \ No newline at end of file diff --git a/dist/switcher.min.js b/dist/switcher.min.js index 4846332..023dbdd 100644 --- a/dist/switcher.min.js +++ b/dist/switcher.min.js @@ -1,4 +1,5 @@ -/* jquery.switcher - 1.2.3 -* Copyright (c) 2014-09-03 Janic Beauchemin - https://github.com/djanix/ */ +/* jquery.switcher - 1.2.4 +* https://github.com/djanix/jquery-switcher +* Copyright (c) 2014-09-17 - */ -!function(a){function b(b,c){this.input=b,this.container=null,this.settings=a.extend({},h,a(b).data(),c),this._defaults=h,this._name=g,this.init()}function c(){this.removeEventListener("touchmove",d),this.removeEventListener("touchend",c),k=!1}function d(b){if(b.preventDefault(),k){var d=b.touches[0].pageX,e=b.touches[0].pageY,f=i-d,g=j-e,h=null;Math.abs(f)>=l?h=f>0?"left":"right":Math.abs(g)>=l&&(h=g>0?"down":"up"),h&&(c.call(this),a(this).trigger("swipe",h).trigger("swipe"+h))}}function e(a){1==a.touches.length&&(i=a.touches[0].pageX,j=a.touches[0].pageY,k=!0,this.addEventListener("touchmove",d,!1),this.addEventListener("touchend",c,!1))}function f(){this.addEventListener&&this.addEventListener("touchstart",e,!1)}var g="switcher",h={"class":"switcher",selected:null,language:"en",disabled:null,style:"default",copy:{en:{yes:"yes",no:"no"},fr:{yes:"oui",no:"non"}}};a.extend(b.prototype,{init:function(){this.buildHtml(this.input,this.settings),this.bindEvents(this.container,this.settings)},buildHtml:function(b,c){var d=this,e=a(b);e.wrap('
'),e.after('
'),this.container=a(e).parent("."+c.class)[0],d.setLanguage(c.language),d.setValue(c.selected),d.setDisabled(c.disabled)},bindEvents:function(b,c){var d=this,e=a(b),f=e.find("input");e.on("click",function(){c.disabled||d.setValue("radio"==f.attr("type")?!0:e.closest("label").length?f.prop("checked"):!f.prop("checked"))}),e.on("swipeleft",function(){c.disabled||d.setValue(!1)}),e.on("swiperight",function(){c.disabled||d.setValue(!0)})},setValue:function(b){var c=this,d=a(c.input),e=a(c.container);if(null===b&&(b="radio"==d.attr("type")?"undefined"!=typeof d.filter(":checked").val():d.prop("checked")),"boolean"!=typeof b)return console.log("The parameter need to be true or false as a boolean");if(c.settings.selected=b,d.prop("checked",b),"radio"==d.attr("type")){var f=d.attr("name"),g=a('input[name="'+f+'"]'),h=g.parent("."+c.settings.class);b===!0&&(h.removeClass("is-active"),g.prop("checked",!1),e.addClass("is-active"),d.prop("checked",!0))}else b===!0?e.addClass("is-active"):e.removeClass("is-active")},setDisabled:function(b){var c=this,d=a(c.input),e=a(c.container);return null===b&&(b=d.attr("disabled")?!0:!1),"boolean"!=typeof b?console.log("The parameter need to be true or false as a boolean"):(c.settings.disabled=b,void(b===!0?e.addClass("is-disabled"):e.removeClass("is-disabled")))},setLanguage:function(b){var c=this,d=a(c.container);c.settings.language=b,d.find(".textYes").text(c.settings.copy[b].yes),d.find(".textNo").text(c.settings.copy[b].no)},getLanguage:function(a){var b=this;return a(b.settings.language)},importLanguage:function(a){var b=this;b.settings.copy=a}}),a.fn[g]=function(c){var d=Array.prototype.slice.call(arguments,1);return this.each(function(){var e=a(this),f=e.data("plugin_"+g);f?"string"==typeof c&&f[c].apply(f,d):e.data("plugin_"+g,new b(this,c))}),this};var i=0,j=0,k=!1,l=30;a.event.special.swipe={setup:f},a.each(["left","up","down","right"],function(){a.event.special["swipe"+this]={setup:function(){a(this).on("swipe",a.noop)}}})}($); \ No newline at end of file +!function(a){function b(b,c){this.input=b,this.container=null,this.settings=a.extend({},h,a(b).data(),c),this._defaults=h,this._name=g,this.init()}function c(){this.removeEventListener("touchmove",d),this.removeEventListener("touchend",c),k=!1}function d(b){if(b.preventDefault(),k){var d=b.touches[0].pageX,e=b.touches[0].pageY,f=i-d,g=j-e,h=null;Math.abs(f)>=l?h=f>0?"left":"right":Math.abs(g)>=l&&(h=g>0?"down":"up"),h&&(c.call(this),a(this).trigger("swipe",h).trigger("swipe"+h))}}function e(a){1==a.touches.length&&(i=a.touches[0].pageX,j=a.touches[0].pageY,k=!0,this.addEventListener("touchmove",d,!1),this.addEventListener("touchend",c,!1))}function f(){this.addEventListener&&this.addEventListener("touchstart",e,!1)}var g="switcher",h={className:"switcher",selected:null,language:"en",disabled:null,style:"default",copy:{en:{yes:"yes",no:"no"},fr:{yes:"oui",no:"non"}}};a.extend(b.prototype,{init:function(){this.buildHtml(this.input,this.settings),this.bindEvents(this.container,this.settings)},buildHtml:function(b,c){var d=this,e=a(b);e.wrap('
'),e.after('
'),this.container=a(e).parent("."+c.className)[0],d.setLanguage(c.language),d.setValue(c.selected),d.setDisabled(c.disabled)},bindEvents:function(b,c){var d=this,e=a(b),f=e.find("input");e.on("click",function(){c.disabled||d.setValue("radio"==f.attr("type")?!0:e.closest("label").length?f.prop("checked"):!f.prop("checked"))}),e.on("swipeleft",function(){c.disabled||d.setValue(!1)}),e.on("swiperight",function(){c.disabled||d.setValue(!0)})},setValue:function(b){var c=this,d=a(c.input),e=a(c.container);if(null===b&&(b="radio"==d.attr("type")?"undefined"!=typeof d.filter(":checked").val():d.prop("checked")),"boolean"!=typeof b)return console.log("The parameter need to be true or false as a boolean");if(c.settings.selected=b,d.prop("checked",b),"radio"==d.attr("type")){var f=d.attr("name"),g=a('input[name="'+f+'"]'),h=g.parent("."+c.settings.className);b===!0&&(h.removeClass("is-active"),g.prop("checked",!1),e.addClass("is-active"),d.prop("checked",!0))}else b===!0?e.addClass("is-active"):e.removeClass("is-active")},setDisabled:function(b){var c=this,d=a(c.input),e=a(c.container);return null===b&&(b=d.attr("disabled")?!0:!1),"boolean"!=typeof b?console.log("The parameter need to be true or false as a boolean"):(c.settings.disabled=b,void(b===!0?e.addClass("is-disabled"):e.removeClass("is-disabled")))},setLanguage:function(b){var c=this,d=a(c.container);c.settings.language=b,d.find(".textYes").text(c.settings.copy[b].yes),d.find(".textNo").text(c.settings.copy[b].no)},getLanguage:function(a){var b=this;return a(b.settings.language)},importLanguage:function(a){var b=this;b.settings.copy=a}}),a.fn[g]=function(c){var d=Array.prototype.slice.call(arguments,1);return this.each(function(){var e=a(this),f=e.data("plugin_"+g);f?"string"==typeof c&&f[c].apply(f,d):e.data("plugin_"+g,new b(this,c))}),this};var i=0,j=0,k=!1,l=30;a.event.special.swipe={setup:f},a.each(["left","up","down","right"],function(){a.event.special["swipe"+this]={setup:function(){a(this).on("swipe",a.noop)}}})}($); \ No newline at end of file diff --git a/package.json b/package.json index 1f5144b..f8cb80b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "jquery.switcher", - "version": "1.2.3", - "description": "jquery.switcher v1.2.3\r ===============", + "version": "1.2.4", + "description": "jquery.switcher v1.2.4\r ===============", "homepage": "https://github.com/djanix/jquery-switcher", "author": "Janic Beauchemin (https://github.com/djanix/)", "devDependencies": { diff --git a/switcher.js b/switcher.js index 69fbbe4..89c3692 100644 --- a/switcher.js +++ b/switcher.js @@ -1,11 +1,11 @@ -/* jquery.switcher - 1.2.3 +/* jquery.switcher - 1.2.4 * Copyright (c) 2014-09-03 Janic Beauchemin - https://github.com/djanix/ */ ;(function ($, undefined) { var pluginName = "switcher"; var defaults = { - class: "switcher", + className: "switcher", selected: null, language: "en", disabled: null, @@ -41,7 +41,7 @@ var self = this; var $input = $(input); - $input.wrap('
'); + $input.wrap('
'); $input.after( '
' + '
' + @@ -50,7 +50,7 @@ '
' ); - this.container = $($input).parent('.' + settings.class)[0]; + this.container = $($input).parent('.' + settings.className)[0]; self.setLanguage(settings.language); self.setValue(settings.selected); @@ -110,7 +110,7 @@ if ($input.attr('type') == 'radio') { var name = $input.attr('name'); var $inputGroup = $('input[name="' + name + '"]'); - var $containerGroup = $inputGroup.parent('.' + self.settings.class); + var $containerGroup = $inputGroup.parent('.' + self.settings.className); if (val === true) { $containerGroup.removeClass('is-active');