/** * RightJS UI Slider unit * http://rightjs.org/ui/slider * * Copyright (C) 2009-2010 Nikolay Nemshilov */ var Slider=RightJS.Slider=function(j,k,e){var h=e.$,m=e.$$,n=e.$w,l=e.$E,o=e.$A,p=e.isHash,q=e.Element,g=new (function(a,b){if(!b){b=a;a="DIV"}var f=new e.Wrapper(e.Element.Wrappers[a]||e.Element,{initialize:function(c,d){this.key=c;var i=[{"class":"rui-"+c}];this instanceof e.Input||this instanceof e.Form||i.unshift(a);this.$super.apply(this,i);if(e.isString(d))d=e.$(d);if(d instanceof e.Element){this._=d._;if("$listeners"in d)d.$listeners=d.$listeners;d={}}this.setOptions(d,this);return this},setOptions:function(c, d){d=d||this;e.Options.setOptions.call(this,e.Object.merge(c,eval("("+(d.get("data-"+this.key)||"{}")+")")));return this}});f=new e.Wrapper(f,b);e.Observer.createShortcuts(f.prototype,f.EVENTS||[]);return f})({include:{assignTo:function(a){var b=e(function(c,d){if(c=h(c))c[c.setValue?"setValue":"update"](d.target.getValue())}).curry(a),f=e(function(c,d){(c=h(c))&&c.onChange&&c.onChange(e(function(){this.setValue(c.value())}).bind(d))}).curry(a);if(h(a)){b({target:this});f(this)}else h(j).onReady(e(function(){b({target:this}); f(this)}.bind(this)));return this.onChange(b)}},extend:{version:"2.0.0",EVENTS:n("change"),Options:{min:0,max:100,snap:0,value:null,direction:"x",update:null,round:0},current:false},initialize:function(){var a=o(arguments).compact(),b=a.pop();a=a.pop();if(!p(b)||b instanceof q){a=h(a||b);b={}}this.$super("slider",a).setOptions(b).on("selectstart","stopEvent");this.level=this.first(".level")||l("div",{"class":"level"}).insertTo(this);this.handle=this.first(".handle")||l("div",{"class":"handle"}).insertTo(this); b=this.options;this.value=b.value===null?b.min:b.value;b.update&&this.assignTo(b.update);if(b.direction==="y")this.addClass("rui-slider-vertical");else if(this.hasClass("rui-slider-vertical"))b.direction="y";this.setValue(this.value)},setValue:function(a){return this.precalc().shiftTo(a)},getValue:function(){return this.value},insertTo:function(a,b){return this.$super(a,b).setValue(this.value)},precalc:function(){var a=this.options.direction==="x",b=this.handle.setStyle(a?{left:0}:{bottom:0}).dimensions(), f=this.hSize=a?b.width:b.height,c=this.dims=this.dimensions();this.offset=a?b.left-c.left:c.top+c.height-b.top-f;this.space=(a?c.width-f-this.offset*2:c.height-f)-this.offset*2;return this},start:function(a){return this.precalc().e2val(a)},move:function(a){return this.e2val(a)},shiftTo:function(a){var b=this.options,f=k.pow(10,b.round),c=b.direction==="x";a=k.round(a*f)/f;if(ab.max)a=b.max;if(b.snap){f=b.snap;var d=a%f;a=d0?b:0)+2+"px";if(a!==this.value){this.value=a;this.fire("change",{value:a})}return this},e2val:function(a){var b=this.options,f=b.direction==="x",c=this.dims,d=this.offset,i=this.space;a=a.position()[f?"x":"y"]-d-this.hSize/2;c=(b.max-b.min)/i*(a-(f?c.left+d:c.top+d));return this.shiftTo(f?b.min+c:b.max-c)}});h(j).on({ready:function(){m(".rui-slider").each(function(a){a instanceof g||new g(a)})},mousedown:function(a){var b=a.find(".rui-slider"); if(b){a.stop();b instanceof g||(b=new g(b));g.current=b.start(a)}},mousemove:function(a){g.current&&g.current.move(a)},mouseup:function(){if(g.current)g.current=false}});h(window).onBlur(function(){if(g.current)g.current=false});j.write(''); return g}(document,Math,RightJS);