jQuery.fn.exists=function(){return this.length>0};!function(a){var o=function(t,e){this.element=a(t);this.picker=a('<div class="slider">'+'<div class="slider-track">'+'<div class="slider-selection"></div>'+'<div class="slider-handle"></div>'+'<div class="slider-handle"></div>'+"</div>"+'<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'+"</div>").insertBefore(this.element).append(this.element);this.id=this.element.data("slider-id")||e.id;if(this.id){this.picker[0].id=this.id}if(typeof Modernizr!=="undefined"&&Modernizr.touch){this.touchCapable=true}var i=this.element.data("slider-tooltip")||e.tooltip;this.tooltip=this.picker.find(".tooltip");this.tooltipInner=this.tooltip.find("div.tooltip-inner");this.orientation=this.element.data("slider-orientation")||e.orientation;switch(this.orientation){case"vertical":this.picker.addClass("slider-vertical");this.stylePos="top";this.mousePos="pageY";this.sizePos="offsetHeight";this.tooltip.addClass("right")[0].style.left="100%";break;default:this.picker.addClass("slider-horizontal").css("width",this.element.outerWidth());this.orientation="horizontal";this.stylePos="left";this.mousePos="pageX";this.sizePos="offsetWidth";this.tooltip.addClass("top")[0].style.top=-this.tooltip.outerHeight()-14+"px";break}this.min=this.element.data("slider-min")||e.min;this.max=this.element.data("slider-max")||e.max;this.step=this.element.data("slider-step")||e.step;this.value=this.element.data("slider-value")||e.value;if(this.value[1]){this.range=true}this.selection=this.element.data("slider-selection")||e.selection;this.selectionEl=this.picker.find(".slider-selection");if(this.selection==="none"){this.selectionEl.addClass("hide")}this.selectionElStyle=this.selectionEl[0].style;this.handle1=this.picker.find(".slider-handle:first");this.handle1Stype=this.handle1[0].style;this.handle2=this.picker.find(".slider-handle:last");this.handle2Stype=this.handle2[0].style;var s=this.element.data("slider-handle")||e.handle;switch(s){case"round":this.handle1.addClass("round");this.handle2.addClass("round");break;case"triangle":this.handle1.addClass("triangle");this.handle2.addClass("triangle");break}if(this.range){this.value[0]=Math.max(this.min,Math.min(this.max,this.value[0]));this.value[1]=Math.max(this.min,Math.min(this.max,this.value[1]))}else{this.value=[Math.max(this.min,Math.min(this.max,this.value))];this.handle2.addClass("hide");if(this.selection=="after"){this.value[1]=this.max}else{this.value[1]=this.min}}this.diff=this.max-this.min;this.percentage=[(this.value[0]-this.min)*100/this.diff,(this.value[1]-this.min)*100/this.diff,this.step*100/this.diff];this.offset=this.picker.offset();this.size=this.picker[0][this.sizePos];this.formater=e.formater;this.layout();if(this.touchCapable){this.picker.on({touchstart:a.proxy(this.mousedown,this)})}else{this.picker.on({mousedown:a.proxy(this.mousedown,this)})}if(i==="show"){this.picker.on({mouseenter:a.proxy(this.showTooltip,this),mouseleave:a.proxy(this.hideTooltip,this)})}else{this.tooltip.addClass("hide")}};o.prototype={constructor:o,over:false,inDrag:false,showTooltip:function(){if(this.orientation=="horizontal"){this.size=this.picker[0][this.sizePos];if(this.range){this.tooltip[0].style[this.stylePos]=this.size*(this.percentage[0]+(this.percentage[1]-this.percentage[0])/2)/100-(this.orientation==="vertical"?this.tooltip.outerHeight()/2:this.tooltip.outerWidth()/2)+"px"}else{this.tooltip[0].style["left"]=this.size*this.percentage[0]/100-this.tooltip.outerWidth()/2+"px";this.tooltip[0].style.top=-this.tooltip.outerHeight()-1+"px";console.log(this.size)}}this.tooltip.addClass("in");this.over=true},hideTooltip:function(){if(this.inDrag===false){this.tooltip.removeClass("in")}this.over=false},layout:function(){this.handle1Stype[this.stylePos]=this.percentage[0]+"%";this.handle2Stype[this.stylePos]=this.percentage[1]+"%";if(this.orientation=="vertical"){this.selectionElStyle.top=Math.min(this.percentage[0],this.percentage[1])+"%";this.selectionElStyle.height=Math.abs(this.percentage[0]-this.percentage[1])+"%"}else{this.selectionElStyle.left=Math.min(this.percentage[0],this.percentage[1])+"%";this.selectionElStyle.width=Math.abs(this.percentage[0]-this.percentage[1])+"%"}if(this.range){this.tooltipInner.text(this.formater(this.value[0])+" : "+this.formater(this.value[1]));this.tooltip[0].style[this.stylePos]=this.size*(this.percentage[0]+(this.percentage[1]-this.percentage[0])/2)/100-(this.orientation==="vertical"?this.tooltip.outerHeight()/2:this.tooltip.outerWidth()/2)+"px"}else{this.tooltipInner.text(this.formater(this.value[0]));this.tooltip[0].style[this.stylePos]=this.size*this.percentage[0]/100-(this.orientation==="vertical"?this.tooltip.outerHeight()/2:this.tooltip.outerWidth()/2)+"px"}},mousedown:function(t){if(this.touchCapable&&t.type==="touchstart"){t=t.originalEvent}this.offset=this.picker.offset();this.size=this.picker[0][this.sizePos];var e=this.getPercentage(t);if(this.range){var i=Math.abs(this.percentage[0]-e);var s=Math.abs(this.percentage[1]-e);this.dragged=i<s?0:1}else{this.dragged=0}this.percentage[this.dragged]=e;this.layout();if(this.touchCapable){a(document).on({touchmove:a.proxy(this.mousemove,this),touchend:a.proxy(this.mouseup,this)})}else{a(document).on({mousemove:a.proxy(this.mousemove,this),mouseup:a.proxy(this.mouseup,this)})}this.inDrag=true;var h=this.calculateValue();this.element.trigger({type:"slideStart",value:h}).trigger({type:"slide",value:h});return false},mousemove:function(t){if(this.touchCapable&&t.type==="touchmove"){t=t.originalEvent}var e=this.getPercentage(t);if(this.range){if(this.dragged===0&&this.percentage[1]<e){this.percentage[0]=this.percentage[1];this.dragged=1}else if(this.dragged===1&&this.percentage[0]>e){this.percentage[1]=this.percentage[0];this.dragged=0}}this.percentage[this.dragged]=e;this.layout();var i=this.calculateValue();this.element.trigger({type:"slide",value:i}).data("value",i).prop("value",i);return false},mouseup:function(t){if(this.touchCapable){a(document).off({touchmove:this.mousemove,touchend:this.mouseup})}else{a(document).off({mousemove:this.mousemove,mouseup:this.mouseup})}this.inDrag=false;if(this.over==false){this.hideTooltip()}this.element;var e=this.calculateValue();this.element.trigger({type:"slideStop",value:e}).data("value",e).prop("value",e);return false},calculateValue:function(){var t;if(this.range){t=[this.min+Math.round(this.diff*this.percentage[0]/100/this.step)*this.step,this.min+Math.round(this.diff*this.percentage[1]/100/this.step)*this.step];this.value=t}else{t=this.min+Math.round(this.diff*this.percentage[0]/100/this.step)*this.step;this.value=[t,this.value[1]]}return t},getPercentage:function(t){if(this.touchCapable){t=t.touches[0]}var e=(t[this.mousePos]-this.offset[this.stylePos])*100/this.size;e=Math.round(e/this.percentage[2])*this.percentage[2];return Math.max(0,Math.min(100,e))},getValue:function(){if(this.range){return this.value}return this.value[0]},setValue:function(t){this.value=t;if(this.range){this.value[0]=Math.max(this.min,Math.min(this.max,this.value[0]));this.value[1]=Math.max(this.min,Math.min(this.max,this.value[1]))}else{this.value=[Math.max(this.min,Math.min(this.max,this.value))];this.handle2.addClass("hide");if(this.selection=="after"){this.value[1]=this.max}else{this.value[1]=this.min}}this.diff=this.max-this.min;this.percentage=[(this.value[0]-this.min)*100/this.diff,(this.value[1]-this.min)*100/this.diff,this.step*100/this.diff];this.layout()}};a.fn.slider=function(s,h){return this.each(function(){var t=a(this),e=t.data("slider"),i=typeof s==="object"&&s;if(!e){t.data("slider",e=new o(this,a.extend({},a.fn.slider.defaults,i)))}if(typeof s=="string"){e[s](h)}})};a.fn.slider.defaults={min:0,max:10,step:1,orientation:"horizontal",value:5,selection:"before",tooltip:"show",handle:"round",formater:function(t){return t}};a.fn.slider.Constructor=o}(window.jQuery);