svgedit/editor/jgraduate/jpicker-1.0.9.min.js

1 line
28 KiB
JavaScript
Raw Normal View History

(function(e,a){var d=function(n,k){var p=this,o=e("img",n),l=function(q){h(q);e(document).bind("mousemove",m).bind("mouseup",j);q.stopPropagation();q.preventDefault();return false;},m=function(q){h(q);q.stopPropagation();q.preventDefault();return false;},j=function(q){e(document).unbind("mouseup",j).unbind("mousemove",m);q.stopPropagation();q.preventDefault();return false;},h=function(u){var w=n.offset(),q=u.pageX-w.left-parseInt(n.css("border-left-width")),z=u.pageY-w.top-parseInt(n.css("border-top-width")),t=n.w,r=n.h,v,s;if(q<0){q=0;}else{if(q>t){q=t;}}if(z<0){z=0;}else{if(z>r){z=r;}}v=Math.floor(q/t*p.mxX);s=Math.floor(z/r*p.mxY);p.x=v;p.y=s;if(p.mxX==p.mnX){q=0;}if(p.mxY==p.mnY){z=0;}p.setArrowPosition(q,z);e.isFunction(p.valuesChanged)&&p.valuesChanged(p);};e.extend(true,p,{settings:k,x:0,y:0,mnX:0,mxX:0,mnY:100,mxY:100,valuesChanged:e.isFunction(arguments[2])&&arguments[2]||null,setPositioningVariables:function(r){var q=p.settings.map;n.w=q&&q.width||n.width();n.h=q&&q.height||n.height();p.MinX=0;p.MinY=0;p.MaxX=n.w;p.MaxY=n.h;},setArrowPositionFromValues:function(t){p.setPositioningVariables();var w=0,v=0,u=p.mnX,r=p.mxX,s=p.mnY,q=p.mxY,A=p.x,z=p.y;if(u!=r){if(A==u){w=0;}else{if(A==r){w=n.w;}else{if(u<1){r+=Math.abs(u)+1;}if(A<1){A+=1;}w=A/r*n.w;if(parseInt(w)==(r-1)){w=r;}else{w=parseInt(w);}if(u<1){w-=Math.abs(u)-1;}}}}if(s!=q){if(z==s){v=0;}else{if(z==q){v=n.h;}else{if(s<1){q+=Math.abs(s)+1;}if(z<1){z+=1;}v=z/q*n.h;if(parseInt(v)==(q-1)){v=q;}else{v=parseInt(v);}if(s<1){v-=Math.abs(s)-1;}}}}p.setArrowPosition(w,v);},setArrowPosition:function(q,v){var u=n.w,s=n.h,t=o.w,r=o.h;if(q<0){q=0;}else{if(q>u){q=u;}}if(v<0){v=0;}else{if(v>s){v=s;}}if(t>u){q=(u>>1)-(t>>1);}else{q-=t>>1;}if(r>s){v=(s>>1)-(r>>1);}else{v-=r>>1;}o.css({left:q+"px",top:v+"px"});},destroy:function(){e(document).unbind("mouseup",j).unbind("mousemove",m);n.unbind("mousedown",l);n=null;o=null;p.valuesChanged=null;}});o.src=p.settings.arrow&&p.settings.arrow.image;o.w=p.settings.arrow&&p.settings.arrow.width||o.width();o.h=p.settings.arrow&&p.settings.arrow.height||o.height();p.setPositioningVariables();n.bind("mousedown",l);p.setArrowPositionFromValues();e.isFunction(p.valuesChanged)&&p.valuesChanged(p);},b=function(n){var m=this,y=function(A){if(A.target.value==""){return;}t(A);m.setValuesFromHsv();e.isFunction(m.valuesChanged)&&m.valuesChanged(m);},s=function(A){if(A.target.value==""){return;}q(A);m.setValuesFromRgb();e.isFunction(m.valuesChanged)&&m.valuesChanged(m);},r=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();}},o=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();}},q=function(A){if(!p(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(!p(A)){return A;}u.alpha.val(h(u.alpha.val(),0,100));},t=function(A){if(!p(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(!p(A)){return A;}u.hex.val(u.hex.val().replace(/[^a-fA-F0-9]/g,"0").toLowerCase().substring(0,6));},p=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(".jPicker_HueText",n),saturation:e(".jPicker_SaturationText",n),value:e(".jPicker_BrightnessText",n),red:e(".jPicker_RedText",n),green:e(".jPicker_GreenText",n),blue:e(".jPicker_BlueText",n),hex:e(".jPicker_HexText",n),alpha:e(".jPicker_AlphaText",n)},valuesChanged:e.isFunction(arguments[1])&&arguments[1]||nul