border.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. Trex.Table.Border = Trex.Class.create({
  2. $const: {
  3. BORDER_STYLE:"1px solid #ccc"
  4. },
  5. initialize: function(editor, config){
  6. var canvas;
  7. canvas = editor.getCanvas();
  8. this.wysiwygPanel = canvas.getPanel(Trex.Canvas.__WYSIWYG_MODE);
  9. this.borderRange = "all";
  10. this.borderColor = "#4174D9";
  11. this.tableSelect = _NULL;
  12. this.selectedBoundary = _NULL;
  13. },
  14. setBorderRange: function(value){
  15. this.borderRange = value;
  16. },
  17. setTableSelect: function(tableSelect){
  18. this.tableSelect = tableSelect;
  19. this.selectedBoundary = tableSelect.getSelected();
  20. },
  21. changeTopBorderStyle: function(tdArr, styleType, value){
  22. var style = {};
  23. var boundary = this.selectedBoundary;
  24. var borderStyle, tdArray ;
  25. var indexer = this.tableSelect.getIndexer();
  26. var tempBoundary;
  27. if (boundary.top == 0){
  28. borderStyle = "borderTop" + styleType;
  29. tempBoundary = new Trex.TableUtil.Boundary({
  30. "top": boundary.top,
  31. "bottom": boundary.top,
  32. "left": boundary.left,
  33. "right": boundary.right
  34. });
  35. } else {
  36. borderStyle = "borderBottom" + styleType;
  37. tempBoundary = new Trex.TableUtil.Boundary({
  38. "top" : boundary.top-1,
  39. "bottom" : boundary.top-1,
  40. "left" : boundary.left,
  41. "right" : boundary.right
  42. });
  43. }
  44. tdArray = indexer.getTdArr(tempBoundary);
  45. style[borderStyle] = value;
  46. for(var i=0; i< tdArray.length; i++){
  47. $tx.setStyle(tdArray[i], style);
  48. }
  49. },
  50. changeBottomBorderStyle: function(tdArr, styleType, value){
  51. var style = {};
  52. var boundary = this.selectedBoundary;
  53. var borderStyle, tdArray, tempBoundary ;
  54. var indexer = this.tableSelect.getIndexer();
  55. borderStyle = "borderBottom" + styleType;
  56. tempBoundary = new Trex.TableUtil.Boundary({
  57. "top" : boundary.bottom,
  58. "bottom" : boundary.bottom,
  59. "left" : boundary.left,
  60. "right" : boundary.right
  61. });
  62. tdArray = indexer.getTdArr(tempBoundary);
  63. style[borderStyle] = value;
  64. for(var i=0; i< tdArray.length; i++){
  65. $tx.setStyle(tdArray[i], style);
  66. }
  67. },
  68. changeLeftBorderStyle: function(tdArr, styleType, value){
  69. var style = {};
  70. var boundary = this.selectedBoundary;
  71. var borderStyle, tdArray ;
  72. var indexer = this.tableSelect.getIndexer();
  73. var tempBoundary;
  74. if (boundary.left == 0){
  75. borderStyle = "borderLeft" + styleType;
  76. tempBoundary = new Trex.TableUtil.Boundary({
  77. "top": boundary.top,
  78. "bottom": boundary.bottom,
  79. "left": boundary.left,
  80. "right": boundary.left
  81. });
  82. } else {
  83. borderStyle = "borderRight" + styleType;
  84. tempBoundary = new Trex.TableUtil.Boundary({
  85. "top" : boundary.top,
  86. "bottom" : boundary.bottom,
  87. "left" : boundary.left-1,
  88. "right" : boundary.left-1
  89. });
  90. }
  91. tdArray = indexer.getTdArr(tempBoundary);
  92. style[borderStyle] = value;
  93. for(var i=0; i< tdArray.length; i++){
  94. $tx.setStyle(tdArray[i], style);
  95. }
  96. },
  97. changeRightBorderStyle: function(tdArr, styleType, value){
  98. var style = {};
  99. var boundary = this.selectedBoundary;
  100. var borderStyle, tdArray ;
  101. var indexer = this.tableSelect.getIndexer();
  102. var tempBoundary;
  103. borderStyle = "borderRight" + styleType;
  104. tempBoundary = new Trex.TableUtil.Boundary({
  105. "top" : boundary.top,
  106. "bottom" : boundary.bottom,
  107. "left" : boundary.right,
  108. "right" : boundary.right
  109. });
  110. tdArray = indexer.getTdArr(tempBoundary);
  111. style[borderStyle] = value;
  112. for(var i=0; i< tdArray.length; i++){
  113. $tx.setStyle(tdArray[i], style);
  114. }
  115. },
  116. changeInBorderStyle: function(tdArr, styleType, value){
  117. var colStyle = {};
  118. var rowStyle = {};
  119. var boundary = this.selectedBoundary;
  120. var colTdArray, rowTdArray, colBorderStyle, rowBorderStyle;
  121. var colBoundary, rowBoundary;
  122. var indexer = this.tableSelect.getIndexer();
  123. colBorderStyle = "borderBottom" + styleType;
  124. colBoundary = new Trex.TableUtil.Boundary({
  125. "top" : boundary.top,
  126. "bottom" : boundary.bottom - 1 ,
  127. "left" : boundary.left,
  128. "right" : boundary.right
  129. });
  130. colTdArray = indexer.getTdArr(colBoundary);
  131. colStyle[colBorderStyle] = value;
  132. for(var i=0; i< colTdArray.length; i++){
  133. $tx.setStyle(colTdArray[i], colStyle);
  134. }
  135. rowBorderStyle = "borderRight" + styleType;
  136. rowBoundary = new Trex.TableUtil.Boundary({
  137. "top" : boundary.top,
  138. "bottom" : boundary.bottom,
  139. "left" : boundary.left,
  140. "right" : boundary.right-1
  141. });
  142. rowTdArray = indexer.getTdArr(rowBoundary);
  143. rowStyle[rowBorderStyle] = value;
  144. for(var i=0; i< rowTdArray.length; i++){
  145. $tx.setStyle(rowTdArray[i], rowStyle);
  146. }
  147. },
  148. changeOutBorderStyle: function(tdArr, styleType, value){
  149. this.changeTopBorderStyle( tdArr, styleType, value );
  150. this.changeBottomBorderStyle( tdArr, styleType, value );
  151. this.changeLeftBorderStyle( tdArr, styleType, value );
  152. this.changeRightBorderStyle( tdArr, styleType, value );
  153. },
  154. changeNoneBorderStyle: function(tdArr, styleType, value){
  155. },
  156. changeBorderStyle: function( tdArr, styleType, value ){
  157. var borderRange = this.borderRange;
  158. switch(borderRange){
  159. case "top":
  160. this.changeTopBorderStyle( tdArr, styleType, value );
  161. break;
  162. case "bottom":
  163. this.changeBottomBorderStyle( tdArr, styleType, value );
  164. break;
  165. case "left":
  166. this.changeLeftBorderStyle( tdArr, styleType, value );
  167. break;
  168. case "right":
  169. this.changeRightBorderStyle( tdArr, styleType, value );
  170. break;
  171. case "in":
  172. this.changeInBorderStyle( tdArr, styleType, value );
  173. break;
  174. case "out":
  175. this.changeOutBorderStyle( tdArr, styleType, value );
  176. break;
  177. case "all":
  178. this.changeInBorderStyle( tdArr, styleType, value );
  179. this.changeOutBorderStyle( tdArr, styleType, value );
  180. break;
  181. case "none":
  182. this.changeInBorderStyle( tdArr, styleType, value );
  183. this.changeOutBorderStyle( tdArr, styleType, value );
  184. break;
  185. default:
  186. break;
  187. }
  188. },
  189. changeBorderColor: function(tdArr, value){
  190. if (value != _NULL) {
  191. this.borderColor = value;
  192. }
  193. this.changeBorderStyle(tdArr, "Color", this.borderColor);
  194. },
  195. changeBorderType: function(tdArr, value){
  196. this.changeBorderStyle(tdArr, "Style", value );
  197. this.changeBorderColor(tdArr);
  198. },
  199. changeBorderHeight: function(tdArr, value){
  200. var width = value.toPx();
  201. this.changeBorderStyle( tdArr, "Width", width );
  202. this.changeBorderColor(tdArr);
  203. }
  204. });