/* ========================================================= * bootstrap-slider.js v2.0.0 * http://www.eyecon.ro/bootstrap-slider * ========================================================= * Copyright 2012 Stefan Petre * * 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(e){var t=function(t,n){this.element=e(t);this.picker=e('
'+'
'+'
'+'
'+'
'+"
"+'
'+"
").insertBefore(this.element).append(this.element);this.id=this.element.data("slider-id")||n.id;if(this.id){this.picker[0].id=this.id}if(typeof Modernizr!=="undefined"&&Modernizr.touch){this.touchCapable=true}var r=this.element.data("slider-tooltip")||n.tooltip;this.tooltip=this.picker.find(".tooltip");this.tooltipInner=this.tooltip.find("div.tooltip-inner");this.orientation=this.element.data("slider-orientation")||n.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")||n.min;this.max=this.element.data("slider-max")||n.max;this.step=this.element.data("slider-step")||n.step;this.value=this.element.data("slider-value")||n.value;if(this.value[1]){this.range=true}this.selection=this.element.data("slider-selection")||n.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 i=this.element.data("slider-handle")||n.handle;switch(i){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=n.formater;this.layout();if(this.touchCapable){this.picker.on({touchstart:e.proxy(this.mousedown,this)})}else{this.picker.on({mousedown:e.proxy(this.mousedown,this)})}if(r==="show"){this.picker.on({mouseenter:e.proxy(this.showTooltip,this),mouseleave:e.proxy(this.hideTooltip,this)})}else{this.tooltip.addClass("hide")}};t.prototype={constructor:t,over:false,inDrag:false,showTooltip:function(){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 n=this.getPercentage(t);if(this.range){var r=Math.abs(this.percentage[0]-n);var i=Math.abs(this.percentage[1]-n);this.dragged=rt){this.percentage[1]=this.percentage[0];this.dragged=0}}this.percentage[this.dragged]=t;this.layout();var n=this.calculateValue();this.element.trigger({type:"slide",value:n}).data("value",n).prop("value",n);return false},mouseup:function(t){if(this.touchCapable){e(document).off({touchmove:this.mousemove,touchend:this.mouseup})}else{e(document).off({mousemove:this.mousemove,mouseup:this.mouseup})}this.inDrag=false;if(this.over==false){this.hideTooltip()}this.element;var n=this.calculateValue();this.element.trigger({type:"slideStop",value:n}).data("value",n).prop("value",n);return false},calculateValue:function(){var e;if(this.range){e=[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=e}else{e=this.min+Math.round(this.diff*this.percentage[0]/100/this.step)*this.step;this.value=[e,this.value[1]]}return e},getPercentage:function(e){if(this.touchCapable){e=e.touches[0]}var t=(e[this.mousePos]-this.offset[this.stylePos])*100/this.size;t=Math.round(t/this.percentage[2])*this.percentage[2];return Math.max(0,Math.min(100,t))},getValue:function(){if(this.range){return this.value}return this.value[0]},setValue:function(e){this.value=e;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()}};e.fn.slider=function(n,r){return this.each(function(){var i=e(this),s=i.data("slider"),o=typeof n==="object"&&n;if(!s){i.data("slider",s=new t(this,e.extend({},e.fn.slider.defaults,o)))}if(typeof n=="string"){s[n](r)}})};e.fn.slider.defaults={min:0,max:10,step:1,orientation:"horizontal",value:5,selection:"before",tooltip:"show",handle:"round",formater:function(e){return e}};e.fn.slider.Constructor=t}(window.jQuery)