8 | !function(a,b,c,d){a.colorpickle=function(c,d){var f,g,h,i,j,k,l,m,n,e={clickToggle:!1,closeOnOk:!1,closeOnCancel:!1,draggable:!1,hex:null,hsl:null,hslSliders:!0,modal:!1,mode:"hex",onCancel:null,onChange:null,onInit:null,onOk:null,onTop:!1,rgb:[255,140,60],rgbSliders:!0,showCancel:!1,showHex:!0,showOk:!1,showSLGradient:!0,showSwatch:!0,textCancel:"Cancel",textOk:"Ok",theme:null,visible:!0,width:null},o=a("div.colorpickle").length+1,p="colorpickle"+o,q=!1,r="#"+p+" .rWrapper",s="#"+p+" .gWrapper",t="#"+p+" .bWrapper",u="#"+p+" .hWrapper",v="#"+p+" .sWrapper",w="#"+p+" .lWrapper",x="#"+p+" .r",y="#"+p+" .g",z="#"+p+" .b",A="#"+p+" .h",B="#"+p+" .s",C="#"+p+" .l",D="#"+p+" .rWrapper .sliderBg",E="#"+p+" .gWrapper .sliderBg",F="#"+p+" .bWrapper .sliderBg",H="#"+p+" .sWrapper .sliderBg",I="#"+p+" .lWrapper .sliderBg",J="#"+p+" .rInput",K="#"+p+" .gInput",L="#"+p+" .bInput",M="#"+p+" .hInput",N="#"+p+" .sInput",O="#"+p+" .lInput",P="#"+p+" .colorPickerWrapper",Q="#"+p+" .colorPickerBg",S="#"+p+" .colorPickerIndicator",T="#"+p+"Icon",U="#"+p+" .swatch",V=this;V.settings={};var W=a(c),X=c;V.init=function(){if(V.settings=a.extend({},e,d),V.rgb=null,V.hsl=null,V.hex=null,W.is("div")?a(X).append('<div id="'+p+'" class="colorpickle"></div>'):(1==V.settings.modal?a("body").append('<div id="'+p+'" class="colorpickle"></div>'):a('<div id="'+p+'" class="colorpickle"></div>').insertAfter(W),a('<button type="button" id="'+p+'Icon" class="colorPickerIcon"> </button>').insertAfter(W)),null!=V.settings.theme&&a("#"+p).addClass("colorpickle-theme-"+V.settings.theme),W.is("input")&&a(X).keypress(function(){return!1}),1==V.settings.onTop&&a("#"+p).addClass("colorpickleOnTop"),null!=V.settings.width&&a("#"+p).css("width",V.settings.width),1==V.settings.draggable&&(a("#"+p).append('<div class="dragHandle"></div>'),a("#"+p+" .dragHandle").mousedown(function(b){var c=a(this).parent().offset(),d=b.pageX-c.left,e=b.pageY-c.top;a("body").mousemove(function(b){a("#"+p).offset({top:b.pageY-e,left:b.pageX-d})}),a("body").css("cursor","move")}),a("body").mouseup(function(){a("body").off("mousemove"),a("body").css("cursor","default")})),null!=V.settings.hex){i=V.settings.hex;var c=ba(V.settings.hex);V.settings.rgb[0]=c.r,V.settings.rgb[1]=c.g,V.settings.rgb[2]=c.b}Y("r",0,255,V.settings.rgb[0]),Y("g",0,255,V.settings.rgb[1]),Y("b",0,255,V.settings.rgb[2]),Y("h",0,360,50),Y("s",0,100,50),Y("l",0,100,50),null!=V.settings.hsl&&(a(A).val(V.settings.hsl[0]),a(B).val(V.settings.hsl[1]),a(C).val(V.settings.hsl[2]),$()),a("#"+p).append('<div class="colorPickerWrapper"></div>'),a(P).append('<div class="colorPickerBg"></div>'),a(P).append('<div class="colorPicker"><div class="gradientTp2White"></div><div class="gradientTp2Black"></div></div>'),a(P).append('<div class="colorPickerIndicator"></div>'),a("#"+p).append('<div class="clear"></div>'),a("#"+p).append('<div class="swatchHex"></div>'),a("#"+p+" .swatchHex").append('<div class="swatch"></div>'),a("#"+p+" .swatchHex").append('<input type="text" class="hexValue" name="hexValue" maxlength="7" />'),a("#"+p).append('<div class="buttonsWrapper"></div>'),V.settings.showCancel&&a("#"+p+" .buttonsWrapper").append('<button type="button" class="cancelBtn">'+V.settings.textCancel+"</button>"),V.settings.showOk&&a("#"+p+" .buttonsWrapper").append('<button type="button" class="okBtn">'+V.settings.textOk+"</button>"),a("#"+p).append('<div class="clear"></div>'),a(x+", "+y+", "+z).bind("touchstart mousedown",function(){a(this).bind("touchmove mousemove",function(){Z()})}),a(A+", "+B+", "+C).bind("touchstart mousedown",function(){a(this).bind("touchmove mousemove",function(){$()})}),a(x+", "+y+", "+z).bind("touchend mouseup mouseout",function(){a(this).unbind("touchmove mousemove")}),a(A+", "+B+", "+C).bind("touchend mouseup mouseout",function(){a(this).unbind("touchmove mousemove")}),a(".colorValue").keyup(function(){var b=a(this).attr("data-sliderId");return isNaN(this.value)?(this.value=a("#"+p+" ."+b).val(),!1):(a("#"+p+" ."+b).val(this.value),"r"==b||"g"==b||"b"==b?Z():"h"!=b&&"s"!=b&&"l"!=b||$(),!0)}),a("#"+p+" .hexValue").keyup(function(){if("#"!=this.value.charAt(0)&&(this.value="#"+this.value),7==this.value.length)if(ba(this.value)){i=this.value;var a=ba(this.value);f=a.r,g=a.g,h=a.b,ia(),Z()}else this.value=i}),a(P).mousedown(function(a){q=!0,ka(a,this)}),a(P).mousemove(function(a){1==q&&ka(a,this)}),a(P).bind("mouseup mouseleave",function(a){q=!1}),a("#"+p+" .okBtn").click(function(){"rgb"==V.settings.mode?W.val("rgb("+f+", "+g+", "+h+")"):"hex"==V.settings.mode?W.val("#"+i):"hsl"==V.settings.mode&&W.val("hsl("+k+", "+l+"%, "+m+"%)"),null!=V.settings.onOk&&V.settings.onOk(),1==V.settings.closeOnOk&&ma(),a(T).css("background-color","#"+i)}),a("#"+p+" .cancelBtn").click(function(){null!=V.settings.onCancel&&V.settings.onCancel(),1==V.settings.closeOnCancel&&ma()}),a(b).scroll(function(){1==V.settings.modal&&0==V.settings.draggable&&na()}),a(b).resize(function(){Z(),1==V.settings.modal&&0==V.settings.draggable&&na()}),1==V.settings.clickToggle&&(W.click(function(){ma()}),a(T).click(function(){ma()})),1==V.settings.modal&&(na(),a("body").append('<div id="'+p+'overlay" class="colorpickleModalOverlay"></div>')),0==V.settings.showSwatch&&a(U).hide(),V.settings.showSLGradient||a(P).hide(),0==V.settings.rgbSliders&&(a(r).hide(),a(s).hide(),a(t).hide()),0==V.settings.hslSliders&&(a(u).hide(),a(v).hide(),a(w).hide()),0==V.settings.showHex&&a("#"+p+" .hexValue").hide(),(V.settings.showCancel||V.settings.showOk)&&a("#"+p).css("min-height",a("#"+p).height()+a("#"+p+" .buttonsWrapper").height()-parseInt(a("#"+p).css("padding-bottom"))+"px"),Z(),a(T).css("background-color","#"+i),0==V.settings.visible&&a("#"+p).hide(),a.isFunction(V.settings.onInit)&&V.settings.onInit()},V.setRGB=function(b,c,d){a(x).val(b),a(y).val(c),a(z).val(d),Z()},V.setHSL=function(b,c,d){a(A).val(b),a(B).val(c),a(C).val(d),$()},V.setHex=function(b){var c=ba(b);a(x).val(c.r),a(y).val(c.g),a(z).val(c.b),Z()};var Y=function(b,c,d,e){var f=b+"Wrapper",g="";"h"==b?g=" °":"s"!=b&&"l"!=b||(g=" %"),a("#"+p).append('<div class="sliderWrapper '+f+'"></div>'),a("#"+p+" ."+f).append("<label>"+b.toUpperCase()+" "+g+"</label>"),a("#"+p+" ."+f).append('<div class="sliderBg"></div>'),a("#"+p+" ."+f).append('<div class="sliderDiv"><input type="range" class="slider '+b+'" min="'+c+'" max="'+d+'" step="1" value="'+e+'" /></div>'),a("#"+p+" ."+f).append('<input type="text" data-sliderId="'+b+'" class="'+b+'Input sliderValue colorValue" value="0" />')},Z=function(){f=parseInt(a(x).val()),g=parseInt(a(y).val()),h=parseInt(a(z).val()),j=da(f,g,h),k=Math.round(360*j[0]),l=Math.round(100*j[1]),m=Math.round(100*j[2]),_(),ia(),ha(),ja(),la()},$=function(){k=parseInt(a(A).val()),l=parseInt(a(B).val()),m=parseInt(a(C).val());var b=ca(k/360,l/100,m/100);f=Math.round(b[0]),g=Math.round(b[1]),h=Math.round(b[2]),_(),ia(),ha(),ja(),la()},_=function(){i=aa(f,g,h),a(U).css("background-color","#"+i);var b=ca(k/360,1,.5),c=Math.round(b[0]),d=Math.round(b[1]),e=Math.round(b[2]),j=aa(c,d,e);a(Q).css("background-color","#"+j),null!=V.settings.onChange&&null!=V.rgb&&V.hex!="#"+i&&V.settings.onChange(),V.rgb="rgb("+f+","+g+","+h+")",V.hsl="hsl("+k+","+l+","+m+")",V.hex="#"+i},aa=function(b,c,d){var e=[b.toString(16),c.toString(16),d.toString(16)];return a.each(e,function(a,b){1===b.length&&(e[a]="0"+b)}),e.join("")},ba=function(a){var b=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(a);return!!b&&{r:parseInt(b[1],16),g:parseInt(b[2],16),b:parseInt(b[3],16)}},ca=function(a,b,c){function g(a,b,c){return c<0&&(c+=1),c>1&&(c-=1),c<1/6?a+6*(b-a)*c:c<.5?b:c<2/3?a+(b-a)*(2/3-c)*6:a}var d,e,f;if(0==b)d=e=f=c;else{var h=c<.5?c*(1+b):c+b-c*b,i=2*c-h;d=g(i,h,a+1/3),e=g(i,h,a),f=g(i,h,a-1/3)}return[255*d,255*e,255*f]},da=function(a,b,c){a/=255,b/=255,c/=255;var f,g,d=Math.max(a,b,c),e=Math.min(a,b,c),h=(d+e)/2;if(d==e)f=g=0;else{var i=d-e;switch(g=h>.5?i/(2-d-e):i/(d+e),d){case a:f=(b-c)/i+(b<c?6:0);break;case b:f=(c-a)/i+2;break;case c:f=(a-b)/i+4}f/=6}return[f,g,h]},ea=function(a,b,c){return[a,b*c/((a=(2-b)*c)<1?a:2-a),a/2]},fa=function(a,b,c){return b*=c<.5?c:1-c,[a,2*b/(c+b),c+b]},ga=function(a){var b=curtop=0;if(a.offsetParent)do{b+=a.offsetLeft,curtop+=a.offsetTop}while(a=a.offsetParent);return[b,curtop]},ha=function(){a(J).val(f),a(K).val(g),a(L).val(h),a(M).val(k),a(N).val(l),a(O).val(m),a("#"+p+" .hexValue").val("#"+i)},ia=function(){a(x).val(f),a(y).val(g),a(z).val(h),a(A).val(k),a(B).val(l),a(C).val(m)},ja=function(){var b="background: -moz-linear-gradient(left, rgb(0,"+g+","+h+") 0%, rgb(255,"+g+","+h+") 100%);";b+="background: -webkit-linear-gradient(left, rgb(0,"+g+","+h+") 0%, rgb(255,"+g+","+h+") 100%);",b+="background: linear-gradient(to right, rgb(0,"+g+","+h+") 0%, rgb(255,"+g+","+h+") 100%);";var c="background: -moz-linear-gradient(left, rgb("+f+",0,"+h+") 0%, rgb("+f+",255,"+h+") 100%);";c+="background: -webkit-linear-gradient(left, rgb("+f+",0,"+h+") 0%, rgb("+f+",255,"+h+") 100%);",c+="background: linear-gradient(to right, rgb("+f+",0,"+h+") 0%, rgb("+f+",255,"+h+") 100%);";var d="background: -moz-linear-gradient(left, rgb("+f+","+g+",0) 0%, rgb("+f+","+g+",255) 100%);";d+="background: -webkit-linear-gradient(left, rgb("+f+","+g+",0) 0%, rgb("+f+","+g+",255) 100%);",d+="background: linear-gradient(to right, rgb("+f+","+g+",0) 0%, rgb("+f+","+g+",255) 100%);";var e="background: -moz-linear-gradient(left, #000 0%, hsl("+k+","+l+"%,50%) 50%, #fff 100%);";e+="background: -webkit-linear-gradient(left, #000 0%, hsl("+k+","+l+"%,50%) 50%, #fff 100%);",e+="background: linear-gradient(to right, #000 0%, hsl("+k+","+l+"%,50%) 50%, #fff 100%);";var i="background: -moz-linear-gradient(left, hsl("+k+",0%,"+m+"%) 0%, hsl("+k+",100%,"+m+"%) 100%);";i+="background: -webkit-linear-gradient(left, hsl("+k+",0%,"+m+"%) 0%, hsl("+k+",100%,"+m+"%) 100%);",i+="background: linear-gradient(to right, hsl("+k+",0%,"+m+"%) 0%, hsl("+k+",100%,"+m+"%) 100%);",a(D).attr("style",b),a(E).attr("style",c),a(F).attr("style",d),a(I).attr("style",e),a(H).attr("style",i)},ka=function(b,c){var d=ga(c),e=b.pageX-d[0],f=b.pageY-d[1];a(S).css("left",Math.ceil(e-a(S).outerWidth()/2)),a(S).css("top",Math.ceil(f-a(S).outerHeight()/2)),l=e/(a(P).width()/100),n=100-f/(a(P).height()/100);var g=ea(k,l/100,n/100);l=Math.round(100*g[1]),m=Math.round(100*g[2]),a(B).val(l),a(C).val(m),$()},la=function(){var b=fa(k,l/100,m/100);l=Math.round(100*b[1]),n=Math.round(100*b[2]);var c=a(P).width()/100,d=a(P).height()/100,e=Math.ceil(l*c-a(S).outerWidth()/2),f=Math.ceil(a(P).height()-n*d-a(S).outerHeight()/2);a(S).css("left",e),a(S).css("top",f)},ma=function(){1==V.settings.modal&&(a("#"+p).is(":visible")||na(),a("#"+p+"overlay").fadeToggle()),a("#"+p).fadeToggle()},na=function(){var c=a(b).width()/2-a("#"+p).width()/2,d=a(b).height()/2-a("#"+p).height()/2+a(b).scrollTop();a("#"+p).css("position","absolute"),a("#"+p).css("top",d+"px"),a("#"+p).css("left",c+"px")};V.init()},a.fn.colorpickle=function(b){var c=arguments;return this.each(function(){var e=a(this).data("colorpickle");if(e==d){var f=new a.colorpickle(this,b);a(this).data("colorpickle",f)}else a.isFunction(e[b])&&e[b].apply(e,Array.prototype.slice.call(c,1))})}}(jQuery,window,document);
|
---|