Current Path : /var/www/www-root/data/www/monolith-realty.ru/local/templates/monolitsochi/js/ |
Current File : /var/www/www-root/data/www/monolith-realty.ru/local/templates/monolitsochi/js/on-off-switch.min.js |
if(!DG)var DG={};DG.switches={},DG.OnOffSwitchProperties=["textOn","textOff","width","height","heightTrack","trackColorOn","trackColorOff","textColorOn","textColorOff","listener","trackBorderColor","textSizeRatio"],DG.OnOffSwitch=function(config){if(null!=config.el){this.inputEl=$(config.el),this.name=this.inputEl.attr("name"),DG.switches[this.name]=this,DG.switches["#"+this.inputEl.attr("id")]=this;var t=this.inputEl.attr("type");this.isCheckbox=t&&"checkbox"==t.toLowerCase(),this.isCheckbox?this.checked=this.inputEl.is(":checked"):this.checked=1==this.inputEl.val()}for(var properties=DG.OnOffSwitchProperties,i=0;i<properties.length;i++)null!=config[properties[i]]&&(this[properties[i]]=config[properties[i]]);this.render()},$.extend(DG.OnOffSwitch.prototype,{inputEl:void 0,listener:void 0,trackBorderColor:void 0,checked:!1,width:0,height:30,heightTrack:12,trackBorderWidth:1,textSizeRatio:.4,trackColorOn:void 0,trackColorOff:"#EEE",textColorOn:void 0,textColorOff:void 0,el:void 0,track:void 0,thumb:void 0,thumbColor:void 0,onTextEl:void 0,offTextEl:void 0,onOffTrackContainer:void 0,textOn:"",textOff:"",minX:0,maxX:0,trackOn:void 0,trackOff:void 0,innerTrackWidth:0,name:void 0,dragCurrentX:0,borderSize:0,isCheckbox:!1,render:function(){if(0==this.width){var ratio=this.textSizeRatio/2,widthFactor=2+Math.max(this.textOff.length*ratio,this.textOn.length*ratio);this.width=this.height*widthFactor}this.inputEl.css("display","none"),this.el=$('<div class="on-off-switch" style="width:'+this.width+"px;height:"+this.height+'px"></div>'),this.inputEl.after(this.el),this.inputEl.on("change",this.listenToClickEvent.bind(this)),this.renderTrack(),this.renderThumb(),this.applyStyles(),this.track.on("click",this.toggle.bind(this)),this.track.on("touchend",this.toggle.bind(this)),this.addEvents()},listenToClickEvent:function(){this.inputEl.is(":checked")?this.checked||this.toggle():this.checked&&this.toggle()},addEvents:function(){this.thumb.on("mousedown",this.startDragging.bind(this)),this.thumb.on("touchstart",this.startDragging.bind(this)),this.thumb.on("mouseenter",this.enterThumb.bind(this)),this.thumb.on("mouseleave",this.leaveThumb.bind(this)),$(document.documentElement).on("touchmove",this.drag.bind(this)),$(document.documentElement).on("mousemove",this.drag.bind(this)),$(document.documentElement).on("mouseup",this.endDrag.bind(this)),$(document.documentElement).on("touchend",this.endDrag.bind(this))},enterThumb:function(){this.thumbColor.addClass("on-off-switch-thumb-over")},leaveThumb:function(){this.thumbColor.removeClass("on-off-switch-thumb-over")},renderTrack:function(){var trackWidth=this.width-2*this.trackBorderWidth,innerTrackWidth=trackWidth-this.height/2;this.innerTrackWidth=trackWidth;var trackHeight=this.height-2*this.trackBorderWidth,trackHeightOuter=this.heightTrack,borderWidth=this.height/2;this.track=$('<div class="on-off-switch-track" style="border-radius:'+borderWidth+"px;border-width:"+this.trackBorderWidth+"px;width:"+trackWidth+"px;margin-top:"+-(trackHeightOuter/2+1)+"px;height:"+trackHeightOuter+'px"></div>'),this.trackBorderColor&&this.track.css("border-color",this.trackBorderColor),this.el.append(this.track),this.onOffTrackContainer=$('<div style="position:absolute;height:'+trackHeight+"px;width:"+2*innerTrackWidth+'px"></div>'),this.track.append(this.onOffTrackContainer),this.trackOn=$('<div class="on-off-switch-track-on" style="border-radius:'+borderWidth+"px;border-width:"+this.trackBorderWidth+"px;width:"+innerTrackWidth+"px;height:"+trackHeightOuter+'px"><div class="track-on-gradient"></div></div>'),this.onOffTrackContainer.append(this.trackOn),this.onTextEl=$('<div class="on-off-switch-text on-off-switch-text-on">'+this.textOn+"</div>"),this.trackOn.append(this.onTextEl),this.textColorOn&&this.onTextEl.css("color",this.textColorOn),this.trackOff=$('<div class="on-off-switch-track-off" style="overflow:hidden;left:'+(innerTrackWidth-this.height/2)+"px;border-radius:"+borderWidth+"px;border-width:"+this.trackBorderWidth+"px;width:"+this.width+"px;height:"+trackHeightOuter+'px"><div class="track-off-gradient"></div></div>'),this.offTextEl=$('<div class="on-off-switch-text on-off-switch-text-off">'+this.textOff+"</div>"),this.onOffTrackContainer.append(this.trackOff),this.trackOff.append(this.offTextEl),this.textColorOff&&this.offTextEl.css("color",this.textColorOff),this.styleText(this.onTextEl),this.styleText(this.offTextEl);var whiteHeight=this.height/2,whiteBorderRadius=whiteHeight/2,horizontalOffset=whiteBorderRadius/2,whiteWidth=this.width-2*horizontalOffset,whiteEl=$('<div class="on-off-switch-track-white" style="left:'+horizontalOffset+"px;width:"+whiteWidth+"px;height:"+whiteHeight+"px;border-radius:"+whiteBorderRadius+'px"></div>'),whiteEl2=$('<div class="on-off-switch-track-white" style="left:'+horizontalOffset+"px;width:"+whiteWidth+"px;height:"+whiteHeight+"px;border-radius:"+whiteBorderRadius+'px"></div>');whiteEl.css("top",this.height/2),whiteEl2.css("top",this.height/2),this.trackOn.append(whiteEl),this.trackOff.append(whiteEl2),this.maxX=this.width-this.height},styleText:function(el){var textHeight=Math.round(this.height*this.textSizeRatio),textWidth=Math.round(this.width-this.height);el.css("line-height",this.height-2*this.trackBorderWidth+"px"),el.css("font-size",textHeight+"px"),el.css("left",this.height/2+"px"),el.css("width",textWidth+"px")},renderThumb:function(){var borderSize=this.getBorderSize(),size=this.height-2*borderSize,borderRadius=(this.height-this.height%2)/2;this.thumb=$('<div class="on-off-switch-thumb" style="width:'+this.height+"px;height:"+this.height+'px"></div>');var shadow=$('<div class="on-off-switch-thumb-shadow" style="border-radius:'+borderRadius+"px;width:"+size+"px;height:"+size+"px;border-width:"+borderSize+'px;"></div>');this.thumb.append(shadow),this.thumbColor=$('<div class="on-off-switch-thumb-color" style="border-radius:'+borderRadius+"px;width:"+size+"px;height:"+size+"px;left:"+borderSize+"px;top:"+borderSize+'px"></div>'),this.thumb.append(this.thumbColor),this.trackColorOff&&this.trackOff.css("background-color",this.trackColorOff),this.trackColorOn&&this.trackOn.css("background-color",this.trackColorOn),this.el.append(this.thumb)},getBorderSize:function(){return 0==this.borderSize&&(this.borderSize=Math.round(this.height/40)),this.borderSize},applyStyles:function(){this.thumbColor.removeClass("on-off-switch-thumb-on"),this.thumbColor.removeClass("on-off-switch-thumb-off"),this.thumbColor.removeClass("on-off-switch-thumb-over"),this.checked?(this.thumbColor.addClass("on-off-switch-thumb-on"),this.thumb.css("left",this.width-this.height),this.onOffTrackContainer.css("left",-1)):(this.onOffTrackContainer.css("left",this.getTrackPosUnchecked()),this.thumbColor.addClass("on-off-switch-thumb-off"),this.thumb.css("left",-1)),this.isCheckbox?this.inputEl.prop("checked",this.checked):this.inputEl.val(this.checked?1:0)},isDragging:!1,hasBeenDragged:!1,startDragging:function(e){this.isDragging=!0,this.hasBeenDragged=!1;var position=this.thumb.position();return this.startCoordinates={x:this.getX(e),elX:position.left},!1},drag:function(e){if(!this.isDragging)return!0;this.hasBeenDragged=!0;var x=this.startCoordinates.elX+this.getX(e)-this.startCoordinates.x;return x<this.minX&&(x=this.minX),x>this.maxX&&(x=this.maxX),this.onOffTrackContainer.css("left",x-this.width+this.height),x||(x=-1),this.thumb.css("left",x),!1},getX:function(e){var x=e.pageX;return!e.type||"touchstart"!=e.type&&"touchmove"!=e.type||(x=e.originalEvent.touches[0].pageX),this.dragCurrentX=x,x},endDrag:function(){if(!this.isDragging)return!0;if(this.hasBeenDragged){var center=this.width/2-this.height/2,x;this.startCoordinates.elX+this.dragCurrentX-this.startCoordinates.x<center?this.animateLeft():this.animateRight()}else this.toggle();this.isDragging=!1},getTrackPosUnchecked:function(){return 0-this.width+this.height},animateLeft:function(){this.onOffTrackContainer.animate({left:this.getTrackPosUnchecked()},100),this.thumb.animate({left:-1},100,"swing",this.uncheck.bind(this))},animateRight:function(){this.onOffTrackContainer.animate({left:0},100),this.thumb.animate({left:this.maxX},100,"swing",this.check.bind(this))},check:function(){this.checked||(this.checked=!0,this.notifyListeners()),this.applyStyles()},uncheck:function(){this.checked&&(this.checked=!1,this.notifyListeners()),this.applyStyles()},toggle:function(){this.checked?(this.checked=!1,this.animateLeft()):(this.checked=!0,this.animateRight()),this.notifyListeners()},notifyListeners:function(){null!=this.listener&&this.listener.call(this,this.name,this.checked)},getValue:function(){return this.checked}}),DG.OnOffSwitchAuto=function(config){var properties=DG.OnOffSwitchProperties;if(config.cls)for(var els=$(config.cls),index=0,i=0,len=els.length;i<len;i++){var elementConfig=jQuery.extend({},config),el=$(els[i]);els[i].id||(els[i].id="dg-switch-"+index,index++),elementConfig.el="#"+els[i].id;for(var j=0;j<properties.length;j++){var attr="data-"+properties[j],val=el.attr(attr);val&&("height"==properties[j]&&(val=parseInt(val)),elementConfig[properties[j]]=val)}new DG.OnOffSwitch(elementConfig)}}; //# sourceMappingURL=on-off-switch.min.js.map