UNPKG

jquery-wheelcolorpicker

Version:

The Wheel Color Picker plugin adds color picker functionality to HTML form inputs in round color wheel style. The Wheel Color Picker can be displayed as a popup dialog as users focus the input, or embedded inline.

6 lines 28.8 kB
/** * Wheel Color Picker 3.0.9 * (c) 2011-2019 Fajar Chandra. Released under MIT License. * https://raffer.one/projects/jquery-wheelcolorpicker */ !function(G){G.fn.wheelColorPicker=function(){var i=this;if(0<arguments.length)var s="string"==typeof(a=[].shift.apply(arguments))?a.charAt(0).toUpperCase()+a.slice(1):a;else{var a=void 0;s=void 0}var o=arguments;return this.each(function(){var e=G(this).data("jQWCP.instance");if(null==e||null==e){var t={};"object"==typeof a&&(t=a),e=new h.ColorPicker(this,t),G(this).data("jQWCP.instance",e)}if(void 0!==a&&"object"!=typeof a)if("function"==typeof e[a]){if((r=e[a].apply(e,o))!==e)return i=r,!1}else if("function"==typeof e["set"+s]&&0<o.length){if((r=e["set"+s].apply(e,o))!==e)return i=r,!1}else if("function"==typeof e["get"+s]){var r;if((r=e["get"+s].apply(e,o))!==e)return i=r,!1}else if(void 0!==e.options[a]&&0<o.length)e.options[a]=o[0];else{if(void 0!==e.options[a])return i=e.options[a],!1;G.error("Method/option named "+a+" does not exist on jQuery.wheelColorPicker")}}),i};var h=G.fn.wheelColorPicker;h.defaults={format:"hex",preview:!1,live:!0,userinput:!0,validate:!0,autoResize:!0,autoFormat:!0,preserveWheel:null,cssClass:"",layout:"popup",animDuration:200,quality:1,sliders:null,rounding:2,mobile:!0,mobileWidth:480,hideKeyboard:!1,htmlOptions:!0,snap:!1,snapTolerance:.05},h.BUG_RELATIVE_PAGE_ORIGIN=!1,h.ORIGIN={left:0,top:0},h.colorToStr=function(e,t){var r="";switch(t){case"css":r="#";case"hex":1==(i=Math.round(255*e.r).toString(16)).length&&(i="0"+i),1==(s=Math.round(255*e.g).toString(16)).length&&(s="0"+s),1==(a=Math.round(255*e.b).toString(16)).length&&(a="0"+a),r+=i+s+a;break;case"cssa":r="#";case"hexa":var i,s,a;1==(i=Math.round(255*e.r).toString(16)).length&&(i="0"+i),1==(s=Math.round(255*e.g).toString(16)).length&&(s="0"+s),1==(a=Math.round(255*e.b).toString(16)).length&&(a="0"+a);var o=Math.round(255*e.a).toString(16);1==o.length&&(o="0"+o),r+=i+s+a+o;break;case"rgb":r="rgb("+Math.round(255*e.r)+","+Math.round(255*e.g)+","+Math.round(255*e.b)+")";break;case"rgb%":r="rgb("+100*e.r+"%,"+100*e.g+"%,"+100*e.b+"%)";break;case"rgba":r="rgba("+Math.round(255*e.r)+","+Math.round(255*e.g)+","+Math.round(255*e.b)+","+e.a+")";break;case"rgba%":r="rgba("+100*e.r+"%,"+100*e.g+"%,"+100*e.b+"%,"+100*e.a+"%)";break;case"hsv":r="hsv("+360*e.h+","+e.s+","+e.v+")";break;case"hsv%":r="hsv("+100*e.h+"%,"+100*e.s+"%,"+100*e.v+"%)";break;case"hsva":r="hsva("+360*e.h+","+e.s+","+e.v+","+e.a+")";break;case"hsva%":r="hsva("+100*e.h+"%,"+100*e.s+"%,"+100*e.v+"%,"+100*e.a+"%)";break;case"hsb":r="hsb("+e.h+","+e.s+","+e.v+")";break;case"hsb%":r="hsb("+100*e.h+"%,"+100*e.s+"%,"+100*e.v+"%)";break;case"hsba":r="hsba("+e.h+","+e.s+","+e.v+","+e.a+")";break;case"hsba%":r="hsba("+100*e.h+"%,"+100*e.s+"%,"+100*e.v+"%,"+100*e.a+"%)"}return r},h.strToColor=function(e){var t,r,i={a:1};if(null!=e.match(/^#[0-9a-f]{3}$/i)||e.match(/^#[0-9a-f]{4}$/i)){if(isNaN(i.r=17*parseInt(e.substr(1,1),16)/255))return!1;if(isNaN(i.g=17*parseInt(e.substr(2,1),16)/255))return!1;if(isNaN(i.b=17*parseInt(e.substr(3,1),16)/255))return!1;if(5==e.length&&isNaN(i.a=17*parseInt(e.substr(4,1),16)/255))return!1}else if(null!=e.match(/^[0-9a-f]{3}$/i)||null!=e.match(/^[0-9a-f]{4}$/i)){if(isNaN(i.r=17*parseInt(e.substr(0,1),16)/255))return!1;if(isNaN(i.g=17*parseInt(e.substr(1,1),16)/255))return!1;if(isNaN(i.b=17*parseInt(e.substr(2,1),16)/255))return!1;if(4==e.length&&isNaN(i.a=17*parseInt(e.substr(3,1),16)/255))return!1}else if(null!=e.match(/^#[0-9a-f]{6}$/i)||null!=e.match(/^#[0-9a-f]{8}$/i)){if(isNaN(i.r=parseInt(e.substr(1,2),16)/255))return!1;if(isNaN(i.g=parseInt(e.substr(3,2),16)/255))return!1;if(isNaN(i.b=parseInt(e.substr(5,2),16)/255))return!1;if(9==e.length&&isNaN(i.a=parseInt(e.substr(7,2),16)/255))return!1}else if(null!=e.match(/^[0-9a-f]{6}$/i)||null!=e.match(/^[0-9a-f]{8}$/i)){if(isNaN(i.r=parseInt(e.substr(0,2),16)/255))return!1;if(isNaN(i.g=parseInt(e.substr(2,2),16)/255))return!1;if(isNaN(i.b=parseInt(e.substr(4,2),16)/255))return!1;if(8==e.length&&isNaN(i.a=parseInt(e.substr(6,2),16)/255))return!1}else if(null!=e.match(/^rgba\s*\(\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*\)$/i)||null!=e.match(/^rgb\s*\(\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*\)$/i)){if(r=null!=e.match(/a/i),"%"==(t=e.substring(e.indexOf("(")+1,e.indexOf(","))).charAt(t.length-1)){if(isNaN(i.r=parseFloat(t)/100))return!1}else if(isNaN(i.r=parseInt(t)/255))return!1;if("%"==(t=e.substring(e.indexOf(",")+1,e.indexOf(",",e.indexOf(",")+1))).charAt(t.length-1)){if(isNaN(i.g=parseFloat(t)/100))return!1}else if(isNaN(i.g=parseInt(t)/255))return!1;if("%"==(t=r?e.substring(e.indexOf(",",e.indexOf(",")+1)+1,e.lastIndexOf(",")):e.substring(e.lastIndexOf(",")+1,e.lastIndexOf(")"))).charAt(t.length-1)){if(isNaN(i.b=parseFloat(t)/100))return!1}else if(isNaN(i.b=parseInt(t)/255))return!1;if(r)if("%"==(t=e.substring(e.lastIndexOf(",")+1,e.lastIndexOf(")"))).charAt(t.length-1)){if(isNaN(i.a=parseFloat(t)/100))return!1}else if(isNaN(i.a=parseFloat(t)))return!1}else{if(null==e.match(/^hsva\s*\(\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*\)$/i)&&null==e.match(/^hsv\s*\(\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*\)$/i)&&null==e.match(/^hsba\s*\(\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*\)$/i)&&null==e.match(/^hsb\s*\(\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*,\s*([0-9\.]+%|[01]?\.?[0-9]*)\s*\)$/i))return!1;if(r=null!=e.match(/a/i),"%"==(t=e.substring(e.indexOf("(")+1,e.indexOf(","))).charAt(t.length-1)){if(isNaN(i.h=parseFloat(t)/100))return!1}else if(isNaN(i.h=parseFloat(t)/360))return!1;if("%"==(t=e.substring(e.indexOf(",")+1,e.indexOf(",",e.indexOf(",")+1))).charAt(t.length-1)){if(isNaN(i.s=parseFloat(t)/100))return!1}else if(isNaN(i.s=parseFloat(t)))return!1;if("%"==(t=r?e.substring(e.indexOf(",",e.indexOf(",")+1)+1,e.lastIndexOf(",")):e.substring(e.lastIndexOf(",")+1,e.lastIndexOf(")"))).charAt(t.length-1)){if(isNaN(i.v=parseFloat(t)/100))return!1}else if(isNaN(i.v=parseFloat(t)))return!1;if(r)if("%"==(t=e.substring(e.lastIndexOf(",")+1,e.lastIndexOf(")"))).charAt(t.length-1)){if(isNaN(i.a=parseFloat(t)/100))return!1}else if(isNaN(i.a=parseFloat(t)))return!1}return i},h.hsvToRgb=function(e,t,r){var i=e<=1/6||5/6<=e?1:e<1/3?1-6*(e-1/6):4/6<e?6*(e-4/6):0,s=1/6<=e&&e<=.5?1:e<1/6?6*e:e<4/6?1-6*(e-.5):0,a=.5<=e&&e<=5/6?1:2/6<e&&e<.5?6*(e-2/6):5/6<e?1-6*(e-5/6):0;return{r:(i+(1-i)*(1-t))*r,g:(s+(1-s)*(1-t))*r,b:(a+(1-a)*(1-t))*r}},h.rgbToHsv=function(e,t,r){var i,s=Math.max(e,t,r),a=s-Math.min(e,t,r);return i=0==a?0:e==s?(6+(t-r)/a)%6:t==s?2+(r-e)/a:r==s?4+(e-t)/a:0,{h:i/=6,s:0!=s?a/s:0,v:s}},h.ColorPicker=function(e,t){this.input=e,this.color={h:0,s:0,v:1,r:1,g:1,b:1,a:1},this.setValue(this.input.value),this.options=G.extend(!0,{},h.defaults),this.setOptions(t),null==this.options.sliders&&(this.options.sliders="wvp"+(0<=this.options.format.indexOf("a")?"a":"")),this.init()},h.ColorPicker.widget=null,h.ColorPicker.overlay=null,h.ColorPicker.init=function(){if(1!=h.ColorPicker.init.hasInit){h.ColorPicker.init.hasInit=!0;var e=G('<div class="jQWCP-overlay" style="display: none;"></div>');e.on("click",h.Handler.overlay_click),h.ColorPicker.overlay=e.get(0),G("body").append(e);var t=h.ColorPicker.getWheelDataUrl(200);G("head").append('<style type="text/css">.jQWCP-wWheel {background-image: url('+t+");}</style>"),G("html").on("mouseup.wheelColorPicker",h.Handler.html_mouseup),G("html").on("touchend.wheelColorPicker",h.Handler.html_mouseup),G("html").on("mousemove.wheelColorPicker",h.Handler.html_mousemove),G("html").on("touchmove.wheelColorPicker",h.Handler.html_mousemove),G(window).on("resize.wheelColorPicker",h.Handler.window_resize)}},h.ColorPicker.createWidget=function(){var e=G("<div class='jQWCP-wWidget'><div class='jQWCP-wWheel'><div class='jQWCP-wWheelOverlay'></div><span class='jQWCP-wWheelCursor'></span></div><div class='jQWCP-wHue jQWCP-slider-wrapper'><canvas class='jQWCP-wHueSlider jQWCP-slider' width='1' height='50' title='Hue'></canvas><span class='jQWCP-wHueCursor jQWCP-scursor'></span></div><div class='jQWCP-wSat jQWCP-slider-wrapper'><canvas class='jQWCP-wSatSlider jQWCP-slider' width='1' height='50' title='Saturation'></canvas><span class='jQWCP-wSatCursor jQWCP-scursor'></span></div><div class='jQWCP-wVal jQWCP-slider-wrapper'><canvas class='jQWCP-wValSlider jQWCP-slider' width='1' height='50' title='Value'></canvas><span class='jQWCP-wValCursor jQWCP-scursor'></span></div><div class='jQWCP-wRed jQWCP-slider-wrapper'><canvas class='jQWCP-wRedSlider jQWCP-slider' width='1' height='50' title='Red'></canvas><span class='jQWCP-wRedCursor jQWCP-scursor'></span></div><div class='jQWCP-wGreen jQWCP-slider-wrapper'><canvas class='jQWCP-wGreenSlider jQWCP-slider' width='1' height='50' title='Green'></canvas><span class='jQWCP-wGreenCursor jQWCP-scursor'></span></div><div class='jQWCP-wBlue jQWCP-slider-wrapper'><canvas class='jQWCP-wBlueSlider jQWCP-slider' width='1' height='50' title='Blue'></canvas><span class='jQWCP-wBlueCursor jQWCP-scursor'></span></div><div class='jQWCP-wAlpha jQWCP-slider-wrapper'><canvas class='jQWCP-wAlphaSlider jQWCP-slider' width='1' height='50' title='Alpha'></canvas><span class='jQWCP-wAlphaCursor jQWCP-scursor'></span></div><div class='jQWCP-wPreview'><canvas class='jQWCP-wPreviewBox' width='1' height='1' title='Selected Color'></canvas></div></div>");return e.find(".jQWCP-wWheel, .jQWCP-slider-wrapper, .jQWCP-scursor, .jQWCP-slider").attr("unselectable","on").css("-moz-user-select","none").css("-webkit-user-select","none").css("user-select","none").css("-webkit-touch-callout","none"),e.on("contextmenu.wheelColorPicker",function(){return!1}),e.on("mousedown.wheelColorPicker",".jQWCP-wWheel",h.Handler.wheel_mousedown),e.on("touchstart.wheelColorPicker",".jQWCP-wWheel",h.Handler.wheel_mousedown),e.on("mousedown.wheelColorPicker",".jQWCP-wWheelCursor",h.Handler.wheelCursor_mousedown),e.on("touchstart.wheelColorPicker",".jQWCP-wWheelCursor",h.Handler.wheelCursor_mousedown),e.on("mousedown.wheelColorPicker",".jQWCP-slider",h.Handler.slider_mousedown),e.on("touchstart.wheelColorPicker",".jQWCP-slider",h.Handler.slider_mousedown),e.on("mousedown.wheelColorPicker",".jQWCP-scursor",h.Handler.sliderCursor_mousedown),e.on("touchstart.wheelColorPicker",".jQWCP-scursor",h.Handler.sliderCursor_mousedown),e.get(0)},h.ColorPicker.getWheelDataUrl=function(e){var t=e/2,r=t,i=document.createElement("canvas");i.width=e,i.height=e;for(var s=i.getContext("2d"),a=0;a<e;a++)for(var o=0;o<e;o++){var n=Math.sqrt(Math.pow(o-r,2)+Math.pow(a-r,2));if(!(2+t<n)){var l=((o-r==0?a<r?90:270:Math.atan((r-a)/(o-r))/Math.PI*180)+(o<r?180:0)+360)%360,d=n/t,h=(Math.abs(360+l)+60)%360<120?1:240<l?(120-Math.abs(l-360))/60:l<120?(120-l)/60:0,u=Math.abs(l-120)<60?1:Math.abs(l-120)<120?(120-Math.abs(l-120))/60:0,c=Math.abs(l-240)<60?1:Math.abs(l-240)<120?(120-Math.abs(l-240))/60:0,p=Math.round(255*(h+(1-h)*(1-d))),C=Math.round(255*(u+(1-u)*(1-d))),f=Math.round(255*(c+(1-c)*(1-d)));s.fillStyle="rgb("+p+","+C+","+f+")",s.fillRect(o,a,1,1)}}return i.toDataURL()},h.ColorPicker.prototype.options=null,h.ColorPicker.prototype.input=null,h.ColorPicker.prototype.widget=null,h.ColorPicker.prototype.color=null,h.ColorPicker.prototype.lastValue=null,h.ColorPicker.prototype.setOptions=function(e){if(e=G.extend(!0,{},e),this.options.htmlOptions)for(var t in h.defaults)this.input.hasAttribute("data-wcp-"+t)&&void 0===e[t]&&(e[t]=this.input.getAttribute("data-wcp-"+t),"true"==e[t]?e[t]=!0:"false"==e[t]&&(e[t]=!1));for(var t in e)if(void 0!==this.options[t]){var r=t.charAt(0).toUpperCase()+t.slice(1);"function"==typeof this["set"+r]?this["set"+r](e[t]):this.options[t]=e[t]}return this},h.ColorPicker.prototype.init=function(){if(h.ColorPicker.init(),1!=this.hasInit){this.hasInit=!0;var e=G(this.input),t=null;"block"==this.options.layout?(this.widget=h.ColorPicker.createWidget(),(t=G(this.widget)).data("jQWCP.instance",this),t.insertAfter(this.input),"inline"==e.css("display")?t.css("display","inline-block"):t.css("display",e.css("display")),t.append(this.input),e.hide(),null!=e.attr("tabindex")?t.attr("tabindex",e.attr("tabindex")):t.attr("tabindex",0),this.refreshWidget(),this.redrawSliders(!0),this.updateSliders(),t.on("focus.wheelColorPicker",h.Handler.widget_focus_block),t.on("blur.wheelColorPicker",h.Handler.widget_blur_block)):(null==h.ColorPicker.widget&&(h.ColorPicker.widget=h.ColorPicker.createWidget(),(t=G(h.ColorPicker.widget)).attr("id","jQWCP-popup"),t.hide(),G("body").append(t),t.on("mousedown.wheelColorPicker",h.Handler.widget_mousedown_popup)),this.widget=h.ColorPicker.widget,e.on("focus.wheelColorPicker",h.Handler.input_focus_popup),e.on("blur.wheelColorPicker",h.Handler.input_blur_popup)),e.on("keyup.wheelColorPicker",h.Handler.input_keyup),e.on("change.wheelColorPicker",h.Handler.input_change),"object"==typeof this.options.color?(this.setColor(this.options.color),this.options.color=void 0):"string"==typeof this.options.color&&(this.setValue(this.options.color),this.options.color=void 0),this.options.userinput?e.removeAttr("readonly"):e.attr("readonly",!0)}},h.ColorPicker.prototype.destroy=function(){var e=G(this.widget),t=G(this.input);if("block"==this.options.layout){var r=G(G("body").data("jQWCP.activeControl"));if(r.length){var i=r.closest(".jQWCP-wWidget");e.is(i)&&G("body").data("jQWCP.activeControl",null)}e.before(this.input),e.remove(),t.show()}t.off("focus.wheelColorPicker"),t.off("blur.wheelColorPicker"),t.off("keyup.wheelColorPicker"),t.off("change.wheelColorPicker"),t.data("jQWCP.instance",null)},h.ColorPicker.prototype.refreshWidget=function(){var e=G(this.widget),t=this.options,r=!1;for(var i in e.attr("class","jQWCP-wWidget"),"block"==t.layout&&e.addClass("jQWCP-block"),e.addClass(t.cssClass),window.innerWidth<=t.mobileWidth&&"block"!=t.layout&&t.mobile&&(r=!0,e.addClass("jQWCP-mobile")),e.find(".jQWCP-wWheel, .jQWCP-slider-wrapper, .jQWCP-wPreview").hide().addClass("hidden"),t.sliders){var s=null;switch(this.options.sliders[i]){case"w":s=e.find(".jQWCP-wWheel");break;case"h":s=e.find(".jQWCP-wHue");break;case"s":s=e.find(".jQWCP-wSat");break;case"v":s=e.find(".jQWCP-wVal");break;case"r":s=e.find(".jQWCP-wRed");break;case"g":s=e.find(".jQWCP-wGreen");break;case"b":s=e.find(".jQWCP-wBlue");break;case"a":s=e.find(".jQWCP-wAlpha");break;case"p":s=e.find(".jQWCP-wPreview")}null!=s&&(s.appendTo(this.widget),s.show().removeClass("hidden"))}var a=50*t.quality;e.find(".jQWCP-slider").attr("height",a);var o=e.find(".jQWCP-wWheel, .jQWCP-slider-wrapper, .jQWCP-wPreview").not(".hidden");if(t.autoResize&&!r){var n=0;o.css({width:"",height:""}),o.each(function(e,t){var r=G(t);n+=parseFloat(r.css("margin-left").replace("px",""))+parseFloat(r.css("margin-right").replace("px",""))+r.outerWidth()}),e.css({width:n+"px"})}else{e.css({width:""});var l=e.find(".jQWCP-wWheel").not(".hidden"),d=e.find(".jQWCP-slider-wrapper, .jQWCP-wPreview").not(".hidden");if(l.css({height:e.height()+"px",width:e.height()}),0<l.length)var h=e.width()-l.outerWidth()-parseFloat(l.css("margin-left").replace("px",""))-parseFloat(l.css("margin-right").replace("px",""));else h=e.width();if(0<d.length){var u=parseFloat(d.css("margin-left").replace("px",""))+parseFloat(d.css("margin-right").replace("px",""));d.css({height:e.height()+"px",width:(h-(d.length-1)*u)/d.length+"px"})}}return this},h.ColorPicker.prototype.redrawSliders=function(e){if(null==this.widget)return this;var t=G(this.widget);if("string"==typeof e&&(e=arguments[1]),this!=t.data("jQWCP.instance"))return this;var r=this.options,i=this.color,s=50*r.quality,a=1,o=0,n=0,l=0,d=0,h=0,u=1;r.live&&(a=i.a,o=Math.round(255*i.r),n=Math.round(255*i.g),l=Math.round(255*i.b),d=i.h,h=i.s,u=i.v);var c=t.find(".jQWCP-wPreviewBox");if(!c.hasClass("hidden")){var p=c.get(0).getContext("2d");p.fillStyle="rgba("+o+","+n+","+l+","+a+")",p.clearRect(0,0,1,1),p.fillRect(0,0,1,1)}if(!this.options.live&&!e)return this;var C=t.find(".jQWCP-wAlphaSlider");if(!C.hasClass("hidden")||e){var f=C.get(0).getContext("2d"),g=f.createLinearGradient(0,0,0,s);g.addColorStop(0,"rgba("+o+","+n+","+l+",1)"),g.addColorStop(1,"rgba("+o+","+n+","+l+",0)"),f.fillStyle=g,f.clearRect(0,0,1,s),f.fillRect(0,0,1,s)}var v=t.find(".jQWCP-wRedSlider");if(!v.hasClass("hidden")||e){var P=v.get(0).getContext("2d"),w=P.createLinearGradient(0,0,0,s);w.addColorStop(0,"rgb(255,"+n+","+l+")"),w.addColorStop(1,"rgb(0,"+n+","+l+")"),P.fillStyle=w,P.fillRect(0,0,1,s)}var W=t.find(".jQWCP-wGreenSlider");if(!W.hasClass("hidden")||e){var b=W.get(0).getContext("2d"),j=b.createLinearGradient(0,0,0,s);j.addColorStop(0,"rgb("+o+",255,"+l+")"),j.addColorStop(1,"rgb("+o+",0,"+l+")"),b.fillStyle=j,b.fillRect(0,0,1,s)}var Q=t.find(".jQWCP-wBlueSlider");if(!Q.hasClass("hidden")||e){var k=Q.get(0).getContext("2d"),y=k.createLinearGradient(0,0,0,s);y.addColorStop(0,"rgb("+o+","+n+",255)"),y.addColorStop(1,"rgb("+o+","+n+",0)"),k.fillStyle=y,k.fillRect(0,0,1,s)}var m=t.find(".jQWCP-wHueSlider");if(!m.hasClass("hidden")||e){var S=m.get(0).getContext("2d"),N=S.createLinearGradient(0,0,0,s);N.addColorStop(0,"#f00"),N.addColorStop(.166666667,"#ff0"),N.addColorStop(.333333333,"#0f0"),N.addColorStop(.5,"#0ff"),N.addColorStop(.666666667,"#00f"),N.addColorStop(.833333333,"#f0f"),N.addColorStop(1,"#f00"),S.fillStyle=N,S.fillRect(0,0,1,s)}var I=t.find(".jQWCP-wSatSlider");if(!I.hasClass("hidden")||e){var x=G.fn.wheelColorPicker.hsvToRgb(d,1,u);x.r=Math.round(255*x.r),x.g=Math.round(255*x.g),x.b=Math.round(255*x.b);var H=I.get(0).getContext("2d"),_=H.createLinearGradient(0,0,0,s);_.addColorStop(0,"rgb("+x.r+","+x.g+","+x.b+")"),_.addColorStop(1,"rgb("+Math.round(255*u)+","+Math.round(255*u)+","+Math.round(255*u)+")"),H.fillStyle=_,H.fillRect(0,0,1,s)}var R=t.find(".jQWCP-wValSlider");if(!R.hasClass("hidden")||e){var M=G.fn.wheelColorPicker.hsvToRgb(d,h,1);M.r=Math.round(255*M.r),M.g=Math.round(255*M.g),M.b=Math.round(255*M.b);var O=R.get(0).getContext("2d"),A=O.createLinearGradient(0,0,0,s);A.addColorStop(0,"rgb("+M.r+","+M.g+","+M.b+")"),A.addColorStop(1,"#000"),O.fillStyle=A,O.fillRect(0,0,1,s)}return this},h.ColorPicker.prototype.updateSliders=function(){if(null==this.widget)return this;var e=G(this.widget),t=this.color;if(this!=e.data("jQWCP.instance"))return this;var r=e.find(".jQWCP-wWheel");if(!r.hasClass("hidden")){var i=e.find(".jQWCP-wWheelCursor"),s=e.find(".jQWCP-wWheelOverlay"),a=Math.cos(2*Math.PI*t.h)*t.s,o=Math.sin(2*Math.PI*t.h)*t.s,n=r.width()/2,l=r.height()/2;i.css("left",n+a*r.width()/2+"px"),i.css("top",l-o*r.height()/2+"px"),1==this.options.preserveWheel||null==this.options.preserveWheel&&0==this.options.live?s.css("opacity",0):s.css("opacity",1-(t.v<.2?.2:t.v))}var d=e.find(".jQWCP-wHueSlider");d.hasClass("hidden")||e.find(".jQWCP-wHueCursor").css("top",t.h*d.height()+"px");var h=e.find(".jQWCP-wSatSlider");h.hasClass("hidden")||e.find(".jQWCP-wSatCursor").css("top",(1-t.s)*h.height()+"px");var u=e.find(".jQWCP-wValSlider");u.hasClass("hidden")||e.find(".jQWCP-wValCursor").css("top",(1-t.v)*u.height()+"px");var c=e.find(".jQWCP-wRedSlider");c.hasClass("hidden")||e.find(".jQWCP-wRedCursor").css("top",(1-t.r)*c.height()+"px");var p=e.find(".jQWCP-wGreenSlider");p.hasClass("hidden")||e.find(".jQWCP-wGreenCursor").css("top",(1-t.g)*p.height()+"px");var C=e.find(".jQWCP-wBlueSlider");C.hasClass("hidden")||e.find(".jQWCP-wBlueCursor").css("top",(1-t.b)*C.height()+"px");var f=e.find(".jQWCP-wAlphaSlider");f.hasClass("hidden")||e.find(".jQWCP-wAlphaCursor").css("top",(1-t.a)*f.height()+"px");return this},h.ColorPicker.prototype.updateSelection=function(){return this.redrawSliders(),this.updateSliders(),this},h.ColorPicker.prototype.updateInput=function(){if(null==this.widget)return this;var e=G(this.input);this.input.value!=this.getValue()&&(e.attr("value",this.getValue()),this.input.value=this.getValue()),e.trigger("colorchange"),this.options.preview&&(e.css("background",h.colorToStr(this.color,"rgba")),.5<this.color.v?e.css("color","black"):e.css("color","white"))},h.ColorPicker.prototype.updateActiveControl=function(e){var t=G(G("body").data("jQWCP.activeControl"));if(0!=t.length){G(this.input);var r=this.options,i=this.color;if(e.originalEvent.touches&&0<e.originalEvent.touches.length&&(e.pageX=e.originalEvent.touches[0].pageX,e.pageY=e.originalEvent.touches[0].pageY),t.hasClass("jQWCP-wWheel")){var s=t.find(".jQWCP-wWheelCursor"),a=(t.find(".jQWCP-wWheelOverlay"),(e.pageX-t.offset().left-t.width()/2)/(t.width()/2)),o=-(e.pageY-t.offset().top-t.height()/2)/(t.height()/2);if(h.BUG_RELATIVE_PAGE_ORIGIN)a=(e.pageX-(t.get(0).getBoundingClientRect().left-h.ORIGIN.left)-t.width()/2)/(t.width()/2),o=-(e.pageY-(t.get(0).getBoundingClientRect().top-h.ORIGIN.top)-t.height()/2)/(t.height()/2);var n=Math.sqrt(Math.pow(a,2)+Math.pow(o,2));1<n&&(n=1),r.snap&&n<r.snapTolerance&&(n=0);var l=0==a&&0==o?0:Math.atan(o/a)/(2*Math.PI);a<0&&0==o&&(l=.5),l<0&&(l+=.5),o<0&&(l+=.5),this.setHsv(l,n,i.v)}else if(t.hasClass("jQWCP-slider-wrapper")){s=t.find(".jQWCP-scursor"),o=(e.pageY-t.offset().top)/t.height();if(h.BUG_RELATIVE_PAGE_ORIGIN)o=(e.pageY-(t.get(0).getBoundingClientRect().top-h.ORIGIN.top))/t.height();var d=o<0?0:1<o?1:o;r.snap&&d<r.snapTolerance?d=0:r.snap&&d>1-r.snapTolerance&&(d=1),r.snap&&d>.5-r.snapTolerance&&d<.5+r.snapTolerance&&(d=.5),s.css("top",d*t.height()+"px"),t.hasClass("jQWCP-wRed")&&this.setRgb(1-d,i.g,i.b),t.hasClass("jQWCP-wGreen")&&this.setRgb(i.r,1-d,i.b),t.hasClass("jQWCP-wBlue")&&this.setRgb(i.r,i.g,1-d),t.hasClass("jQWCP-wHue")&&this.setHsv(d,i.s,i.v),t.hasClass("jQWCP-wSat")&&this.setHsv(i.h,1-d,i.v),t.hasClass("jQWCP-wVal")&&this.setHsv(i.h,i.s,1-d),t.hasClass("jQWCP-wAlpha")&&this.setAlpha(1-d)}}},h.ColorPicker.prototype.getColor=function(){return this.color},h.ColorPicker.prototype.getValue=function(e){var t=this.options;return null==e&&(e=t.format),0<=t.rounding&&(this.color.a=Math.round(this.color.a*Math.pow(10,t.rounding))/Math.pow(10,t.rounding)),h.colorToStr(this.color,e)},h.ColorPicker.prototype.setValue=function(e,t){var r=h.strToColor(e);return r?this.setColor(r,t):this},h.ColorPicker.prototype.setColor=function(e,t){return"string"==typeof e?this.setValue(e,t):null!=e.r?this.setRgba(e.r,e.g,e.b,e.a,t):null!=e.h?this.setHsva(e.h,e.s,e.v,e.a,t):null!=e.a?this.setAlpha(e.a,t):this},h.ColorPicker.prototype.setRgba=function(e,t,r,i,s){void 0===s&&(s=!0);var a=this.color;a.r=e,a.g=t,a.b=r,null!=i&&(a.a=i);var o=h.rgbToHsv(e,t,r);return a.h=o.h,a.s=o.s,a.v=o.v,this.updateSliders(),this.redrawSliders(),s&&this.updateInput(),this},h.ColorPicker.prototype.setRgb=function(e,t,r,i){return this.setRgba(e,t,r,null,i)},h.ColorPicker.prototype.setHsva=function(e,t,r,i,s){void 0===s&&(s=!0);var a=this.color;a.h=e,a.s=t,a.v=r,null!=i&&(a.a=i);var o=h.hsvToRgb(e,t,r);return a.r=o.r,a.g=o.g,a.b=o.b,this.updateSliders(),this.redrawSliders(),s&&this.updateInput(),this},h.ColorPicker.prototype.setHsv=function(e,t,r,i){return this.setHsva(e,t,r,null,i)},h.ColorPicker.prototype.setAlpha=function(e,t){return void 0===t&&(t=!0),this.color.a=e,this.updateSliders(),this.redrawSliders(),t&&this.updateInput(),this},h.ColorPicker.prototype.show=function(){var e=this.input,t=G(e),r=G(this.widget),i=this.options;if("popup"==i.layout&&(r.data("jQWCP.instance",this),r.stop(!0,!0),r.css({top:e.getBoundingClientRect().top-h.ORIGIN.top+t.outerHeight()+"px",left:e.getBoundingClientRect().left-h.ORIGIN.left+"px"}),this.refreshWidget(),this.redrawSliders(),this.lastValue=e.value,r.fadeIn(i.animDuration),this.updateSliders(),i.hideKeyboard&&(t.blur(),G(h.ColorPicker.overlay).show()),r.hasClass("jQWCP-mobile"))){var s=G("html").scrollTop(),a=e.getBoundingClientRect().top-h.ORIGIN.top;a<s?G("html").animate({scrollTop:a}):a+t.outerHeight()>s+window.innerHeight-r.outerHeight()&&G("html").animate({scrollTop:a+t.outerHeight()-window.innerHeight+r.outerHeight()})}},h.ColorPicker.prototype.hide=function(){var e=G(this.widget);this==e.data("jQWCP.instance")&&(e.fadeOut(this.options.animDuration),G(h.ColorPicker.overlay).hide(),e.data("jQWCP.instance",null))},h.Handler={},h.Handler.input_focus_popup=function(e){var t=G(this).data("jQWCP.instance");t.show(),null==G(this).attr("readonly")&&(G(this).attr("readonly",!0),setTimeout(function(){G(t.input).removeAttr("readonly")}),null!=navigator.userAgent.match(/Android .* Firefox/)&&setTimeout(function(){G(t.input).attr("readonly",!0),G(t.input).one("blur",function(){G(t.input).removeAttr("readonly")})}))},h.Handler.input_blur_popup=function(e){var t=G(this).data("jQWCP.instance");t.options.hideKeyboard||(t.hide(),t.lastValue!=this.value&&G(this).trigger("change"))},h.Handler.input_keyup=function(e){var t=G(this).data("jQWCP.instance"),r=h.strToColor(this.value);r&&t.setColor(r,!1)},h.Handler.input_change=function(e){var t=G(this).data("jQWCP.instance"),r=h.strToColor(this.value);t.options.autoFormat&&r?t.setColor(r,!0):t.options.validate&&!r&&""!=this.value&&(this.value=t.getValue())},h.Handler.widget_focus_block=function(e){var t=G(this).data("jQWCP.instance"),r=G(t.input);t.lastValue=t.input.value,r.triggerHandler("focus")},h.Handler.widget_mousedown_popup=function(e){e.preventDefault();var t=G(this).data("jQWCP.instance"),r=G(t.input);if(r.off("focus.wheelColorPicker"),r.off("blur.wheelColorPicker"),null!=r.data("events"))var i=r.data("events").blur;else i=void 0;var s={blur:[]};if(null!=i)for(var a=0;a<i.length;a++)s.blur.push(i[a]);r.data("jQWCP.suspendedEvents",s)},h.Handler.widget_blur_block=function(e){var t=G(this).data("jQWCP.instance"),r=G(t.input);t.lastValue!=t.input.value&&r.trigger("change"),r.triggerHandler("blur")},h.Handler.wheelCursor_mousedown=function(e){e.preventDefault();var t=G(this),r=t.closest(".jQWCP-wWidget").data("jQWCP.instance"),i=G(r.input);G("body").data("jQWCP.activeControl",t.parent().get(0)),i.trigger("sliderdown")},h.Handler.wheel_mousedown=function(e){e.preventDefault();var t=G(this),r=t.closest(".jQWCP-wWidget").data("jQWCP.instance"),i=G(r.input);G("body").data("jQWCP.activeControl",t.get(0)),i.trigger("sliderdown"),r.updateActiveControl(e)},h.Handler.slider_mousedown=function(e){e.preventDefault();var t=G(this),r=t.closest(".jQWCP-wWidget").data("jQWCP.instance"),i=G(r.input);G("body").data("jQWCP.activeControl",t.parent().get(0)),i.trigger("sliderdown"),r.updateActiveControl(e)},h.Handler.sliderCursor_mousedown=function(e){e.preventDefault();var t=G(this),r=t.closest(".jQWCP-wWidget").data("jQWCP.instance"),i=G(r.input);G("body").data("jQWCP.activeControl",t.parent().get(0)),i.trigger("sliderdown")},h.Handler.html_mouseup=function(e){var t=G(G("body").data("jQWCP.activeControl"));if(t.length)var r=t.closest(".jQWCP-wWidget");else r=G("#jQWCP-popup");var i=r.data("jQWCP.instance");if(null!=i){var s=G(i.input);if("popup"==i.options.layout){i.options.hideKeyboard||s.trigger("focus.jQWCP_DONT_TRIGGER_EVENTS"),s.on("focus.wheelColorPicker",h.Handler.input_focus_popup),s.on("blur.wheelColorPicker",h.Handler.input_blur_popup);var a=s.data("jQWCP.suspendedEvents");if(null!=a)for(var o=a.blur,n=0;n<o.length;n++)s.on("blur"+(""==o[n].namespace?"":"."+o[n].namespace),o[n].handler)}0!=t.length&&("touchend"!=e.type&&i.updateActiveControl(e),G("body").data("jQWCP.activeControl",null),s.trigger("sliderup"))}},h.Handler.html_mousemove=function(e){var t=G(G("body").data("jQWCP.activeControl"));if(0!=t.length){e.preventDefault();var r=t.closest(".jQWCP-wWidget").data("jQWCP.instance"),i=G(r.input);return r.updateActiveControl(e),i.trigger("slidermove"),!1}},h.Handler.window_resize=function(e){G("body .jQWCP-wWidget.jQWCP-block").each(function(){var e=G(this).data("jQWCP.instance");e.refreshWidget(),e.redrawSliders()})},h.Handler.overlay_click=function(e){if(null!=h.ColorPicker.widget){var t=G(h.ColorPicker.widget).data("jQWCP.instance");if(null!=t){var r=G(t.input);t.lastValue!=t.input.value&&r.trigger("change"),t.hide()}}},G(document).ready(function(){G("[data-wheelcolorpicker]").wheelColorPicker({htmlOptions:!0})}),null!=G.browser&&G.browser.mozilla&&(G.fn.wheelColorPicker.defaults.quality=.2),G(document).ready(function(){G("body").append('<div id="jQWCP-PageOrigin" style="position: absolute; top: 0; left: 0; height: 0; width: 0;"></div>');var e=document.getElementById("jQWCP-PageOrigin").getBoundingClientRect();h.ORIGIN=e,G(window).on("scroll.jQWCP_RelativePageOriginBugFix",function(){var e=document.getElementById("jQWCP-PageOrigin").getBoundingClientRect();0==(h.ORIGIN=e).left&&0==e.top||(h.BUG_RELATIVE_PAGE_ORIGIN=!0)})})}(jQuery);