svgedit/editor/jpicker/jpicker.js

1 line
30 KiB
JavaScript
Raw Normal View History

(function(e,a){var d=function(h,q){var n=this,l=e("#"+h),p=e("#"+h+"_Arrow"),o=function(r){k(r);e(document).bind("mousemove",j).bind("mouseup",m);r.stopPropagation();r.preventDefault();return false;},j=function(r){k(r);r.stopPropagation();r.preventDefault();return false;},m=function(r){e(document).unbind("mouseup",m).unbind("mousemove",j);r.stopPropagation();r.preventDefault();return false;},k=function(v){var z=l.offset(),r=v.pageX-z.left-parseInt(l.css("border-left-width")),A=v.pageY-z.top-parseInt(l.css("border-top-width")),u=l.w,s=l.h,w,t;if(r<0){r=0;}else{if(r>u){r=u;}}if(A<0){A=0;}else{if(A>s){A=s;}}w=Math.floor(r/u*n.mxX);t=Math.floor(A/s*n.mxY);n.x=w;n.y=t;if(n.mxX==n.mnX){r=0;}if(n.mxY==n.mnY){A=0;}n.setArrowPosition(r,A);e.isFunction(n.valuesChanged)&&n.valuesChanged(n);};e.extend(true,n,{settings:q,x:0,y:0,mnX:0,mxX:0,mnY:100,mxY:100,valuesChanged:e.isFunction(arguments[2])&&arguments[2]||null,setPositioningVariables:function(s){var r=n.settings.map;l.w=r&&r.width||l.width();l.h=r&&r.height||l.height();n.MinX=0;n.MinY=0;n.MaxX=l.w;n.MaxY=l.h;},setArrowPositionFromValues:function(u){n.setPositioningVariables();var z=0,w=0,v=n.mnX,s=n.mxX,t=n.mnY,r=n.mxY,B=n.x,A=n.y;if(v!=s){if(B==v){z=0;}else{if(B==s){z=l.w;}else{if(v<1){s+=Math.abs(v)+1;}if(B<1){B+=1;}z=B/s*l.w;if(parseInt(z)==(s-1)){z=s;}else{z=parseInt(z);}if(v<1){z-=Math.abs(v)-1;}}}}if(t!=r){if(A==t){w=0;}else{if(A==r){w=l.h;}else{if(t<1){r+=Math.abs(t)+1;}if(A<1){A+=1;}w=A/r*l.h;if(parseInt(w)==(r-1)){w=r;}else{w=parseInt(w);}if(t<1){w-=Math.abs(t)-1;}}}}n.setArrowPosition(z,w);},setArrowPosition:function(r,w){var v=l.w,t=l.h,u=p.w,s=p.h;if(r<0){r=0;}else{if(r>v){r=v;}}if(w<0){w=0;}else{if(w>t){w=t;}}if(u>v){r=(v>>1)-(u>>1);}else{r-=u>>1;}if(s>t){w=(t>>1)-(s>>1);}else{w-=s>>1;}p.css({left:r+"px",top:w+"px"});},destroy:function(){e(document).unbind("mouseup",m).unbind("mousemove",j);l.unbind("mousedown",o);l=null;p=null;n.valuesChanged=null;}});p.src=n.settings.arrow&&n.settings.arrow.image;p.w=n.settings.arrow&&n.settings.arrow.width||p.width();p.h=n.settings.arrow&&n.settings.arrow.height||p.height();n.setPositioningVariables();l.bind("mousedown",o);n.setArrowPositionFromValues();e.isFunction(n.valuesChanged)&&n.valuesChanged(n);},b=function(t){var m=this,y=function(A){if(A.target.value==""){return;}s(A);m.setValuesFromHsv();e.isFunction(m.valuesChanged)&&m.valuesChanged(m);},r=function(A){if(A.target.value==""){return;}p(A);m.setValuesFromRgb();e.isFunction(m.valuesChanged)&&m.valuesChanged(m);},q=function(A){if(A.target.value==""){return;}l(A);w.a=A.target.value;e.isFunction(m.valuesChanged)&&m.valuesChanged(m);},v=function(A){if(A.target.value==""){m.setValuesFromRgb();}},k=function(A){if(A.target.value==""){m.setValuesFromHsv();}},n=function(A){if(A.target.value==""){u.alpha.val(100);}},z=function(A){if(A.target.value==""){return;}x(A);m.setValuesFromHex();e.isFunction(m.valuesChanged)&&m.valuesChanged(m);},j=function(A){if(A.target.value==""){m.setValuesFromHsv();}},p=function(A){if(!o(A)){return A;}u.red.val(h(u.red.val(),0,255));u.green.val(h(u.green.val(),0,255));u.blue.val(h(u.blue.val(),0,255));},l=function(A){if(!o(A)){return A;}u.alpha.val(h(u.alpha.val(),0,100));},s=function(A){if(!o(A)){return A;}u.hue.val(h(u.hue.val(),0,360));u.saturation.val(h(u.saturation.val(),0,100));u.value.val(h(u.value.val(),0,100));},x=function(A){if(!o(A)){return A;}u.hex.val(u.hex.val().replace(/[^a-fA-F0-9]/g,"0").toLowerCase().substring(0,6));},o=function(A){switch(A.keyCode){case 9:case 16:case 29:case 37:case 38:case 40:return false;case"c".charCodeAt():case"v".charCodeAt():if(A.ctrlKey){return false;}}return true;},h=function(C,B,A){if(C==""||isNaN(C)){return B;}C=parseInt(C);if(C>A){return A;}if(C<B){return B;}return C;};e.extend(true,m,{color:new f(),fields:{hue:e("#"+t+"_jPicker_Hue"),saturation:e("#"+t+"_jPicker_Saturation"),value:e("#"+t+"_jPicker_Brightness"),red:e("#"+t+"_jPicker_Red"),green:e("#"+t+"_jPicker_Green"),blue:e("#"+t+"_jPicker_Blue"),hex:e("#"+t+"_jPicker_Hex"),alpha:e("#"+t+"_jPicker_Alpha")},valuesChanged:e.isFunction(arguments[1])&