alignexecution.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. Trex.I.AlignExecution = Trex.Mixin.create(/** @lends Trex.I.AlignExecution */{
  2. executeAlignImageMode: function(processor) {
  3. var _imageAlignProps = this.constructor.__ImageModeProps['image'];
  4. var _node = processor.getControl();
  5. if(!_node) {
  6. return;
  7. }
  8. processor.apply(_node, _imageAlignProps);
  9. var _textAlignProps = this.constructor.__ImageModeProps['paragraph'];
  10. if (_textAlignProps) {
  11. var _wNode = $tom.find(_node, "%paragraph");
  12. processor.apply(_wNode, _textAlignProps);
  13. }
  14. },
  15. executeAlignTextMode: function(processor) {
  16. var _textAlignProps = this.constructor.__TextModeProps['paragraph'];
  17. var _node = processor.getControl();
  18. if(_node && $tom.kindOf(_node, 'button') ) {
  19. var _wNode = $tom.find(_node, '%paragraph');
  20. if (_wNode) {
  21. processor.apply(_wNode, _textAlignProps);
  22. }
  23. var _tNode = $tom.collect(_node, 'blockquote'); //NOTE: # FTDUEDTR-1027
  24. if(_tNode) {
  25. _tNode.style.margin = this.constructor.__TextModeProps['button']['style']['margin'];
  26. }
  27. } else {
  28. var _nodes = processor.blocks(function(){
  29. return '%paragraph';
  30. });
  31. processor.apply(_nodes, _textAlignProps);
  32. var _controlNodes = [];
  33. _nodes.each(function (node) {
  34. var tables;
  35. tables = $tom.collectAll(node, 'table,hr');
  36. tables.each(function (table) {
  37. _controlNodes.push(table);
  38. });
  39. });
  40. processor.apply(_controlNodes, {
  41. 'align': _textAlignProps['style']['textAlign']
  42. });
  43. }
  44. },
  45. queryImageFloat: function(processor) {
  46. var _node = processor.getControl();
  47. if (_node) {
  48. return processor.queryStyle(_node, 'float');
  49. } else {
  50. return _NULL;
  51. }
  52. },
  53. queryParaFloat: function(processor) {
  54. var _value, _node = processor.findNode('%paragraph');
  55. if (_node) {
  56. _value = processor.queryStyle(_node, 'float');
  57. }
  58. return _value || _NULL;
  59. },
  60. queryTextAlign: function(processor) {
  61. var _node = processor.findNode('%paragraph');
  62. var _value = processor.queryStyle(_node, 'textAlign');
  63. if(!_value) {
  64. _value = processor.queryAttr(_node, 'align');
  65. }
  66. if(!_value || _value == "start" || _value == "auto" || _value == "-webkit-auto") {
  67. _value = 'left';
  68. }
  69. return _value;
  70. },
  71. queryControlAlign: function(processor) {
  72. var node = processor.getControl();
  73. return processor.queryAttr(node, 'align');
  74. },
  75. executeAlign: function(processor) {
  76. var tool = this;
  77. var alignMode = tool.getAlignMode(processor);
  78. if (alignMode == "tableCell") {
  79. tool.executeTableCellMode(processor);
  80. } else if (alignMode == "image") {
  81. tool.executeAlignImageMode(processor);
  82. } else {
  83. tool.executeAlignTextMode(processor);
  84. }
  85. },
  86. getAlignMode: function(processor) {
  87. var selectedTdArr = (processor.table) ? processor.table.getTdArr() : [];
  88. if (selectedTdArr.length > 0) {
  89. return "tableCell";
  90. } else if (this.imageAlignMode) {
  91. return "image";
  92. } else {
  93. return "text";
  94. }
  95. },
  96. executeTableCellMode: function(processor) {
  97. if (!this.indenter) {
  98. var Judge = Trex.Tool.Indent.Judge;
  99. var ChainHandler = Trex.ChainHandler;
  100. var self = this;
  101. function alignBlockNode(node) {
  102. $tom.applyAttributes(node, self.constructor.__TextModeProps.paragraph);
  103. }
  104. var defaultAlign = ChainHandler.connect([
  105. new ChainHandler(Judge.ListItem, alignBlockNode),
  106. new ChainHandler(Judge.BlockNode, alignBlockNode)
  107. ]);
  108. this.indenter = new Trex.Tool.Indent.TableCellIndenter(defaultAlign);
  109. }
  110. this.indenter.indent(processor);
  111. },
  112. syncButtonState: function() {
  113. var self = this;
  114. var state = self.canvas.query(function(processor) {
  115. return self.queryCurrentStyle(processor);
  116. });
  117. self.button.setState(state);
  118. },
  119. queryCurrentStyle: function(processor) {
  120. if (this.imageAlignMode) {
  121. return this.queryImageMode(processor)
  122. }
  123. return this.queryTextMode(processor);
  124. },
  125. queryImageMode: function(processor) {
  126. var imageModeProps = this.constructor.__ImageModeProps;
  127. var currentImageFloat = this.queryImageFloat(processor);
  128. if (currentImageFloat && currentImageFloat != 'none') {
  129. if (imageModeProps.image && imageModeProps.image.style['float']) {
  130. return (currentImageFloat == imageModeProps.image.style['float']);
  131. }
  132. }
  133. var currentParaFloat = this.queryParaFloat(processor);
  134. if (currentParaFloat && currentParaFloat != 'none') {
  135. if (imageModeProps.paragraph && imageModeProps.paragraph.style['float']) {
  136. return (currentParaFloat == imageModeProps.paragraph.style['float']);
  137. }
  138. }
  139. var currentTextAlign = this.queryTextAlign(processor);
  140. if (imageModeProps.paragraph && imageModeProps.paragraph.style.textAlign) {
  141. return (currentTextAlign == imageModeProps.paragraph.style.textAlign);
  142. }
  143. return _FALSE;
  144. },
  145. queryTextMode: function(processor) {
  146. var textModeProps = this.constructor.__TextModeProps;
  147. var textAlign = textModeProps.paragraph.style.textAlign;
  148. var controlAlign = this.queryControlAlign(processor);
  149. if (controlAlign == _NULL) {
  150. var align = this.queryTextAlign(processor) || 'left';
  151. return (align == textAlign);
  152. } else {
  153. return (controlAlign == textAlign);
  154. }
  155. }
  156. });