-
Notifications
You must be signed in to change notification settings - Fork 13
/
jquery.toggleswitch.min.js
8 lines (8 loc) · 1.18 KB
/
jquery.toggleswitch.min.js
1
2
3
4
5
6
7
8
/*
Title: Toggle Switch
URL: http://github.com/jamiebicknell/Toggle-Switch
Author: Jamie Bicknell
Twitter: @jamiebicknell
Thanks: @steve228uk for prop/var mods and plugin suggestion
*/
(function(e){"use strict";e.fn.toggleSwitch=function(t){var n=e.extend({onClick:function(){return true},onChangeOn:function(){return true},onChangeOff:function(){return true}},t);e(this).each(function(){var t=e(this),r=t.is(":checked")?"":" off";if(!t.parent("div.switch").length){t.wrap('<div class="switch"></div>');t.parent("div.switch").prepend('<span class="switched'+r+'" />').prepend('<div class="overlay" />')}t.parent("div.switch").add(e("label[for="+t.prop("id")+"]")).click(function(r){r.preventDefault();if(!t.prop("disabled")){var i,s;n.onClick.call(t);if(e(this).is("label")){i=e("#"+e(this).prop("for")).prev("span.switched");s=e("#"+e(this).prop("for"))}else{i=e(this).children("span.switched");s=e(this).children("input[type=checkbox]")}if(i.is(".off")){i.stop().animate({left:0},150,"linear").removeClass("off");s.prop("checked","checked");n.onChangeOn.call(t)}else{i.stop().animate({left:-21},150,"linear").addClass("off");s.prop("checked","");n.onChangeOff.call(t)}}})})}})(jQuery)