/** * jscolor, JavaScript Color Picker * * @version 1.3.1 * @license GNU Lesser General Public License, http://www.gnu.org/copyleft/lesser.html * @author Jan Odvarko, http://odvarko.cz * @created 2008-06-15 * @updated 2010-01-23 * @link http://jscolor.com */var jscolor={dir:"",binding:!0,preloading:!0,install:function(){jscolor.addEvent(window,"load",jscolor.init)},init:function(){jscolor.binding&&jscolor.bind(),jscolor.preloading&&jscolor.preload()},getDir:function(){if(!jscolor.dir){var a=jscolor.detectDir();jscolor.dir=a!==!1?a:"jscolor/"}return jscolor.dir},detectDir:function(){var a=location.href,b=document.getElementsByTagName("base");for(var c=0;ce[h]?-d[h]+b[h]+c[h]/2>e[h]/2&&b[h]+c[h]-f[h]>=0?b[h]+c[h]-f[h]:b[h]:b[h],-d[i]+b[i]+c[i]+f[i]-l+l*k>e[i]?-d[i]+b[i]+c[i]/2>e[i]/2&&b[i]+c[i]-l-l*k>=0?b[i]+c[i]-l-l*k:b[i]+c[i]-l+l*k:b[i]+c[i]-l+l*k>=0?b[i]+c[i]-l+l*k:b[i]+c[i]-l-l*k];g(m[h],m[i])}},this.importColor=function(){r?this.adjust?!this.required&&/^\s*$/.test(r.value)?(r.value="",s.style.backgroundColor=s.jscStyle.backgroundColor,s.style.color=s.jscStyle.color,this.exportColor(x|y)):this.fromString(r.value)||this.exportColor():this.fromString(r.value,x)||(s.style.backgroundColor=s.jscStyle.backgroundColor,s.style.color=s.jscStyle.color,this.exportColor(x|y)):this.exportColor()},this.exportColor=function(a){if(!(a&x)&&r){var b=this.toString();this.caps&&(b=b.toUpperCase()),this.hash&&(b="#"+b),r.value=b}!(a&y)&&s&&(s.style.backgroundColor="#"+this.toString(),s.style.color=.213*this.rgb[0]+.715*this.rgb[1]+.072*this.rgb[2]<.5?"#FFF":"#000"),!(a&z)&&j()&&h(),!(a&A)&&j()&&i()},this.fromHSV=function(a,b,c,d){a<0&&(a=0)||a>6&&(a=6),b<0&&(b=0)||b>1&&(b=1),c<0&&(c=0)||c>1&&(c=1),this.rgb=e(a===null?this.hsv[0]:this.hsv[0]=a,b===null?this.hsv[1]:this.hsv[1]=b,c===null?this.hsv[2]:this.hsv[2]=c),this.exportColor(d)},this.fromRGB=function(a,b,c,e){a<0&&(a=0)||a>1&&(a=1),b<0&&(b=0)||b>1&&(b=1),c<0&&(c=0)||c>1&&(c=1);var f=d(a===null?this.rgb[0]:this.rgb[0]=a,b===null?this.rgb[1]:this.rgb[1]=b,c===null?this.rgb[2]:this.rgb[2]=c);f[0]!==null&&(this.hsv[0]=f[0]),f[2]!==0&&(this.hsv[1]=f[1]),this.hsv[2]=f[2],this.exportColor(e)},this.fromString=function(a,b){var c=a.match(/^\W*([0-9A-F]{3}([0-9A-F]{3})?)\W*$/i);return c?(c[1].length===6?this.fromRGB(parseInt(c[1].substr(0,2),16)/255,parseInt(c[1].substr(2,2),16)/255,parseInt(c[1].substr(4,2),16)/255,b):this.fromRGB(parseInt(c[1].charAt(0)+c[1].charAt(0),16)/255,parseInt(c[1].charAt(1)+c[1].charAt(1),16)/255,parseInt(c[1].charAt(2)+c[1].charAt(2),16)/255,b),!0):!1},this.toString=function(){return(256|Math.round(255*this.rgb[0])).toString(16).substr(1)+(256|Math.round(255*this.rgb[1])).toString(16).substr(1)+(256|Math.round(255*this.rgb[2])).toString(16).substr(1)};var o=this,p=this.pickerMode.toLowerCase()==="hvs"?1:0,q=!1,r=jscolor.fetchElement(this.valueElement),s=jscolor.fetchElement(this.styleElement),t=!1,u=!1,v,w,x=1,y=2,z=4,A=8;jscolor.addEvent(a,"focus",function(){o.pickerOnfocus&&o.showPicker()}),jscolor.addEvent(a,"blur",function(){q?q=!1:window.setTimeout(function(){q||k(),q=!1},0)});if(r){var B=function(){o.fromString(r.value,x)};jscolor.addEvent(r,"keyup",B),jscolor.addEvent(r,"input",B),jscolor.addEvent(r,"blur",l),r.setAttribute("autocomplete","off")}s&&(s.jscStyle={backgroundColor:s.style.backgroundColor,color:s.style.color});switch(p){case 0:jscolor.requireImage("hs.png");break;case 1:jscolor.requireImage("hv.png")}jscolor.requireImage("cross.gif"),jscolor.requireImage("arrow.gif"),this.importColor()}};jscolor.install();