/* ========================================================================
* bootstrap-switch - v3.3.2
* http://www.bootstrap-switch.org
* ========================================================================
* copyright 2012-2013 mattia larentis
*
* ========================================================================
* licensed under the apache license, version 2.0 (the "license");
* you may not use this file except in compliance with the license.
* you may obtain a copy of the license at
*
* http://www.apache.org/licenses/license-2.0
*
* unless required by applicable law or agreed to in writing, software
* distributed under the license is distributed on an "as is" basis,
* without warranties or conditions of any kind, either express or implied.
* see the license for the specific language governing permissions and
* limitations under the license.
* ========================================================================
*/
(function(){var t=[].slice;!function(e,i){"use strict";var n;return n=function(){function t(t,i){null==i&&(i={}),this.$element=e(t),this.options=e.extend({},e.fn.bootstrapswitch.defaults,{state:this.$element.is(":checked"),size:this.$element.data("size"),animate:this.$element.data("animate"),disabled:this.$element.is(":disabled"),readonly:this.$element.is("[readonly]"),indeterminate:this.$element.data("indeterminate"),inverse:this.$element.data("inverse"),radioalloff:this.$element.data("radio-all-off"),oncolor:this.$element.data("on-color"),offcolor:this.$element.data("off-color"),ontext:this.$element.data("on-text"),offtext:this.$element.data("off-text"),labeltext:this.$element.data("label-text"),handlewidth:this.$element.data("handle-width"),labelwidth:this.$element.data("label-width"),baseclass:this.$element.data("base-class"),wrapperclass:this.$element.data("wrapper-class")},i),this.$wrapper=e("
",{"class":function(t){return function(){var e;return e=[""+t.options.baseclass].concat(t._getclasses(t.options.wrapperclass)),e.push(t.options.state?""+t.options.baseclass+"-on":""+t.options.baseclass+"-off"),null!=t.options.size&&e.push(""+t.options.baseclass+"-"+t.options.size),t.options.disabled&&e.push(""+t.options.baseclass+"-disabled"),t.options.readonly&&e.push(""+t.options.baseclass+"-readonly"),t.options.indeterminate&&e.push(""+t.options.baseclass+"-indeterminate"),t.options.inverse&&e.push(""+t.options.baseclass+"-inverse"),t.$element.attr("id")&&e.push(""+t.options.baseclass+"-id-"+t.$element.attr("id")),e.join(" ")}}(this)()}),this.$container=e("
",{"class":""+this.options.baseclass+"-container"}),this.$on=e("",{html:this.options.ontext,"class":""+this.options.baseclass+"-handle-on "+this.options.baseclass+"-"+this.options.oncolor}),this.$off=e("",{html:this.options.offtext,"class":""+this.options.baseclass+"-handle-off "+this.options.baseclass+"-"+this.options.offcolor}),this.$label=e("",{html:this.options.labeltext,"class":""+this.options.baseclass+"-label"}),this.$element.on("init.bootstrapswitch",function(e){return function(){return e.options.oninit.apply(t,arguments)}}(this)),this.$element.on("switchchange.bootstrapswitch",function(e){return function(){return e.options.onswitchchange.apply(t,arguments)}}(this)),this.$container=this.$element.wrap(this.$container).parent(),this.$wrapper=this.$container.wrap(this.$wrapper).parent(),this.$element.before(this.options.inverse?this.$off:this.$on).before(this.$label).before(this.options.inverse?this.$on:this.$off),this.options.indeterminate&&this.$element.prop("indeterminate",!0),this._init(),this._elementhandlers(),this._handlehandlers(),this._labelhandlers(),this._formhandler(),this._externallabelhandler(),this.$element.trigger("init.bootstrapswitch")}return t.prototype._constructor=t,t.prototype.state=function(t,e){return"undefined"==typeof t?this.options.state:this.options.disabled||this.options.readonly?this.$element:this.options.state&&!this.options.radioalloff&&this.$element.is(":radio")?this.$element:(this.options.indeterminate&&this.indeterminate(!1),t=!!t,this.$element.prop("checked",t).trigger("change.bootstrapswitch",e),this.$element)},t.prototype.togglestate=function(t){return this.options.disabled||this.options.readonly?this.$element:this.options.indeterminate?(this.indeterminate(!1),this.state(!0)):this.$element.prop("checked",!this.options.state).trigger("change.bootstrapswitch",t)},t.prototype.size=function(t){return"undefined"==typeof t?this.options.size:(null!=this.options.size&&this.$wrapper.removeclass(""+this.options.baseclass+"-"+this.options.size),t&&this.$wrapper.addclass(""+this.options.baseclass+"-"+t),this._width(),this._containerposition(),this.options.size=t,this.$element)},t.prototype.animate=function(t){return"undefined"==typeof t?this.options.animate:(t=!!t,t===this.options.animate?this.$element:this.toggleanimate())},t.prototype.toggleanimate=function(){return this.options.animate=!this.options.animate,this.$wrapper.toggleclass(""+this.options.baseclass+"-animate"),this.$element},t.prototype.disabled=function(t){return"undefined"==typeof t?this.options.disabled:(t=!!t,t===this.options.disabled?this.$element:this.toggledisabled())},t.prototype.toggledisabled=function(){return this.options.disabled=!this.options.disabled,this.$element.prop("disabled",this.options.disabled),this.$wrapper.toggleclass(""+this.options.baseclass+"-disabled"),this.$element},t.prototype.readonly=function(t){return"undefined"==typeof t?this.options.readonly:(t=!!t,t===this.options.readonly?this.$element:this.togglereadonly())},t.prototype.togglereadonly=function(){return this.options.readonly=!this.options.readonly,this.$element.prop("readonly",this.options.readonly),this.$wrapper.toggleclass(""+this.options.baseclass+"-readonly"),this.$element},t.prototype.indeterminate=function(t){return"undefined"==typeof t?this.options.indeterminate:(t=!!t,t===this.options.indeterminate?this.$element:this.toggleindeterminate())},t.prototype.toggleindeterminate=function(){return this.options.indeterminate=!this.options.indeterminate,this.$element.prop("indeterminate",this.options.indeterminate),this.$wrapper.toggleclass(""+this.options.baseclass+"-indeterminate"),this._containerposition(),this.$element},t.prototype.inverse=function(t){return"undefined"==typeof t?this.options.inverse:(t=!!t,t===this.options.inverse?this.$element:this.toggleinverse())},t.prototype.toggleinverse=function(){var t,e;return this.$wrapper.toggleclass(""+this.options.baseclass+"-inverse"),e=this.$on.clone(!0),t=this.$off.clone(!0),this.$on.replacewith(t),this.$off.replacewith(e),this.$on=t,this.$off=e,this.options.inverse=!this.options.inverse,this.$element},t.prototype.oncolor=function(t){var e;return e=this.options.oncolor,"undefined"==typeof t?e:(null!=e&&this.$on.removeclass(""+this.options.baseclass+"-"+e),this.$on.addclass(""+this.options.baseclass+"-"+t),this.options.oncolor=t,this.$element)},t.prototype.offcolor=function(t){var e;return e=this.options.offcolor,"undefined"==typeof t?e:(null!=e&&this.$off.removeclass(""+this.options.baseclass+"-"+e),this.$off.addclass(""+this.options.baseclass+"-"+t),this.options.offcolor=t,this.$element)},t.prototype.ontext=function(t){return"undefined"==typeof t?this.options.ontext:(this.$on.html(t),this._width(),this._containerposition(),this.options.ontext=t,this.$element)},t.prototype.offtext=function(t){return"undefined"==typeof t?this.options.offtext:(this.$off.html(t),this._width(),this._containerposition(),this.options.offtext=t,this.$element)},t.prototype.labeltext=function(t){return"undefined"==typeof t?this.options.labeltext:(this.$label.html(t),this._width(),this.options.labeltext=t,this.$element)},t.prototype.handlewidth=function(t){return"undefined"==typeof t?this.options.handlewidth:(this.options.handlewidth=t,this._width(),this._containerposition(),this.$element)},t.prototype.labelwidth=function(t){return"undefined"==typeof t?this.options.labelwidth:(this.options.labelwidth=t,this._width(),this._containerposition(),this.$element)},t.prototype.baseclass=function(){return this.options.baseclass},t.prototype.wrapperclass=function(t){return"undefined"==typeof t?this.options.wrapperclass:(t||(t=e.fn.bootstrapswitch.defaults.wrapperclass),this.$wrapper.removeclass(this._getclasses(this.options.wrapperclass).join(" ")),this.$wrapper.addclass(this._getclasses(t).join(" ")),this.options.wrapperclass=t,this.$element)},t.prototype.radioalloff=function(t){return"undefined"==typeof t?this.options.radioalloff:(t=!!t,t===this.options.radioalloff?this.$element:(this.options.radioalloff=t,this.$element))},t.prototype.oninit=function(t){return"undefined"==typeof t?this.options.oninit:(t||(t=e.fn.bootstrapswitch.defaults.oninit),this.options.oninit=t,this.$element)},t.prototype.onswitchchange=function(t){return"undefined"==typeof t?this.options.onswitchchange:(t||(t=e.fn.bootstrapswitch.defaults.onswitchchange),this.options.onswitchchange=t,this.$element)},t.prototype.destroy=function(){var t;return t=this.$element.closest("form"),t.length&&t.off("reset.bootstrapswitch").removedata("bootstrap-switch"),this.$container.children().not(this.$element).remove(),this.$element.unwrap().unwrap().off(".bootstrapswitch").removedata("bootstrap-switch"),this.$element},t.prototype._width=function(){var t,e;return t=this.$on.add(this.$off),t.add(this.$label).css("width",""),e="auto"===this.options.handlewidth?math.max(this.$on.width(),this.$off.width()):this.options.handlewidth,t.width(e),this.$label.width(function(t){return function(i,n){return"auto"!==t.options.labelwidth?t.options.labelwidth:e>n?e:n}}(this)),this._handlewidth=this.$on.outerwidth(),this._labelwidth=this.$label.outerwidth(),this.$container.width(2*this._handlewidth+this._labelwidth),this.$wrapper.width(this._handlewidth+this._labelwidth)},t.prototype._containerposition=function(t,e){return null==t&&(t=this.options.state),this.$container.css("margin-left",function(e){return function(){var i;return i=[0,"-"+e._handlewidth+"px"],e.options.indeterminate?"-"+e._handlewidth/2+"px":t?e.options.inverse?i[1]:i[0]:e.options.inverse?i[0]:i[1]}}(this)),e?settimeout(function(){return e()},50):void 0},t.prototype._init=function(){var t,e;return t=function(t){return function(){return t._width(),t._containerposition(null,function(){return t.options.animate?t.$wrapper.addclass(""+t.options.baseclass+"-animate"):void 0})}}(this),this.$wrapper.is(":visible")?t():e=i.setinterval(function(n){return function(){return n.$wrapper.is(":visible")?(t(),i.clearinterval(e)):void 0}}(this),50)},t.prototype._elementhandlers=function(){return this.$element.on({"change.bootstrapswitch":function(t){return function(i,n){var o;return i.preventdefault(),i.stopimmediatepropagation(),o=t.$element.is(":checked"),t._containerposition(o),o!==t.options.state?(t.options.state=o,t.$wrapper.toggleclass(""+t.options.baseclass+"-off").toggleclass(""+t.options.baseclass+"-on"),n?void 0:(t.$element.is(":radio")&&e("[name='"+t.$element.attr("name")+"']").not(t.$element).prop("checked",!1).trigger("change.bootstrapswitch",!0),t.$element.trigger("switchchange.bootstrapswitch",[o]))):void 0}}(this),"focus.bootstrapswitch":function(t){return function(e){return e.preventdefault(),t.$wrapper.addclass(""+t.options.baseclass+"-focused")}}(this),"blur.bootstrapswitch":function(t){return function(e){return e.preventdefault(),t.$wrapper.removeclass(""+t.options.baseclass+"-focused")}}(this),"keydown.bootstrapswitch":function(t){return function(e){if(e.which&&!t.options.disabled&&!t.options.readonly)switch(e.which){case 37:return e.preventdefault(),e.stopimmediatepropagation(),t.state(!1);case 39:return e.preventdefault(),e.stopimmediatepropagation(),t.state(!0)}}}(this)})},t.prototype._handlehandlers=function(){return this.$on.on("click.bootstrapswitch",function(t){return function(e){return e.preventdefault(),e.stoppropagation(),t.state(!1),t.$element.trigger("focus.bootstrapswitch")}}(this)),this.$off.on("click.bootstrapswitch",function(t){return function(e){return e.preventdefault(),e.stoppropagation(),t.state(!0),t.$element.trigger("focus.bootstrapswitch")}}(this))},t.prototype._labelhandlers=function(){return this.$label.on({"mousedown.bootstrapswitch touchstart.bootstrapswitch":function(t){return function(e){return t._dragstart||t.options.disabled||t.options.readonly?void 0:(e.preventdefault(),e.stoppropagation(),t._dragstart=(e.pagex||e.originalevent.touches[0].pagex)-parseint(t.$container.css("margin-left"),10),t.options.animate&&t.$wrapper.removeclass(""+t.options.baseclass+"-animate"),t.$element.trigger("focus.bootstrapswitch"))}}(this),"mousemove.bootstrapswitch touchmove.bootstrapswitch":function(t){return function(e){var i;if(null!=t._dragstart&&(e.preventdefault(),i=(e.pagex||e.originalevent.touches[0].pagex)-t._dragstart,!(i<-t._handlewidth||i>0)))return t._dragend=i,t.$container.css("margin-left",""+t._dragend+"px")}}(this),"mouseup.bootstrapswitch touchend.bootstrapswitch":function(t){return function(e){var i;if(t._dragstart)return e.preventdefault(),t.options.animate&&t.$wrapper.addclass(""+t.options.baseclass+"-animate"),t._dragend?(i=t._dragend>-(t._handlewidth/2),t._dragend=!1,t.state(t.options.inverse?!i:i)):t.state(!t.options.state),t._dragstart=!1}}(this),"mouseleave.bootstrapswitch":function(t){return function(){return t.$label.trigger("mouseup.bootstrapswitch")}}(this)})},t.prototype._externallabelhandler=function(){var t;return t=this.$element.closest("label"),t.on("click",function(e){return function(i){return i.preventdefault(),i.stopimmediatepropagation(),i.target===t[0]?e.togglestate():void 0}}(this))},t.prototype._formhandler=function(){var t;return t=this.$element.closest("form"),t.data("bootstrap-switch")?void 0:t.on("reset.bootstrapswitch",function(){return i.settimeout(function(){return t.find("input").filter(function(){return e(this).data("bootstrap-switch")}).each(function(){return e(this).bootstrapswitch("state",this.checked)})},1)}).data("bootstrap-switch",!0)},t.prototype._getclasses=function(t){var i,n,o,s;if(!e.isarray(t))return[""+this.options.baseclass+"-"+t];for(n=[],o=0,s=t.length;s>o;o++)i=t[o],n.push(""+this.options.baseclass+"-"+i);return n},t}(),e.fn.bootstrapswitch=function(){var i,o,s;return o=arguments[0],i=2<=arguments.length?t.call(arguments,1):[],s=this,this.each(function(){var t,a;return t=e(this),a=t.data("bootstrap-switch"),a||t.data("bootstrap-switch",a=new n(this,o)),"string"==typeof o?s=a[o].apply(a,i):void 0}),s},e.fn.bootstrapswitch.constructor=n,e.fn.bootstrapswitch.defaults={state:!0,size:null,animate:!0,disabled:!1,readonly:!1,indeterminate:!1,inverse:!1,radioalloff:!1,oncolor:"primary",offcolor:"default",ontext:"on",offtext:"off",labeltext:" ",handlewidth:"auto",labelwidth:"auto",baseclass:"bootstrap-switch",wrapperclass:"wrapper",oninit:function(){},onswitchchange:function(){}}}(window.jquery,window)}).call(this);