cellslinepreview.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. Trex.MarkupTemplate.add(
  2. 'cellsline.preview', [
  3. '<table width="#{width}" cellPadding="0" style="line-height:0"><tbody><tr>',
  4. '<td valign="center" height="#{height}">',
  5. '<div style="border-bottom:#{value};width:#{width}px;height:2px;overflow:hidden;"></div>',
  6. '</td>',
  7. '</tr></tbody></table>'
  8. ].join('')
  9. );
  10. TrexConfig.addTool(
  11. "cellslinepreview", {
  12. sync: _FALSE,
  13. status: _TRUE,
  14. options: [{
  15. label: Trex.MarkupTemplate.get('cellsline.preview').evaluate({
  16. value: '1pt solid #ccc',
  17. width: 70,
  18. height: 14
  19. }),
  20. title: '1pt solid #ccc',
  21. data: '#ccc 1 solid'
  22. }, {
  23. label: Trex.MarkupTemplate.get('cellsline.preview').evaluate({
  24. value: '2pt solid #c54',
  25. width: 70,
  26. height: 14
  27. }),
  28. title: '2pt solid #c54',
  29. data: '#c54 2 solid'
  30. }, {
  31. label: Trex.MarkupTemplate.get('cellsline.preview').evaluate({
  32. value: '2pt solid #67f',
  33. width: 70,
  34. height: 14
  35. }),
  36. title: '2pt solid #67f',
  37. data: '#67f 2 solid'
  38. }, {
  39. label: Trex.MarkupTemplate.get('cellsline.preview').evaluate({
  40. value: '3pt solid #000',
  41. width: 70,
  42. height: 14
  43. }),
  44. title: '3pt solid #000',
  45. data: '#000 3 solid'
  46. }, {
  47. label: Trex.MarkupTemplate.get('cellsline.preview').evaluate({
  48. value: '1pt dashed #d4c',
  49. width: 70,
  50. height: 14
  51. }),
  52. title: '1pt dashed #d4c',
  53. data: '#d4c 1 dashed'
  54. }]
  55. }
  56. );
  57. Trex.Tool.Cellslinepreview = Trex.Class.create({
  58. $const: {
  59. __Identity: 'cellslinepreview'
  60. },
  61. $extend: Trex.Tool,
  62. oninitialized: function(config) {
  63. var self = this;
  64. this.data = {
  65. color: '',
  66. height: 0,
  67. type: ''
  68. };
  69. this.weave(
  70. new Trex.Button.CellslinepreviewList(this.buttonCfg),
  71. new Trex.Menu.Select(this.menuCfg),
  72. this.handler);
  73. this.toolbar.observeJob(Trex.Ev.__TOOL_CELL_LINE_CHANGE, function(data){
  74. self.setData(data);
  75. self.refreshPreview();
  76. });
  77. },
  78. setData: function(data){
  79. if ("color" in data) {
  80. this.data.color = data.color;
  81. }
  82. if ("height" in data) {
  83. this.data.height = data.height;
  84. }
  85. if ("type" in data) {
  86. this.data.type = data.type;
  87. }
  88. },
  89. refreshPreview: function(){
  90. var data;
  91. data = this.data;
  92. text = data.height + "pt " + data.type + " " + data.color;
  93. this.setPreview(text);
  94. },
  95. setPreview: function(value){
  96. this.button.elText.innerHTML = Trex.MarkupTemplate.get('cellsline.preview').evaluate({
  97. value: value,
  98. width: 43,
  99. height: 14
  100. });
  101. },
  102. addBorderHistory: function(data){
  103. this.setData(data);
  104. this.refreshPreview();
  105. },
  106. handler: function(data, title){
  107. var self = this, canvas = self.canvas;
  108. canvas.execute(function(processor) {
  109. var datas;
  110. if (processor.table) {
  111. datas = data.split(" ");
  112. processor.table.setBorderButtons(datas[0], datas[1], datas[2]);
  113. }
  114. });
  115. }
  116. });
  117. Trex.Button.CellslinepreviewList = Trex.Class.create({
  118. $extend: Trex.Button.Select,
  119. setText: function(text) {
  120. this.tool.setPreview(text);
  121. }
  122. });