PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/admin/FileManager/JCrop/js/jquery.color.js

#
JavaScript | 123 lines | 84 code | 19 blank | 20 comment | 17 complexity | 8738618224090e7a179a6248cb00d1bb MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause
  1. /*
  2. * jQuery Color Animations
  3. * Copyright 2007 John Resig
  4. * Released under the MIT and GPL licenses.
  5. */
  6. (function(jQuery){
  7. // We override the animation for all of these color styles
  8. jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
  9. jQuery.fx.step[attr] = function(fx){
  10. if ( fx.state == 0 ) {
  11. fx.start = getColor( fx.elem, attr );
  12. fx.end = getRGB( fx.end );
  13. }
  14. fx.elem.style[attr] = "rgb(" + [
  15. Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
  16. Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
  17. Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
  18. ].join(",") + ")";
  19. }
  20. });
  21. // Color Conversion functions from highlightFade
  22. // By Blair Mitchelmore
  23. // http://jquery.offput.ca/highlightFade/
  24. // Parse strings looking for color tuples [255,255,255]
  25. function getRGB(color) {
  26. var result;
  27. // Check if we're already dealing with an array of colors
  28. if ( color && color.constructor == Array && color.length == 3 )
  29. return color;
  30. // Look for rgb(num,num,num)
  31. if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
  32. return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];
  33. // Look for rgb(num%,num%,num%)
  34. if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
  35. return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];
  36. // Look for #a0b1c2
  37. if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
  38. return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];
  39. // Look for #fff
  40. if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
  41. return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];
  42. // Otherwise, we're most likely dealing with a named color
  43. return colors[jQuery.trim(color).toLowerCase()];
  44. }
  45. function getColor(elem, attr) {
  46. var color;
  47. do {
  48. color = jQuery.curCSS(elem, attr);
  49. // Keep going until we find an element that has color, or we hit the body
  50. if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
  51. break;
  52. attr = "backgroundColor";
  53. } while ( elem = elem.parentNode );
  54. return getRGB(color);
  55. };
  56. // Some named colors to work with
  57. // From Interface by Stefan Petre
  58. // http://interface.eyecon.ro/
  59. var colors = {
  60. aqua:[0,255,255],
  61. azure:[240,255,255],
  62. beige:[245,245,220],
  63. black:[0,0,0],
  64. blue:[0,0,255],
  65. brown:[165,42,42],
  66. cyan:[0,255,255],
  67. darkblue:[0,0,139],
  68. darkcyan:[0,139,139],
  69. darkgrey:[169,169,169],
  70. darkgreen:[0,100,0],
  71. darkkhaki:[189,183,107],
  72. darkmagenta:[139,0,139],
  73. darkolivegreen:[85,107,47],
  74. darkorange:[255,140,0],
  75. darkorchid:[153,50,204],
  76. darkred:[139,0,0],
  77. darksalmon:[233,150,122],
  78. darkviolet:[148,0,211],
  79. fuchsia:[255,0,255],
  80. gold:[255,215,0],
  81. green:[0,128,0],
  82. indigo:[75,0,130],
  83. khaki:[240,230,140],
  84. lightblue:[173,216,230],
  85. lightcyan:[224,255,255],
  86. lightgreen:[144,238,144],
  87. lightgrey:[211,211,211],
  88. lightpink:[255,182,193],
  89. lightyellow:[255,255,224],
  90. lime:[0,255,0],
  91. magenta:[255,0,255],
  92. maroon:[128,0,0],
  93. navy:[0,0,128],
  94. olive:[128,128,0],
  95. orange:[255,165,0],
  96. pink:[255,192,203],
  97. purple:[128,0,128],
  98. violet:[128,0,128],
  99. red:[255,0,0],
  100. silver:[192,192,192],
  101. white:[255,255,255],
  102. yellow:[255,255,0]
  103. };
  104. })(jQuery);