48860de0e8800c6b22898c92411f369f1ba67f92.svn-base 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. Ext.ColorPalette = function(A) {
  7. Ext.ColorPalette.superclass.constructor.call(this, A);
  8. this.addEvents("select");
  9. if (this.handler) {
  10. this.on("select", this.handler, this.scope, true)
  11. }
  12. };
  13. Ext.extend(Ext.ColorPalette, Ext.Component, {
  14. itemCls : "x-color-palette",
  15. value : null,
  16. clickEvent : "click",
  17. ctype : "Ext.ColorPalette",
  18. allowReselect : false,
  19. colors : ["000000", "993300", "333300", "003300", "003366", "000080",
  20. "333399", "333333", "800000", "FF6600", "808000", "008000",
  21. "008080", "0000FF", "666699", "808080", "FF0000", "FF9900",
  22. "99CC00", "339966", "33CCCC", "3366FF", "800080", "969696",
  23. "FF00FF", "FFCC00", "FFFF00", "00FF00", "00FFFF", "00CCFF",
  24. "993366", "C0C0C0", "FF99CC", "FFCC99", "FFFF99", "CCFFCC",
  25. "CCFFFF", "99CCFF", "CC99FF", "FFFFFF"],
  26. onRender : function(B, A) {
  27. var C = new Ext.XTemplate("<tpl for=\".\"><a href=\"#\" class=\"color-{.}\" hidefocus=\"on\"><em><span style=\"background:#{.}\" unselectable=\"on\">&#160;</span></em></a></tpl>");
  28. var D = document.createElement("div");
  29. D.className = this.itemCls;
  30. C.overwrite(D, this.colors);
  31. B.dom.insertBefore(D, A);
  32. this.el = Ext.get(D);
  33. this.el.on(this.clickEvent, this.handleClick, this, {
  34. delegate : "a"
  35. });
  36. if (this.clickEvent != "click") {
  37. this.el.on("click", Ext.emptyFn, this, {
  38. delegate : "a",
  39. preventDefault : true
  40. })
  41. }
  42. },
  43. afterRender : function() {
  44. Ext.ColorPalette.superclass.afterRender.call(this);
  45. if (this.value) {
  46. var A = this.value;
  47. this.value = null;
  48. this.select(A)
  49. }
  50. },
  51. handleClick : function(B, A) {
  52. B.preventDefault();
  53. if (!this.disabled) {
  54. var C = A.className.match(/(?:^|\s)color-(.{6})(?:\s|$)/)[1];
  55. this.select(C.toUpperCase())
  56. }
  57. },
  58. select : function(A) {
  59. A = A.replace("#", "");
  60. if (A != this.value || this.allowReselect) {
  61. var B = this.el;
  62. if (this.value) {
  63. B.child("a.color-" + this.value)
  64. .removeClass("x-color-palette-sel")
  65. }
  66. B.child("a.color-" + A).addClass("x-color-palette-sel");
  67. this.value = A;
  68. this.fireEvent("select", this, A)
  69. }
  70. }
  71. });
  72. Ext.reg("colorpalette", Ext.ColorPalette);