sonarr-repo-only/NzbDrone.Web/Scripts/2011.2.712/telerik.slider.min.js

1 line
19 KiB
JavaScript

(function(g){var l=g.telerik;l.scripts.push("telerik.slider.js");l.slider=function(n,o){var p=g(n);this.element=n;o.distance=o.maxValue-o.minValue;g.extend(this,o);o.position=this.orientation=="horizontal"?"left":"bottom";o.size=this.orientation=="horizontal"?"width":"height";o.orientation=this.orientation;k(n,o);this.wrapper=p.closest(".t-slider");this.trackDiv=this.wrapper.find(".t-slider-track");l.slider.setTrackDivWidth(this.wrapper,o);this.maxSelection=this.trackDiv[o.size]();var r=this.maxSelection/((this.maxValue-this.minValue)/this.smallStep);var q=l.slider.calculateItemsWidth(this.wrapper,o,Math.floor(this.distance/this.smallStep));if(o.tickPlacement!="none"&&r>=2){this.trackDiv.before(c(o));l.slider.setItemsWidth(this.wrapper,this.trackDiv,q,o);l.slider.setItemsTitle(this.wrapper,o);l.slider.setItemsLargeTick(this.wrapper,o)}l.slider.calculateSteps.call(this,q);var m={element:n,dragHandle:this.wrapper.find(".t-draghandle"),orientation:o.orientation,size:o.size,position:o.position,owner:this};this._setValueInRange(o.val);this[o.enabled?"enable":"disable"]();new l.slider.Selection(m);this._drag=new l.slider.Drag(m);this.keyMap={37:h(o.smallStep),40:h(o.smallStep),39:j(o.smallStep),38:j(o.smallStep),35:e(o.maxValue),36:e(o.minValue),33:j(o.largeStep),34:h(o.largeStep)};l.bind(this,{slide:this.onSlide,change:this.onChange,load:this.onLoad})};g.extend(l.slider,{setTrackDivWidth:function(o,p){var n=o.find(".t-slider-track");var m=parseFloat(n.css(p.position),10)*2;n[p.size]((o[p.size]()-2)-m)},setItemsWidth:function(u,q,p,n){var m=Math.floor(n.distance/n.smallStep),s=u.find(".t-tick"),r=0,t=q[n.size]();arr=g.extend([],p);if(n.orientation=="horizontal"){for(var o=0;o<s.length-2;o++){g(s[o+1])[n.size](arr[o])}}else{arr=arr.reverse();for(var o=2;o<s.length;o++){g(s[o-1])[n.size](arr[o])}}if(n.orientation=="horizontal"){g(s[0]).addClass("t-first")[n.size](arr[m]);g(s[s.length-1]).addClass("t-last")[n.size](arr[m-1])}else{g(s[s.length-1]).addClass("t-first")[n.size](arr[0]);g(s[0]).addClass("t-last")[n.size](arr[1])}if(n.distance%n.smallStep!=0&&n.orientation=="vertical"){for(var o=0;o<arr.length;o++){r+=p[o]}u.find(".t-slider-items").css("padding-top",29+(t-r))}},setItemsTitle:function(o,p){var q=o.find(".t-tick"),n=p.minValue;if(p.orientation=="horizontal"){for(var m=0;m<q.length;m++){g(q[m]).attr("title",l.formatString(p.tooltip.format||"{0}",parseFloat(n.toFixed(3),10)));n+=p.smallStep}}else{for(var m=q.length-1;m>=0;m--){g(q[m]).attr("title",l.formatString(p.tooltip.format||"{0}",parseFloat(n.toFixed(3),10)));n+=p.smallStep}}},setItemsLargeTick:function(r,o){if((1000*o.largeStep)%(1000*o.smallStep)==0){var q=r.find(".t-tick"),p={},m=parseFloat((o.largeStep/o.smallStep).toFixed(3),10);if(o.orientation=="horizontal"){for(var n=0;n<q.length;n=parseFloat((n+m).toFixed(3),10)){p=g(q[n]);p.addClass("t-tick-large").html(g("<span class='t-label'></span>").html(p.attr("title")))}}else{for(var n=q.length-1;n>=0;n=parseFloat((n-m).toFixed(3),10)){p=g(q[n]);p.addClass("t-tick-large").html(g("<span class='t-label'></span>").html(p.attr("title")));if(n!=0&&n!=q.length-1){p.css("line-height",p[o.size]()+"px")}}}}},calculateItemsWidth:function(t,o,n){var s=parseFloat(t.find(".t-slider-track").css(o.size))+1,p=s/o.distance;if((o.distance/o.smallStep)-Math.floor(o.distance/o.smallStep)>0){s-=((o.distance%o.smallStep)*p)}var m=s/n,r=new Array();for(var q=0;q<n-1;q++){r[q]=m}r[n-1]=r[n]=m/2;return this.roudWidths(r)},roudWidths:function(m){var n=0;for(i=0;i<m.length;i++){n+=(m[i]-Math.floor(m[i]));m[i]=Math.floor(m[i])}n=Math.round(n);return this.addAdditionalSize(n,m)},addAdditionalSize:function(n,m){if(n==0){return m}var o=parseFloat(m.length-1)/parseFloat(n==1?n:n-1);for(var p=0;p<n;p++){m[parseInt(Math.round(o*p))]+=1}return m},getValueFromPosition:function(o,p,r){var m=Math.max(r.smallStep*(r.maxSelection/r.distance),0),q=0,s=(m/2);if(r.orientation=="horizontal"){q=o-p.startPoint}else{q=p.startPoint-o}if(r.maxSelection-((parseInt(r.maxSelection%m)-3)/2)<q){return r.maxValue}for(var n=0;n<r._pixelStepsArray.length;n++){if(Math.abs(r._pixelStepsArray[n]-q)-1<=s){return parseFloat(r._valuesArray[n].toFixed(3),10)}}},getDragableArea:function(n,o,m){var q=n.offset().left,p=n.offset().top;return{startPoint:m=="horizontal"?q:p+o,endPoint:m=="horizontal"?q+o:p}},calculateSteps:function(o){var q=this,p=q.minValue,n=0,m=o.length;i=1;o.splice(0,0,o.pop()*2);o.splice(m,1,o.pop()*2);q._pixelStepsArray=[n];q._valuesArray=[p];if(m==0){return}while(i<m){n+=(o[i-1]+o[i])/2;q._pixelStepsArray[i]=n;q._valuesArray[i]=p+=q.smallStep;i++}var r=q.maxValue%q.smallStep==0?m-1:m;q._pixelStepsArray[r]=q.maxSelection;q._valuesArray[r]=q.maxValue}});function j(m){return function(n){return n+m}}function h(m){return function(n){return n-m}}function e(m){return function(){return m}}function a(m){return(m+"").replace(".",l.cultureInfo.numericdecimalseparator)}l.slider.prototype={enable:function(){this.wrapper.removeAttr("disabled").removeClass("t-state-disabled").addClass("t-state-default");var m=g.proxy(function(r){if(g(r.target).hasClass("t-draghandle")){return}var q=this.orientation=="horizontal"?r.pageX:r.pageY,p=l.slider.getDragableArea(this.trackDiv,this.maxSelection,this.orientation);this._update(l.slider.getValueFromPosition(q,p,this));this._drag.start(r)},this);this.wrapper.find(".t-tick").bind("mousedown",m).end().find(".t-slider-track").bind("mousedown",m);var o=g.proxy(function(q,r){var p=Math.ceil(this.val/this.smallStep);if(p>=this._valuesArray.length-1||p<=0){this._setValueInRange(this.val+(r*this.smallStep))}else{this._setValueInRange(this._valuesArray[p+(r*1)])}},this);if(this.showButtons){var n=g.proxy(function(p,q){if(p.which==1){o(p,q);this.timeout=setTimeout(g.proxy(function(){this.timer=setInterval(function(){o(p,q)},60)},this),200)}},this);this.wrapper.find(".t-button").unbind("mousedown").unbind("mouseup").bind("mouseup",g.proxy(function(p){this._clearTimer()},this)).unbind("mouseover").bind("mouseover",function(p){g(p.currentTarget).addClass("t-state-hover")}).unbind("mouseout").bind("mouseout",g.proxy(function(p){g(p.currentTarget).removeClass("t-state-hover");this._clearTimer()},this)).eq(0).bind("mousedown",g.proxy(function(p){n(p,1)},this)).end().eq(1).bind("mousedown",g.proxy(function(p){n(p,-1)},this))}this.wrapper.find(".t-draghandle").bind({keydown:g.proxy(this._keydown,this)});this.enabled=true},disable:function(){this.wrapper.attr("disabled","disabled").removeClass("t-state-default").addClass("t-state-disabled");var m=l.preventDefault;this.wrapper.find(".t-button").unbind("mousedown").bind("mousedown",m).unbind("mouseup").bind("mouseup",m).unbind("mouseleave").bind("mouseleave",m).unbind("mouseover").bind("mouseover",m);this.wrapper.find(".t-tick").unbind("mousedown").end().find(".t-slider-track").unbind("mousedown");this.wrapper.find(".t-draghandle").unbind("keydown").bind("keydown",m);this.enabled=false},_update:function(m){var n=this.value()!=m;this.value(m);if(n){l.trigger(this.element,"change",{value:this.val})}},value:function(m){m=parseFloat(parseFloat(m,10).toFixed(3),10);if(isNaN(m)){return this.val}if(m>=this.minValue&&m<=this.maxValue){if(this.val!=m){g(this.element).attr("value",a(m));this.val=m;this.refresh()}}},refresh:function(){l.trigger(this.element,"t:moveSelection",{value:this.val})},_clearTimer:function(m){clearTimeout(this.timeout);clearInterval(this.timer)},_keydown:function(m){if(m.keyCode in this.keyMap){this._setValueInRange(this.keyMap[m.keyCode](this.val));m.preventDefault()}},_setValueInRange:function(m){m=parseFloat(parseFloat(m,10).toFixed(3),10);if(isNaN(m)){this._update(this.minValue);return}m=Math.max(m,this.minValue);m=Math.min(m,this.maxValue);this._update(m)}};l.slider.Selection=function(o){var p=g(o.element);function n(t){var v=o.owner,s=t-v.minValue,w=Math.ceil(s/v.smallStep),r=v._pixelStepsArray[w],q=v.trackDiv.find(".t-slider-selection"),u=parseInt(o.dragHandle[o.size]()/2,10)+1;q[o.size](r);o.dragHandle.css(o.position,r-u)}n(parseFloat(p.val(),10));var m=function(q){n(parseFloat(q.value,10))};p.bind({change:m,slide:m,"t:moveSelection":m})};l.slider.Drag=function(n){n.dragHandleSize=n.dragHandle[n.size]();g.extend(this,n);var m="";switch(n.type){case"firstHandle":m=".t-draghandle:first";break;case"lastHandle":m=".t-draghandle:last";break;default:m=".t-draghandle";break}this.draggable=new l.draggable({distance:0,owner:n.owner.wrapper[0],selector:m,scope:n.element.id,start:g.proxy(this._start,this),drag:g.proxy(this.drag,this),stop:g.proxy(this.stop,this)})};l.slider.Drag.prototype={start:function(m){this.draggable._startDrag(m.currentTarget,{x:m.pageX,y:m.pageY})},_start:function(p){if(!this.owner.enabled){return false}g(this.element).unbind("mouseover");this.val=parseFloat(g(this.element).val());this.dragableArea=l.slider.getDragableArea(this.owner.trackDiv,this.owner.maxSelection,this.orientation);this.step=Math.max(this.owner.smallStep*(this.owner.maxSelection/this.owner.distance),0);this.selectionStart=this.owner.selectionStart;this.selectionEnd=this.owner.selectionEnd;this.oldVal=this.val;this.format=this.owner.tooltip.format||"{0}";if(this.type){this.owner._setZIndex(this.type)}if(this.owner.tooltip.enabled){this.tooltipDiv=g("<div class='t-widget t-tooltip'><!-- --></div>").appendTo(document.body);if(this.type){var n=l.formatString(this.format,this.selectionStart),m=l.formatString(this.format,this.selectionEnd);this.tooltipDiv.html(n+" - "+m)}else{var o="t-callout-";if(this.orientation=="horizontal"){if(this.owner.tickPlacement=="topLeft"){o+="n"}else{o+="s"}}else{if(this.owner.tickPlacement=="topLeft"){o+="w"}else{o+="e"}}this.tooltipInnerDiv="<div class='t-callout "+o+"'><!-- --></div>";this.tooltipDiv.html(l.formatString(this.owner.tooltip.format||"{0}",this.val)+this.tooltipInnerDiv)}this.moveTooltip(this.tooltipDiv)}},drag:function(o){if(this.orientation=="horizontal"){this.val=this.horizontalDrag(o)}else{this.val=this.verticalDrag(o)}if(this.oldVal!=this.val){this.oldVal=this.val;if(this.type){if(this.type=="firstHandle"){if(this.val<this.selectionEnd){this.selectionStart=this.val}else{this.selectionStart=this.selectionEnd=this.val}}else{if(this.val>this.selectionStart){this.selectionEnd=this.val}else{this.selectionStart=this.selectionEnd=this.val}}l.trigger(this.element,"slide",{values:[this.selectionStart,this.selectionEnd]});if(this.owner.tooltip.enabled){var n=l.formatString(this.format,this.selectionStart),m=l.formatString(this.format,this.selectionEnd);this.tooltipDiv.html(n+" - "+m)}}else{l.trigger(this.element,"slide",{value:this.val});if(this.owner.tooltip.enabled){this.tooltipDiv.html(l.formatString(this.format,this.val)+this.tooltipInnerDiv)}}if(this.owner.tooltip.enabled){this.moveTooltip(this.tooltipDiv)}}},stop:function(m){if(m.keyCode==27){this.owner.refresh()}else{if(this.type){this.owner._update(this.selectionStart,this.selectionEnd)}else{this.owner._update(this.val)}}if(this.owner.tooltip.enabled){this.tooltipDiv.remove()}g(this.element).bind("mouseover");return false},moveTooltip:function(s){var r=0,p=0;if(this.type){var o=this.owner.wrapper.find(".t-draghandle"),n=o.eq(0).offset(),t=o.eq(1).offset();if(this.orientation=="horizontal"){r=t.top;p=n.left+((t.left-n.left)/2)}else{r=n.top+((t.top-n.top)/2);p=t.left}}else{var q=this.dragHandle.offset();r=q.top;p=q.left}var m=s[this.size]()/2;if(this.orientation=="horizontal"){p-=m;if(this.owner.tickPlacement!="topLeft"){r-=35}else{r+=33}}else{r-=m;if(this.owner.tickPlacement!="topLeft"){p-=s.width()+23}else{p+=31}}s.css({top:r,left:p})},horizontalDrag:function(m){var n=0;if(this.dragableArea.startPoint<m.pageX&&m.pageX<this.dragableArea.endPoint){n=l.slider.getValueFromPosition(m.pageX,this.dragableArea,this.owner)}else{if(m.pageX>=this.dragableArea.endPoint){n=this.owner.maxValue}else{n=this.owner.minValue}}return n},verticalDrag:function(m){var n=0;if(this.dragableArea.startPoint>m.pageY&&m.pageY>this.dragableArea.endPoint){n=l.slider.getValueFromPosition(m.pageY,this.dragableArea,this.owner)}else{if(m.pageY<=this.dragableArea.endPoint){n=this.owner.maxValue}else{n=this.owner.minValue}}return n}};function b(n,m){var o=g(m),r=n.orientation=="horizontal"?" t-slider-horizontal":" t-slider-vertical",p;if(n.tickPlacement=="bottomRight"){p=" t-slider-bottomright"}else{if(n.tickPlacement=="topLeft"){p=" t-slider-topleft"}}var q=n.style?n.style:o.attr("style");return new l.stringBuilder().cat("<div class='t-widget t-slider").cat(r).catIf(" ",o.attr("class"),o.attr("class")).cat("'").catIf(" style='",q,"'",q).cat(">").cat("<div class='t-slider-wrap").catIf(" t-slider-buttons",n.showButtons).catIf(p,p).cat("'></div></div>").string()}function d(p,o){var n,m=p.orientation=="horizontal";if(o=="increase"){n=m?"t-arrow-next":"t-arrow-up"}else{n=m?"t-arrow-prev":"t-arrow-down"}return new l.stringBuilder().cat("<a ").cat("class='t-button ").cat("t-button-"+o).cat("'><span class='t-icon ").cat(n).cat("' title='").cat(p[o+"ButtonTitle"]).cat("'>").cat(p[o+"ButtonTitle"]).cat("</span></a>").string()}function c(m){return new l.stringBuilder().cat("<ul class='t-reset t-slider-items'>").rep("<li class='t-tick'>&nbsp;</li>",(Math.floor((m.distance/m.smallStep).toFixed(3),10)+1)).cat("</ul>").string()}function f(m){var n=m.is("input")?1:2;return new l.stringBuilder().cat("<div class='t-slider-track'>").cat("<div class='t-slider-selection'><!-- --></div>").cat("<a href='javascript:void(0)' class='t-draghandle' title='Drag'>Drag</a>").catIf("<a href='javascript:void(0)' class='t-draghandle t-draghandle1' title='Drag'>Drag</a>",n>1).cat("</div>").string()}function k(m,n){var o=g(m);o.val(n.val);o.wrap(b(n,m)).hide();if(n.showButtons){o.before(d(n,"increase")).before(d(n,"decrease"))}o.before(f(o))}g.fn.tSlider=function(m){return l.create(this,{name:"tSlider",init:function(n,o){return new l.slider(n,o)},options:m})};g.fn.tSlider.defaults={enabled:true,minValue:0,maxValue:10,val:0,smallStep:1,largeStep:5,showButtons:true,increaseButtonTitle:"Increase",decreaseButtonTitle:"Decrease",orientation:"horizontal",tickPlacement:"both",tooltip:{enabled:true,format:"{0}"}};l.rangeSlider=function(m,n){var o=g(m);this.element=m;n.distance=n.maxValue-n.minValue;g.extend(this,n);n.position=this.orientation=="horizontal"?"left":"bottom";n.size=this.orientation=="horizontal"?"width":"height";k(m,n);this.wrapper=o.closest(".t-slider");this.trackDiv=this.wrapper.find(".t-slider-track");l.slider.setTrackDivWidth(this.wrapper,n);this.maxSelection=this.trackDiv[n.size]();var q=this.maxSelection/((this.maxValue-this.minValue)/this.smallStep);var p=l.slider.calculateItemsWidth(this.wrapper,n,Math.floor(this.distance/this.smallStep));if(n.tickPlacement!="none"&&q>=2){this.trackDiv.before(c(n));l.slider.setItemsWidth(this.wrapper,this.trackDiv,p,n);l.slider.setItemsTitle(this.wrapper,n);l.slider.setItemsLargeTick(this.wrapper,n)}l.slider.calculateSteps.call(this,p);this._correctValues(this.selectionStart,this.selectionEnd);var s={element:m,type:"firstHandle",dragHandle:this.wrapper.find(".t-draghandle:first"),orientation:n.orientation,size:n.size,position:n.position,owner:this};this._firstHandleDrag=new l.slider.Drag(s);new l.rangeSlider.Selection(s);var r={element:m,type:"lastHandle",dragHandle:this.wrapper.find(".t-draghandle:last"),orientation:n.orientation,size:n.size,position:n.position,owner:this};this._lastHandleDrag=new l.slider.Drag(r);this[n.enabled?"enable":"disable"]();this.keyMap={37:h(n.smallStep),40:h(n.smallStep),39:j(n.smallStep),38:j(n.smallStep),35:e(n.maxValue),36:e(n.minValue),33:j(n.largeStep),34:h(n.largeStep)};l.bind(this,{slide:this.onSlide,change:this.onChange,load:this.onLoad})};l.rangeSlider.prototype={enable:function(){this.wrapper.removeAttr("disabled").removeClass("t-state-disabled").addClass("t-state-default");var m=g.proxy(function(q){if(g(q.target).hasClass("t-draghandle")){return}var o=this.orientation=="horizontal"?q.pageX:q.pageY,n=l.slider.getDragableArea(this.trackDiv,this.maxSelection,this.orientation),p=l.slider.getValueFromPosition(o,n,this);if(p<this.selectionStart){this._setValueInRange(p,this.selectionEnd);this._firstHandleDrag.start(q)}else{if(p>this.selectionEnd){this._setValueInRange(this.selectionStart,p);this._lastHandleDrag.start(q)}else{if(p-this.selectionStart<=this.selectionEnd-p){this._setValueInRange(p,this.selectionEnd);this._firstHandleDrag.start(q)}else{this._setValueInRange(this.selectionStart,p);this._lastHandleDrag.start(q)}}}},this);this.wrapper.find(".t-tick").bind("mousedown",m).end().find(".t-slider-track").bind("mousedown",m);this.wrapper.find(".t-draghandle").eq(0).bind({keydown:g.proxy(function(n){this._keydown(n,true)},this)}).end().eq(1).bind({keydown:g.proxy(function(n){this._keydown(n,false)},this)});this.enabled=true},disable:function(){this.wrapper.attr("disabled","disabled").removeClass("t-state-default").addClass("t-state-disabled");this.wrapper.find(".t-tick").unbind("mousedown").end().find(".t-slider-track").unbind("mousedown");this.wrapper.find(".t-draghandle").unbind("keydown").bind("keydown",l.preventDefault);this.enabled=false},_keydown:function(p,m){var o=this.selectionStart,n=this.selectionEnd;if(p.keyCode in this.keyMap){if(m){o=this.keyMap[p.keyCode](o);if(o>n){n=o}}else{n=this.keyMap[p.keyCode](n);if(n<o){o=n}}this._setValueInRange(o,n);p.preventDefault()}},_update:function(n,m){var p=this.values();var o=p[0]!=n||p[1]!=m;this.values(n,m);if(o){l.trigger(this.element,"change",{values:[n,m]})}},values:function(n,m){var o=[this.selectionStart,this.selectionEnd];n=parseFloat(parseFloat(n,10).toFixed(3),10);if(isNaN(n)){return o}m=parseFloat(parseFloat(m,10).toFixed(3),10);if(isNaN(m)){return o}if(n>=this.minValue&&n<=this.maxValue&&m>=this.minValue&&m<=this.maxValue&&n<=m){if(this.selectionStart!=n||this.selectionEnd!=m){g(this.element).find("input").eq(0).attr("value",a(n)).end().eq(1).attr("value",a(m));this.selectionStart=n;this.selectionEnd=m;this.refresh()}}},refresh:function(){l.trigger(this.element,"t:moveSelection",{values:[this.selectionStart,this.selectionEnd]});if(this.selectionStart==this.maxValue&&this.slectionEnd==this.maxValue){this._setZIndex("firstHandle")}},_setValueInRange:function(m,n){m=Math.max(m,this.minValue);m=Math.min(m,this.maxValue);n=Math.max(n,this.minValue);n=Math.min(n,this.maxValue);if(this.selectionStart==this.maxValue&&this.slectionEnd==this.maxValue){this._setZIndex("firstHandle")}this._update(m,n)},_correctValues:function(n,m){if(n>=m){this._setValueInRange(m,n)}else{this._setValueInRange(n,m)}},_setZIndex:function(o){var q=this.wrapper.find(".t-draghandle"),m=q.eq(0),p=q.eq(1),n="z-index";if(o=="firstHandle"){m.css(n,"1");p.css(n,"")}else{m.css(n,"");p.css(n,"1")}}};l.rangeSlider.Selection=function(m){var q=m.owner;function r(t){var z=t[0]-q.minValue,x=t[1]-q.minValue,y=Math.ceil(z/q.smallStep),v=Math.ceil(x/q.smallStep),u=q._pixelStepsArray[y],w=q._pixelStepsArray[v],s=q.wrapper.find(".t-draghandle"),A=parseInt(s.eq(0)[m.size]()/2,10)+1;s.eq(0).css(m.position,u-A).end().eq(1).css(m.position,w-A);o(u,w)}function o(v,t){var u=0,w=0,s=q.trackDiv.find(".t-slider-selection");u=Math.abs(v-t);w=v<t?v:t;s[m.size](u);s.css(m.position,w-1)}var p=g(q.element).find("input");r([parseFloat(p[0].getAttribute("value"),10),parseFloat(p[1].getAttribute("value"),10)]);var n=function(s){r(s.values)};g(q.element).bind({change:n,slide:n,"t:moveSelection":n})};g.fn.tRangeSlider=function(m){return l.create(this,{name:"tRangeSlider",init:function(n,o){return new l.rangeSlider(n,o)},options:m})};g.fn.tRangeSlider.defaults={enabled:true,minValue:0,maxValue:10,slectionStart:0,slectionEnd:10,smallStep:1,largeStep:5,orientation:"horizontal",tickPlacement:"both",tooltip:{enabled:true,format:"{0}"}}})(jQuery);