forked from minhur/bootstrap-toggle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.bootstrap.toggle.min.js
1 lines (1 loc) · 3.42 KB
/
jquery.bootstrap.toggle.min.js
1
!function(e){var f={id:"toggle","data-on-caption":"On","data-off-caption":"Off","data-on-icon":"icon-check icon-white","data-off-icon":"icon-ban-circle icon-white"};var d='<div class="toggle btn btn-mini" data-toggle="toggle"><input type="checkbox"><div class="toggle-group"><label class="toggle-on btn btn-mini btn-success"></label><label class="toggle-off btn btn-mini btn-danger"></label><span class="toggle-handle btn btn-mini"></span></div></div>';var c={".toggle":{"min-width":"40px",height:"20px",position:"relative",overflow:"hidden"},'.toggle input[type="checkbox"]':{display:"none"},".toggle-group":{position:"absolute",width:"200%",top:"0",bottom:"0",left:"0",transition:"left 0.35s","-webkit-transition":"left 0.35s","-moz-user-select":"none","-webkit-user-select":"none"},".toggle:not(.off) .toggle-group":{left:"0"},".toggle.off .toggle-group":{left:"-100%"},".toggle-on":{position:"absolute",top:"0",bottom:"0",left:"0",right:"50%",margin:"0",border:"0","border-radius":"0"},".toggle-off":{position:"absolute",top:"0",bottom:"0",left:"50%",right:"0",margin:"0",border:"0","border-radius":"0"},".toggle-handle":{position:"relative",margin:"0 auto","padding-top":"0px","padding-bottom":"0px",height:"100%",width:"0px","border-width":"0 1px"},".toggle-handle.btn-mini":{top:"-1px"},".toggle.btn":{"min-width":"30px","-webkit-border-radius":"3px !important","-moz-border-radius":"3px !important","border-radius":"3px !important"},".toggle-on.btn":{"padding-right":"24px"},".toggle-off.btn":{"padding-left":"24px"},".toggle.btn-large":{"min-width":"40px"},".toggle-on.btn-large":{"padding-right":"35px"},".toggle-off.btn-large":{"padding-left":"35px"},".toggle.btn-small":{"min-width":"25px"},".toggle-on.btn-small":{"padding-right":"20px"},".toggle-off.btn-small":{"padding-left":"20px"},".toggle.btn-mini":{"min-width":"20px"},".toggle-on.btn-mini":{"padding-right":"12px"},".toggle-off.btn-mini":{"padding-left":"12px"}};var a=function(g,i){var j=g.find("input[type=checkbox]");var h=(i==="on");if(h){g.attr("class","toggle "+g.find(".toggle-on").attr("class").replace(/toggle-on/g,""));g.removeClass("off")}else{g.attr("class","toggle "+g.find(".toggle-off").attr("class").replace(/toggle-off/g,""));g.addClass("off")}j.prop("checked",h);g.attr("data-toggle-on",h);b()};var b=function(){e(".toggle.btn").css({"-webkit-border-radius":"3px","-moz-border-radius":"3px","border-radius":"3px"});e(".toggle .toggle-group").css("left","0");e(".toggle.off .toggle-group").css("left","-100%")};e(document).on("click.bootstrap-toggle","[data-toggle^=toggle]",function(h){var g=e(this).hasClass("off")?"on":"off";a(e(this),g);e(this).find("input").change()});e(document).on("change",".toggle input",function(){var g=e(this).prop("checked")?"on":"off";a(e(this).closest(".toggle"),g)});e.fn.togglize=function(){this.each(function(){if(e(this)[0].type==="checkbox"){var i=e(this).prop("checked")?"off":"on";var g=e(d);var h={id:e(this).attr("id"),"data-on-caption":e(this).attr("data-on-caption"),"data-off-caption":e(this).attr("data-off-caption"),"data-on-icon":e(this).attr("data-on-icon"),"data-off-icon":e(this).attr("data-off-icon")};var j=e.extend({},f,h);g.find(".toggle-on").html("<i class = '"+j["data-on-icon"]+"'></i> "+j["data-on-caption"]);g.find(".toggle-off").html("<i class = '"+j["data-off-icon"]+"'></i> "+j["data-off-caption"]);g.find("input[type=checkbox]").attr("id",j.id);e(this).replaceWith(g);a(g,i)}});e.each(c,function(h,g){e(h).css(g);b()});return this}}(window.jQuery);