mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
2 lines
7.1 KiB
JavaScript
2 lines
7.1 KiB
JavaScript
!function(a){var b=!1;a.fn.farbtastic=function(b){return a.farbtastic(this,b),this},a.farbtastic=function(b,c){var b=a(b)[0];return b.farbtastic||(b.farbtastic=new a._farbtastic(b,c))},a._farbtastic=function(c,d){var e=this;e.linkTo=function(b){return"object"==typeof e.callback&&a(e.callback).unbind("keyup",e.updateValue),e.color=null,"function"==typeof b?e.callback=b:("object"==typeof b||"string"==typeof b)&&(e.callback=a(b),e.callback.bind("keyup",e.updateValue),e.callback[0].value&&e.setColor(e.callback[0].value)),this},e.updateValue=function(){this.value&&this.value!=e.color&&e.setColor(this.value)},e.setColor=function(a){var b=e.unpack(a);return e.color!=a&&b&&(e.color=a,e.rgb=b,e.hsl=e.RGBToHSL(e.rgb),e.updateDisplay()),this},e.setHSL=function(a){return e.hsl=a,e.rgb=e.HSLToRGB(a),e.color=e.pack(e.rgb),e.updateDisplay(),this},e.initWidget=function(){var b={width:d.width,height:d.width};a(c).html('<div class="farbtastic" style="position: relative"><div class="farbtastic-solid"></div><canvas class="farbtastic-mask"></canvas><canvas class="farbtastic-overlay"></canvas></div>').find("*").attr(b).css(b).end().find("div>*").css("position","absolute"),a.browser.msie||!1,e.radius=(d.width-d.wheelWidth)/2-1,e.square=Math.floor(.7*(e.radius-d.wheelWidth/2))-1,e.mid=Math.floor(d.width/2),e.markerSize=.3*d.wheelWidth,e.solidFill=a(".farbtastic-solid",c).css({width:2*e.square-1,height:2*e.square-1,left:e.mid-e.square,top:e.mid-e.square}),e.cnvMask=a(".farbtastic-mask",c),e.ctxMask=e.cnvMask[0].getContext("2d"),e.cnvOverlay=a(".farbtastic-overlay",c),e.ctxOverlay=e.cnvOverlay[0].getContext("2d"),e.ctxMask.translate(e.mid,e.mid),e.ctxOverlay.translate(e.mid,e.mid),e.drawCircle(),e.drawMask()},e.drawCircle=function(){var c,f,g=+new Date,h=24,i=e.radius,j=d.wheelWidth,k=8/i/h*Math.PI,l=e.ctxMask,m=0;l.save(),l.lineWidth=j/i,l.scale(i,i);for(var n=0;h>=n;++n){var o=n/h,p=o*Math.PI*2,q=Math.sin(m),r=-Math.cos(m);if(x2=Math.sin(p),y2=-Math.cos(p),am=(m+p)/2,tan=1/Math.cos((p-m)/2),xm=Math.sin(am)*tan,ym=-Math.cos(am)*tan,color2=e.pack(e.HSLToRGB([o,1,.5])),n>0)if(a.browser.msie){var s=(1+Math.min(Math.abs(Math.tan(m)),Math.abs(Math.tan(Math.PI/2-m))))/h;c=e.pack(e.HSLToRGB([f-.15*s,1,.5])),color2=e.pack(e.HSLToRGB([o+.15*s,1,.5]));var t=l.createLinearGradient(q,r,x2,y2);t.addColorStop(0,c),t.addColorStop(1,color2),l.fillStyle=t;var u=(i+j/2)/i,v=(i-j/2)/i;l.beginPath(),l.moveTo(q*u,r*u),l.quadraticCurveTo(xm*u,ym*u,x2*u,y2*u),l.lineTo(x2*v,y2*v),l.quadraticCurveTo(xm*v,ym*v,q*v,r*v),l.fill()}else{var t=l.createLinearGradient(q,r,x2,y2);t.addColorStop(0,c),t.addColorStop(1,color2),l.strokeStyle=t,l.beginPath(),l.moveTo(q,r),l.quadraticCurveTo(xm,ym,x2,y2),l.stroke()}m=p-k,c=color2,f=o}l.restore(),b&&a("body").append("<div>drawCircle "+(+new Date-g)+"ms")},e.drawMask=function(){function c(a,b,c){for(var d=1/a,e=1/b,f=0;b>=f;++f)for(var g=1-f*e,h=0;a>=h;++h){var i=1-h*d,j=1-2*Math.min(g*i,(1-g)*i),k=j>0?.5*(2*g-1+j)/j:0;c(h,f,k,j)}}var d=+new Date,f=2*e.square,g=e.square;if(e.ctxMask.getImageData){var h=Math.floor(f/2),i=document.createElement("canvas");i.width=i.height=h+1;var j=i.getContext("2d"),k=j.getImageData(0,0,h+1,h+1),l=0;c(h,h,function(a,b,c,d){k.data[l++]=k.data[l++]=k.data[l++]=255*c,k.data[l++]=255*d}),j.putImageData(k,0,0),e.ctxMask.drawImage(i,0,0,h+1,h+1,-g,-g,2*g,2*g)}else if(a.browser.msie){var m,n,o=6,p=Math.floor(f/o);c(p,6,function(b,c,d,f){if(0==b&&(m=n,n=[]),d=Math.round(255*d),f=Math.round(255*f),c>0){var h=m[b][0],i=m[b][1],j=e.packDX(h,i),k=e.packDX(d,f),l=Math.round(e.mid+(.333*(c-1)-1)*g),q=Math.round(e.mid+(.333*c-1)*g);a("<div>").css({position:"absolute",filter:"progid:DXImageTransform.Microsoft.Gradient(StartColorStr="+j+", EndColorStr="+k+", GradientType=0)",top:l,height:q-l,left:e.mid+(b*o-g-1),width:o-(b==p?Math.round(o/2):0)}).appendTo(e.cnvMask)}n.push([d,f])})}else{var h=Math.floor(f/2);c(h,h,function(a,b,c,d){c=Math.round(255*c),e.ctxMask.fillStyle="rgba("+c+", "+c+", "+c+", "+d+")",e.ctxMask.fillRect(2*a-g-1,2*b-g-1,2,2)})}b&&a("body").append("<div>drawMask "+(+new Date-d)+"ms")},e.drawMarkers=function(){var a=d.width,b=Math.ceil(e.markerSize/4),c=e.markerSize-b+1,f=6.28*e.hsl[0],g=Math.sin(f)*e.radius,h=-Math.cos(f)*e.radius,i=2*e.square*(.5-e.hsl[1]),j=2*e.square*(.5-e.hsl[2]),k=e.invert?"#fff":"#000",l=e.invert?"#000":"#fff",m=[{x:g,y:h,r:c,c:"#000",lw:b+1},{x:g,y:h,r:e.markerSize,c:"#fff",lw:b},{x:i,y:j,r:c,c:l,lw:b+1},{x:i,y:j,r:e.markerSize,c:k,lw:b}];e.ctxOverlay.clearRect(-e.mid,-e.mid,a,a);for(var n=0;n<m.length;n++){var o=m[n];e.ctxOverlay.lineWidth=o.lw,e.ctxOverlay.strokeStyle=o.c,e.ctxOverlay.beginPath(),e.ctxOverlay.arc(o.x,o.y,o.r,0,2*Math.PI,!0),e.ctxOverlay.stroke()}},e.updateDisplay=function(){e.invert=.3*e.rgb[0]+.59*e.rgb[1]+.11*e.rgb[2]<=.6,e.solidFill.css("backgroundColor",e.pack(e.HSLToRGB([e.hsl[0],1,.5]))),e.drawMarkers(),"object"==typeof e.callback?(a(e.callback).css({backgroundColor:e.color,color:e.invert?"#fff":"#000"}),a(e.callback).each(function(){"string"==typeof this.value&&this.value!=e.color&&(this.value=e.color)}).change()):"function"==typeof e.callback&&e.callback.call(e,e.color)},e.widgetCoords=function(a){return{x:a.pageX-e.offset.left-e.mid,y:a.pageY-e.offset.top-e.mid}},e.mousedown=function(b){a._farbtastic.dragging||(a(document).bind("mousemove",e.mousemove).bind("mouseup",e.mouseup),a._farbtastic.dragging=!0),e.offset=a(c).offset();var d=e.widgetCoords(b);return e.circleDrag=Math.max(Math.abs(d.x),Math.abs(d.y))>e.square+2,e.mousemove(b),!1},e.mousemove=function(a){var b=e.widgetCoords(a);if(e.circleDrag){var c=Math.atan2(b.x,-b.y)/6.28;e.setHSL([(c+1)%1,e.hsl[1],e.hsl[2]])}else{var d=Math.max(0,Math.min(1,-(b.x/e.square/2)+.5)),f=Math.max(0,Math.min(1,-(b.y/e.square/2)+.5));e.setHSL([e.hsl[0],d,f])}return!1},e.mouseup=function(){a(document).unbind("mousemove",e.mousemove),a(document).unbind("mouseup",e.mouseup),a._farbtastic.dragging=!1},e.dec2hex=function(a){return(16>a?"0":"")+a.toString(16)},e.packDX=function(a,b){return"#"+e.dec2hex(b)+e.dec2hex(a)+e.dec2hex(a)+e.dec2hex(a)},e.pack=function(a){var b=Math.round(255*a[0]),c=Math.round(255*a[1]),d=Math.round(255*a[2]);return"#"+e.dec2hex(b)+e.dec2hex(c)+e.dec2hex(d)},e.unpack=function(a){function b(b){return parseInt(a.substring(b,b+2),16)/255}function b(b){return parseInt(a.substring(b,b+1),16)/15}return 7==a.length?[b(1),b(3),b(5)]:4==a.length?[b(1),b(2),b(3)]:void 0},e.HSLToRGB=function(a){var b,c,d=a[0],e=a[1],f=a[2];return c=.5>=f?f*(e+1):f+e-f*e,b=2*f-c,[this.hueToRGB(b,c,d+.33333),this.hueToRGB(b,c,d),this.hueToRGB(b,c,d-.33333)]},e.hueToRGB=function(a,b,c){return c=(c+1)%1,1>6*c?a+(b-a)*c*6:1>2*c?b:2>3*c?a+(b-a)*(.66666-c)*6:a},e.RGBToHSL=function(a){var b=a[0],c=a[1],d=a[2],e=Math.min(b,c,d),f=Math.max(b,c,d),g=f-e,h=0,i=0,j=(e+f)/2;return j>0&&1>j&&(i=g/(.5>j?2*j:2-2*j)),g>0&&(f==b&&f!=c&&(h+=(c-d)/g),f==c&&f!=d&&(h+=2+(d-b)/g),f==d&&f!=b&&(h+=4+(b-c)/g),h/=6),[h,i,j]},d.callback||(d={callback:d}),d=a.extend({width:300,wheelWidth:(d.width||300)/10,callback:null},d),e.initWidget(),a("canvas.farbtastic-overlay",c).mousedown(e.mousedown),d.callback&&e.linkTo(d.callback),e.color||e.setColor("#808080")}}(jQuery);
|
|
//# sourceMappingURL=../../maps/libs/farbtastic.js.map
|