/** * RightJS-UI Colorpicker v2.2.2 * http://rightjs.org/ui/colorpicker * * Copyright (C) 2010-2012 Nikolay Nemshilov */ var Colorpicker=RightJS.Colorpicker=function(a,b,c,d){function z(a){u.tracking&&u.tracking.trackMove(a)}function y(){u.tracking&&u.tracking.stopTrack()}function i(a,b,e){var f=this.reAnchor||(this.reAnchor=new d.Element("div",{"class":"rui-re-anchor"})).insert(this),g=f.insertTo(a,"after").position(),h=a.dimensions(),i=this,j=c(a.getStyle("borderTopWidth")),k=c(a.getStyle("borderLeftWidth")),l=c(a.getStyle("borderRightWidth")),m=c(a.getStyle("borderBottomWidth")),n=h.top-g.y+j,o=h.left-g.x+k,p=h.width-k-l,q=h.height-j-m;i.setStyle("visibility:hidden").show(null),b==="right"?o+=p-i.size().x:n+=q,i.moveTo(o,n),e&&(b==="left"||b==="right"?i.setHeight(q):i.setWidth(p)),i.setStyle("visibility:visible").hide(null)}function h(a,b,c,e){d.Fx&&(c===undefined&&(c=a.options.fxName,e===undefined&&(e={duration:a.options.fxDuration,onFinish:d(a.fire).bind(a,b)},b==="hide"&&(e.duration=(d.Fx.Durations[e.duration]||e.duration)/2)))),(!d.Fx||!c)&&a.fire(b);return a.$super(c,e)}function e(a,b){b||(b=a,a="DIV");var c=new d.Class(d.Element.Wrappers[a]||d.Element,{initialize:function(b,c){this.key=b;var e=[{"class":"rui-"+b}];this instanceof d.Input||this instanceof d.Form||e.unshift(a),this.$super.apply(this,e),d.isString(c)&&(c=d.$(c)),c instanceof d.Element&&(this._=c._,"$listeners"in c&&(c.$listeners=c.$listeners),c={}),this.setOptions(c,this);return d.Wrapper.Cache[d.$uid(this._)]=this},setOptions:function(a,b){b&&(a=d.Object.merge(a,(new Function("return "+(b.get("data-"+this.key)||"{}")))())),a&&d.Options.setOptions.call(this,d.Object.merge(this.options,a));return this}}),e=new d.Class(c,b);d.Observer.createShortcuts(e.prototype,e.EVENTS||d([]));return e}var f=new d.Class(d.Element,{initialize:function(a,b){this.$super("div",b),this._.innerHTML=a,this.addClass("rui-button"),this.on("selectstart","stopEvent")},disable:function(){return this.addClass("rui-button-disabled")},enable:function(){return this.removeClass("rui-button-disabled")},disabled:function(){return this.hasClass("rui-button-disabled")},enabled:function(){return!this.disabled()},fire:function(){this.enabled()&&this.$super.apply(this,arguments);return this}}),g={show:function(a,b){this.constructor.current=this;return h(this,"show",a,b)},hide:function(a,b){this.constructor.current=null;return h(this,"show",a,b)},showAt:function(a,b,c){this.hide(null).shownAt=a=d.$(a),i.call(this,a,b,c);return this.show()},toggleAt:function(a,b,c){return this.hidden()?this.showAt(a,b,c):this.hide()}},j={assignTo:function(a,b){a=d.$(a),b=d.$(b),b?(b[this.key]=this,b.assignedInput=a):a[this.key]=this;var c=d(function(){this.visible()&&(!this.showAt||this.shownAt===a)&&this.setValue(a.value())}).bind(this);a.on({keyup:c,change:c}),this.onChange(function(){(!this.showAt||this.shownAt===a)&&a.setValue(this.getValue())});return this}},k=d,l=d.$,m=d.$w,n=d.$$,o=d.$E,p=d.$A,q=d.isArray,r=d.Class,s=d.Element,t=d.Input,u=new e({include:[g,j],extend:{version:"2.2.2",EVENTS:m("change show hide done"),Options:{format:"hex",update:null,updateBg:null,updateBorder:null,updateColor:null,trigger:null,fxName:"fade",fxDuration:"short",cssRule:"*[data-colorpicker]"},i18n:{Done:"Done"},hideAll:function(){n("div.rui-colorpicker").each(function(a){a instanceof u&&!a.inlined()&&a.hide()})}},initialize:function(a){this.$super("colorpicker",a).addClass("rui-panel").insert([this.field=new v,this.colors=new w,this.controls=new x]).on({mousedown:this.startTrack,touchstart:this.startTrack,keyup:this.recalc,blur:this.update,focus:this.cancelTimer,done:this.done}),this.options.update&&this.assignTo(this.options.update,this.options.trigger),this.options.updateBg&&this.updateBg(this.options.updateBg),this.options.updateBorder&&this.updateBorder(this.options.updateBorder),this.options.updateColor&&this.updateColor(this.options.updateColor),this.tint=k([1,0,0]),this.satur=0,this.bright=1,this.color=k([255,255,255]),this.recalc().update()},setValue:function(a){var b=q(a)?a:this.toColor(a);b&&b.length===3&&(b=b.map(function(a){return this.bound(c(""+a),0,255)},this),this.color=b,this.color2tint().update(),this.colors.size().y||this.update.bind(this).delay(20));return this},getValue:function(a){return a?this.color:this[this.options.format==="rgb"?"toRgb":"toHex"]()},updateBg:function(a){var b=l(a);b&&this.onChange(k(function(a){b._.style.backgroundColor=this.toRgb()}).bind(this));return this},updateColor:function(a){var b=l(a);b&&this.onChange(k(function(a){b._.style.color=this.toRgb()}).bind(this));return this},updateBorder:function(a){var b=l(a);b&&this.onChange(k(function(a){b._.style.borderColor=this.toRgb()}).bind(this));return this},insertTo:function(a,b){return this.$super(a,b).addClass("rui-colorpicker-inline")},inlined:function(){return this.hasClass("rui-colorpicker-inline")},done:function(){this.inlined()||this.hide();return this},setOptions:function(a){a=a||{},this.$super(a,l(a.trigger||a.update))},update:function(){this.field._.style.backgroundColor="rgb("+this.tint.map(function(a){return b.round(a*255)})+")";var a=this.color,c=this.controls;c.preview._.style.backgroundColor=c.display._.value=this.toHex(),c.rDisplay._.value=a[0],c.gDisplay._.value=a[1],c.bDisplay._.value=a[2];var d=this.field.pointer._.style,e=this.field.size(),f=e.y-this.bright*e.y-2,g=this.satur*e.x-2;d.top=this.bound(f,0,e.y-5)+"px",d.left=this.bound(g,0,e.x-5)+"px";var h=this.tint,i;e=this.colors.size(),h[1]==0?i=h[0]==1?h[2]:2-h[0]:h[0]==0?i=2+(h[2]==1?h[1]:2-h[2]):i=4+(h[1]==1?h[0]:2-h[1]),i=i/6*e.y,this.colors.pointer._.style.top=this.bound(i,0,e.y-4)+"px",this.prevColor!==""+this.color&&(this.fire("change",{value:this.color}),this.prevColor=""+this.color);return this},recalc:function(a){if(a){var b=a.target,c=b._.value,d=p(this.color),e=!1;b===this.controls.display&&/#\w{6}/.test(c)?e=d=this.toColor(c):/^\d+$/.test(c)&&(d[b._.cIndex]=c,e=!0),e&&this.setValue(d)}else this.tint2color();return this},startTrack:function(a){this.stopTrack(),this.cancelTimer(),a.target===this.field.pointer?a.target=this.field:a.target===this.colors.pointer&&(a.target=this.colors);if(a.target===this.field||a.target===this.colors)a.stop(),u.tracking=this,a.target.tracking=!0,this.trackMove(a)},stopTrack:function(){u.tracking=!1,this.field.tracking=!1,this.colors.tracking=!1},trackMove:function(a){var b,c=a.position(),d,e;this.field.tracking?b=this.field.dimensions():this.colors.tracking&&(b=this.colors.dimensions());if(b){d=this.bound(c.y-b.top,0,b.height),e=this.bound(c.x-b.left,0,b.width);if(this.field.tracking)this.satur=e/b.width,this.bright=1-d/b.height;else if(this.colors.tracking){d==b.height&&(d=b.height-.1);var f=b.height/6,g=this.tint=[0,0,0],h=d%f/f,i=1-h;dc?c:d:(d>c&&(d=c),d