jquery.xcolor.min.js 14 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. jQuery paging plugin v1.8.0 06/21/2010
  3. http://www.xarg.org/project/jquery-color-plugin-xcolor/
  4. Copyright (c) 2010, Robert Eisele (robert@xarg.org)
  5. Dual licensed under the MIT or GPL Version 2 licenses.
  6. */
  7. (function(h,k){function e(a){function d(a,b){var d;k!==a&&(a=parseFloat(a));if(k===b)d=b=255;else if(1===b){if(k===a||1===a)return 1;b=100;d=1}else d=b;return isNaN(a)||0>=a?0:b<a?d:1>a||1===b?1===d?a:a*d|0:a*d/b}function b(a,b,c){function e(a,b,d){d=++d%1;return 1>6*d?a+6*(b-a)*d:1>2*d?b:2>3*d?a+(b-a)*(4-6*d):a}a=d(a,360)/360;b=d(b,1);c=d(c,1);if(0===b)return c=Math.round(255*c),[c,c,c];b=0.5>c?c+c*b:c+b-c*b;c=c+c-b;return[Math.round(255*e(c,b,a+1/3)),Math.round(255*e(c,b,a)),Math.round(255*e(c,
  8. b,a-1/3))]}function c(a,b,c){a=d(a,360)/60;b=d(b,1);c=d(c,1);var e=a|0,n=a-e;a=Math.round(255*c*(1-b));var l=Math.round(255*c*(1-b*n));b=Math.round(255*c*(1-b*(1-n)));c=Math.round(255*c);switch(e){case 1:return[l,c,a];case 2:return[a,c,b];case 3:return[a,l,c];case 4:return[b,a,c];case 5:return[c,a,l]}return[c,b,a]}this.setColor=function(a){this.c=!0;if("number"===typeof a)this.a=(a>>24&255)/255,this.r=a>>16&255,this.g=a>>8&255,this.b=a&255;else{for(;"object"===typeof a;){if(0 in a&&1 in a&&2 in a){this.a=
  9. d(a[3],1);this.r=d(a[0]);this.g=d(a[1]);this.b=d(a[2]);return}if("r"in a&&"g"in a&&"b"in a){this.a=d(a.a,1);this.r=d(a.r);this.g=d(a.g);this.b=d(a.b);return}if("h"in a&&"s"in a){var f;if("l"in a)f=b(a.h,a.s,a.l);else if("v"in a)f=c(a.h,a.s,a.v);else if("b"in a)f=c(a.h,a.s,a.b);else break;this.a=d(a.a,1);this.r=f[0];this.g=f[1];this.b=f[2];return}break}if("string"===typeof a){a=a.toLowerCase().replace(/[^a-z0-9,.()#%]/g,"");if("transparent"===a){this.a=this.r=this.g=this.b=0;return}if("rand"===a){a=
  10. 16777215*Math.random()|0;this.a=1;this.r=a>>16&255;this.g=a>>8&255;this.b=a&255;return}k!==q[a]&&(a="#"+q[a]);if(f=/^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/.exec(a)){this.a=1;this.r=parseInt(f[1],16);this.g=parseInt(f[2],16);this.b=parseInt(f[3],16);return}if(f=/^#?([0-9a-f])([0-9a-f])([0-9a-f])$/.exec(a)){this.a=1;this.r=parseInt(f[1]+f[1],16);this.g=parseInt(f[2]+f[2],16);this.b=parseInt(f[3]+f[3],16);return}if(f=/^rgba?\((\d{1,3}),(\d{1,3}),(\d{1,3})(,([0-9.]+))?\)$/.exec(a)){this.a=d(f[5],
  11. 1);this.r=d(f[1]);this.g=d(f[2]);this.b=d(f[3]);return}if(f=/^rgba?\(([0-9.]+\%),([0-9.]+\%),([0-9.]+\%)(,([0-9.]+)\%?)?\)$/.exec(a)){this.a=d(f[5],1);this.r=Math.round(2.55*d(f[1],100));this.g=Math.round(2.55*d(f[2],100));this.b=Math.round(2.55*d(f[3],100));return}if(f=/^hs([bvl])a?\((\d{1,3}),(\d{1,3}),(\d{1,3})(,([0-9.]+))?\)$/.exec(a)){a=("l"===f[1]?b:c)(parseInt(f[2],10),parseInt(f[3],10),parseInt(f[4],10));this.a=d(f[6],1);this.r=a[0];this.g=a[1];this.b=a[2];return}if(f=/^(\d{1,3}),(\d{1,3}),(\d{1,3})(,([0-9.]+))?$/.exec(a)){this.a=
  12. d(f[5],1);this.r=d(f[1]);this.g=d(f[2]);this.b=d(f[3]);return}}this.c=!1}};this.getColor=function(a){if(k!==a)switch(a.toLowerCase()){case "rgb":return this.getRGB();case "hsv":case "hsb":return this.getHSV();case "hsl":return this.getHSL();case "int":return this.getInt();case "array":return this.getArray();case "fraction":return this.getFraction();case "css":case "style":return this.getCSS();case "name":return this.getName()}return this.getHex()};this.getRGB=function(){return this.c?{r:this.r,g:this.g,
  13. b:this.b,a:this.a}:null};this.getCSS=function(){return this.c?0===this.a?"transparent":1===this.a?"rgb("+this.r+","+this.g+","+this.b+")":r(this.r,this.g,this.b,this.a):null};this.getArray=function(){return this.c?[this.r,this.g,this.b,100*this.a|0]:null};this.getName=function(){if(this.c){var a=null,b,d=q,c=this.getHSL(),n;for(n in d){var l=(new e(d[n])).getHSL(),l=Math.sqrt(0.5*(c.h-l.h)*(c.h-l.h)+0.5*(c.s-l.s)*(c.s-l.s)+(c.l-l.l)*(c.l-l.l));if(null===a||l<a)a=l,b=n}return b}return null};this.getFraction=
  14. function(){return this.c?{r:this.r/255,g:this.g/255,b:this.b/255,a:this.a}:null};this.getHSL=function(){if(this.c){var a=this.r/255,b=this.g/255,d=this.b/255,c=Math.min(a,b,d),e=Math.max(a,b,d),l=e-c,h=(e+c)/2;0===l?c=a=0:(a=a===e?(b-d)/l:b===e?2+(d-a)/l:4+(a-b)/l,c=l/(0.5>h?e+c:2-e-c));return{h:Math.round((6+a)%6*60),s:Math.round(100*c),l:Math.round(100*h),a:this.a}}return null};this.getHSV=function(){if(this.c){var a=this.r/255,b=this.g/255,c=this.b/255,d=Math.min(a,b,c),e=Math.max(a,b,c),d=e-d;
  15. return{h:Math.round((6+(0===d?0:a===e?(b-c)/d:b===e?2+(c-a)/d:4+(a-b)/d))%6*60),s:Math.round(100*(0===e?0:d/e)),v:Math.round(100*e),a:this.a}}return null};this.getHex=function(){return this.c?"#"+"0123456789abcdef".charAt(this.r>>4)+"0123456789abcdef".charAt(this.r&15)+"0123456789abcdef".charAt(this.g>>4)+"0123456789abcdef".charAt(this.g&15)+"0123456789abcdef".charAt(this.b>>4)+"0123456789abcdef".charAt(this.b&15):null};this.getInt=function(a){return this.c?k!==a?(100*this.a|0)<<24^this.r<<16^this.g<<
  16. 8^this.b:(this.r<<16^this.g<<8^this.b)&16777215:null};this.toString=function(){return this.getHex()};this.setColor(a)}function s(a,d){var b="";do if(b=h.css(a,d),""!==b&&"transparent"!==b&&"rgba(0, 0, 0, 0)"!==b||h.nodeName(a,"body"))break;while(a=a.parentNode);""===b&&(b=h.support.rgba?"transparent":"backgroundColor"===d?"white":"black");return new e(b)}var q={aliceblue:"f0f8ff",antiquewhite:"faebd7",aqua:"0ff",aquamarine:"7fffd4",azure:"f0ffff",beige:"f5f5dc",bisque:"ffe4c4",black:"000",blanchedalmond:"ffebcd",
  17. blue:"00f",blueviolet:"8a2be2",brown:"a52a2a",burlywood:"deb887",burntsienna:"ea7e5d",cadetblue:"5f9ea0",chartreuse:"7fff00",chocolate:"d2691e",coral:"ff7f50",cornflowerblue:"6495ed",cornsilk:"fff8dc",crimson:"dc143c",cyan:"0ff",darkblue:"00008b",darkcyan:"008b8b",darkgoldenrod:"b8860b",darkgray:"a9a9a9",darkgreen:"006400",darkgrey:"a9a9a9",darkkhaki:"bdb76b",darkmagenta:"8b008b",darkolivegreen:"556b2f",darkorange:"ff8c00",darkorchid:"9932cc",darkred:"8b0000",darksalmon:"e9967a",darkseagreen:"8fbc8f",
  18. darkslateblue:"483d8b",darkslategray:"2f4f4f",darkslategrey:"2f4f4f",darkturquoise:"00ced1",darkviolet:"9400d3",deeppink:"ff1493",deepskyblue:"00bfff",dimgray:"696969",dimgrey:"696969",dodgerblue:"1e90ff",firebrick:"b22222",floralwhite:"fffaf0",forestgreen:"228b22",fuchsia:"f0f",gainsboro:"dcdcdc",ghostwhite:"f8f8ff",gold:"ffd700",goldenrod:"daa520",gray:"808080",green:"008000",greenyellow:"adff2f",grey:"808080",honeydew:"f0fff0",hotpink:"ff69b4",indianred:"cd5c5c",indigo:"4b0082",ivory:"fffff0",
  19. khaki:"f0e68c",lavender:"e6e6fa",lavenderblush:"fff0f5",lawngreen:"7cfc00",lemonchiffon:"fffacd",lightblue:"add8e6",lightcoral:"f08080",lightcyan:"e0ffff",lightgoldenrodyellow:"fafad2",lightgray:"d3d3d3",lightgreen:"90ee90",lightgrey:"d3d3d3",lightpink:"ffb6c1",lightsalmon:"ffa07a",lightseagreen:"20b2aa",lightskyblue:"87cefa",lightslategray:"789",lightslategrey:"789",lightsteelblue:"b0c4de",lightyellow:"ffffe0",lime:"0f0",limegreen:"32cd32",linen:"faf0e6",magenta:"f0f",maroon:"800000",mediumaquamarine:"66cdaa",
  20. mediumblue:"0000cd",mediumorchid:"ba55d3",mediumpurple:"9370db",mediumseagreen:"3cb371",mediumslateblue:"7b68ee",mediumspringgreen:"00fa9a",mediumturquoise:"48d1cc",mediumvioletred:"c71585",midnightblue:"191970",mintcream:"f5fffa",mistyrose:"ffe4e1",moccasin:"ffe4b5",navajowhite:"ffdead",navy:"000080",oldlace:"fdf5e6",olive:"808000",olivedrab:"6b8e23",orange:"ffa500",orangered:"ff4500",orchid:"da70d6",palegoldenrod:"eee8aa",palegreen:"98fb98",paleturquoise:"afeeee",palevioletred:"db7093",papayawhip:"ffefd5",
  21. peachpuff:"ffdab9",peru:"cd853f",pink:"ffc0cb",plum:"dda0dd",powderblue:"b0e0e6",purple:"800080",red:"f00",rosybrown:"bc8f8f",royalblue:"4169e1",saddlebrown:"8b4513",salmon:"fa8072",sandybrown:"f4a460",seagreen:"2e8b57",seashell:"fff5ee",sienna:"a0522d",silver:"c0c0c0",skyblue:"87ceeb",slateblue:"6a5acd",slategray:"708090",slategrey:"708090",snow:"fffafa",springgreen:"00ff7f",steelblue:"4682b4",tan:"d2b48c",teal:"008080",thistle:"d8bfd8",tomato:"ff6347",turquoise:"40e0d0",violet:"ee82ee",wheat:"f5deb3",
  22. white:"fff",whitesmoke:"f5f5f5",yellow:"ff0",yellowgreen:"9acd32"},r;h.each("color backgroundColor borderColor borderTopColor borderBottomColor borderLeftColor borderRightColor outlineColor".split(" "),function(a,d){h.cssHooks[d]={set:function(a,c){a.style[d]=(new e(c)).getCSS()}};h.fx.step[d]=function(a){if(k===a.xinit){if("string"===typeof a.end&&-1!==a.end.indexOf(";")){var c,g=a.end.split(";");if(2<g.length){for(c in g)g[c]=-1===g[c].indexOf("native")?new e(g[c]):s(a.elem,d);a.start=null;a.end=
  23. g}else a.start=new e(g[0]),a.end=new e(g[1])}else a.start=s(a.elem,d),a.end=new e(a.end);a.xinit=1}c=a.start;var g=a.end,f=a.pos;if(null===c){var h=f*(g.length-1),f=1>f?h|0:g.length-2;c=g[f];g=g[f+1];f=h-f}a.elem.style[d]=r(c.r+f*(g.r-c.r)|0,c.g+f*(g.g-c.g)|0,c.b+f*(g.b-c.b)|0,c.a+f*(g.a-c.a))}});h(function(){var a=document.createElement("div").style;r=function(a,b,c,e){return"rgba("+a+","+b+","+c+","+e+")"};a.cssText="background-color:rgba(1,1,1,.5)";(h.support.rgba=-1<a.backgroundColor.indexOf("rgba"))||
  24. (r=function(a,b,c){return"rgb("+a+","+b+","+c+")"})});h.xcolor=new function(){this.test=function(a){a=new e(a);return a.c?a:null};this.red=function(a){a=new e(a);return a.c?(a.g=255,a.b=255,a):null};this.blue=function(a){a=new e(a);return a.c?(a.r=255,a.g=255,a):null};this.green=function(a){a=new e(a);return a.c?(a.r=255,a.b=255,a):null};this.sepia=function(a){a=new e(a);if(a.c){var d=a.r,b=a.g,c=a.b;a.r=Math.round(0.393*d+0.769*b+0.189*c);a.g=Math.round(0.349*d+0.686*b+0.168*c);a.b=Math.round(0.272*
  25. d+0.534*b+0.131*c);return a}return null};this.random=function(){return new e([255*Math.random()|0,255*Math.random()|0,255*Math.random()|0])};this.inverse=function(a){a=new e(a);return a.c?(a.r^=255,a.g^=255,a.b^=255,a):null};this.opacity=function(a,d,b){a=new e(a);d=new e(d);return a.c&d.c?(1<b&&(b/=100),b=Math.max(b-1+d.a,0),a.r=Math.round((d.r-a.r)*b+a.r),a.g=Math.round((d.g-a.g)*b+a.g),a.b=Math.round((d.b-a.b)*b+a.b),a):null};this.greyfilter=function(a,d){var b,c=new e(a);if(c.c){switch(d){case 1:b=
  26. 0.35+13*(c.r+c.g+c.b)/60;break;case 2:b=(13*(c.r+c.g+c.b)+5355)/60;break;default:b=0.3*c.r+0.59*c.g+0.11*c.b}c.r=c.g=c.b=Math.min(b|0,255);return c}return null};this.webround=function(a){a=new e(a);return a.c?(255<(a.r+=51-a.r%51)&&(a.r=255),255<(a.g+=51-a.g%51)&&(a.g=255),255<(a.b+=51-a.b%51)&&(a.b=255),a):null};this.distance=function(a,d){var b=new e(a),c=new e(d);return b.c&c.c?Math.sqrt(3*(c.r-b.r)*(c.r-b.r)+4*(c.g-b.g)*(c.g-b.g)+2*(c.b-b.b)*(c.b-b.b)):null};this.readable=function(a,d,b){d=new e(d);
  27. a=new e(a);b=b||10;return d.c&a.c?(a=0.299*a.r+0.587*a.g+0.114*a.b-0.299*d.r-0.587*d.g-0.114*d.b,!(a<1.5+141.162*Math.pow(0.975,b)&&a>-0.5-154.709*Math.pow(0.99,b))):null};this.combine=function(a,d){var b=new e(a),c=new e(d);return b.c&c.c?(b.r^=c.r,b.g^=c.g,b.b^=c.b,b):null};this.breed=function(a,d){var b=new e(a),c=new e(d),g=0,f=6;if(b.c&c.c){for(;f--;)0.5>Math.random()&&(g|=15<<(f<<2));b.r=b.r&g>>16&255|c.r&(g>>16&255^255);b.g=b.g&g>>8&255|c.g&(g>>8&255^255);b.b=b.b&g>>0&255|c.b&(g>>0&255^255);
  28. return b}return null};this.additive=function(a,d){var b=new e(a),c=new e(d);return b.c&c.c?(255<(b.r+=c.r)&&(b.r=255),255<(b.g+=c.g)&&(b.g=255),255<(b.b+=c.b)&&(b.b=255),b):null};this.subtractive=function(a,d){var b=new e(a),c=new e(d);return b.c&c.c?(0>(b.r+=c.r-255)&&(b.r=0),0>(b.g+=c.g-255)&&(b.g=0),0>(b.b+=c.b-255)&&(b.b=0),b):null};this.subtract=function(a,d){var b=new e(a),c=new e(d);return b.c&c.c?(0>(b.r-=c.r)&&(b.r=0),0>(b.g-=c.g)&&(b.g=0),0>(b.b-=c.b)&&(b.b=0),b):null};this.multiply=function(a,
  29. d){var b=new e(a),c=new e(d);return b.c&c.c?(b.r=b.r/255*c.r|0,b.g=b.g/255*c.g|0,b.b=b.b/255*c.b|0,b):null};this.average=function(a,d){var b=new e(a),c=new e(d);return b.c&c.c?(b.r=b.r+c.r>>1,b.g=b.g+c.g>>1,b.b=b.b+c.b>>1,b):null};this.triad=function(a){a=new e(a);return a.c?[a,new e([a.b,a.r,a.g]),new e([a.g,a.b,a.r])]:null};this.tetrad=function(a){a=new e(a);return a.c?[a,new e([a.b,a.r,a.b]),new e([a.b,a.g,a.r]),new e([a.r,a.b,a.r])]:null};this.gradientlevel=function(a,d,b,c){k===c&&(c=1);if(b>
  30. c)return null;a=new e(a);d=new e(d);return a.c&d.c?(a.r=a.r+(d.r-a.r)/c*b|0,a.g=a.g+(d.g-a.g)/c*b|0,a.b=a.b+(d.b-a.b)/c*b|0,a):null};this.gradientarray=function(a,d,b){if(d>b||!a.length)return null;if(1==a.length)return new e(a[0]);var c=d*(a.length-1)/(b+1)|0;b=b/(a.length-1);return h.xcolor.gradientlevel(a[c],a[c+1],d-c*b,b)};this.nearestname=function(a){a=new e(a);return a.c?a.getName():null};this.darken=function(a,d,b){if(k===d)d=1;else if(0>d)return this.lighten(a,-d,b);k===b&&(b=32);a=new e(a);
  31. return a.c?(0>(a.r-=b*d)&&(a.r=0),0>(a.g-=b*d)&&(a.g=0),0>(a.b-=b*d)&&(a.b=0),a):null};this.lighten=function(a,d,b){if(k===d)d=1;else if(0>d)return this.darken(a,-d,b);k===b&&(b=32);a=new e(a);return a.c?(255<(a.r+=b*d)&&(a.r=255),255<(a.g+=b*d)&&(a.g=255),255<(a.b+=b*d)&&(a.b=255),a):null};this.analogous=function(a,d,b){k===d&&(d=8);k===b&&(b=30);var c=new e(a);if(c.c){a=c.getHSV();b=360/b;c=[c];for(a.h=(a.h-(b*d>>1)+720)%360;--d;)a.h+=b,a.h%=360,c.push(new e(a));return c}return null};this.complementary=
  32. function(a){a=new e(a);return a.c?(a=a.getHSL(),a.h=(a.h+180)%360,new e(a)):null};this.splitcomplement=function(a){var d=new e(a);return d.c?(a=d.getHSV(),d=[d],a.h+=72,a.h%=360,d.push(new e(a)),a.h+=144,a.h%=360,d.push(new e(a)),d):null};this.monochromatic=function(a,d){k===d&&(d=6);var b=new e(a);if(b.c){for(var c=b.getHSV(),b=[b];--d;)c.v+=20,c.v%=100,b.push(new e(c));return b}return null}};h.fn.readable=function(){var a=this[0],d="",b="";do if(""!==d||"transparent"!==(d=h.css(a,"color"))&&"rgba(0, 0, 0, 0)"!==
  33. d||(d=""),""!==b||"transparent"!==(b=h.css(a,"backgroundColor"))&&"rgba(0, 0, 0, 0)"!==b||(b=""),""!==d&&""!==b||h.nodeName(a,"body"))break;while(a=a.parentNode);""===d&&(d="black");""===b&&(b="white");return h.xcolor.readable(b,d)};h.fn.colorize=function(a,d,b){var c={gradient:function(a,b){return a/b},flip:function(a,b,c,d){return" "===d?c:!c},pillow:function(a,b){a*=2;return a<=b?a/b:2-a/b}};if("function"!==typeof b){if(void 0===c[b])return;b=c[b]}a=new e(a);d=new e(d);this.each(function(){var c=
  34. this.childNodes,e=0,h=0;if(a.c&d.c){for(var k=c.length;k--;e+=c[k].textContent.length);(function l(c){var g=0,k;if(3===c.nodeType){var m=a,t=d,q=e,u,v,p=0,w,s=b;k=c.nodeValue.length;v=document.createElement("span");for(g=0;g<k;++g)u=document.createElement("span"),w=c.nodeValue.charAt(g),p=s(h,q,p,w),u.style.color=r(m.r+p*(t.r-m.r)|0,m.g+p*(t.g-m.g)|0,m.b+p*(t.b-m.b)|0,m.a+p*(t.a-m.a)),u.appendChild(document.createTextNode(w)),v.appendChild(u),++h;c.parentNode.replaceChild(v,c)}else for(k=c.childNodes.length;g<
  35. k;++g)l(c.childNodes[g])})(this)}})}})(jQuery);