| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- Trex.I.AlignExecution = Trex.Mixin.create(/** @lends Trex.I.AlignExecution */{
- executeAlignImageMode: function(processor) {
- var _imageAlignProps = this.constructor.__ImageModeProps['image'];
- var _node = processor.getControl();
- if(!_node) {
- return;
- }
- processor.apply(_node, _imageAlignProps);
- var _textAlignProps = this.constructor.__ImageModeProps['paragraph'];
- if (_textAlignProps) {
- var _wNode = $tom.find(_node, "%paragraph");
- processor.apply(_wNode, _textAlignProps);
- }
- },
- executeAlignTextMode: function(processor) {
- var _textAlignProps = this.constructor.__TextModeProps['paragraph'];
- var _node = processor.getControl();
- if(_node && $tom.kindOf(_node, 'button') ) {
- var _wNode = $tom.find(_node, '%paragraph');
- if (_wNode) {
- processor.apply(_wNode, _textAlignProps);
- }
- var _tNode = $tom.collect(_node, 'blockquote'); //NOTE: # FTDUEDTR-1027
- if(_tNode) {
- _tNode.style.margin = this.constructor.__TextModeProps['button']['style']['margin'];
- }
- } else {
- var _nodes = processor.blocks(function(){
- return '%paragraph';
- });
- processor.apply(_nodes, _textAlignProps);
- var _controlNodes = [];
- _nodes.each(function (node) {
- var tables;
- tables = $tom.collectAll(node, 'table,hr');
- tables.each(function (table) {
- _controlNodes.push(table);
- });
- });
- processor.apply(_controlNodes, {
- 'align': _textAlignProps['style']['textAlign']
- });
- }
- },
- queryImageFloat: function(processor) {
- var _node = processor.getControl();
- if (_node) {
- return processor.queryStyle(_node, 'float');
- } else {
- return _NULL;
- }
- },
- queryParaFloat: function(processor) {
- var _value, _node = processor.findNode('%paragraph');
- if (_node) {
- _value = processor.queryStyle(_node, 'float');
- }
- return _value || _NULL;
- },
- queryTextAlign: function(processor) {
- var _node = processor.findNode('%paragraph');
- var _value = processor.queryStyle(_node, 'textAlign');
- if(!_value) {
- _value = processor.queryAttr(_node, 'align');
- }
- if(!_value || _value == "start" || _value == "auto" || _value == "-webkit-auto") {
- _value = 'left';
- }
- return _value;
- },
- queryControlAlign: function(processor) {
- var node = processor.getControl();
- return processor.queryAttr(node, 'align');
- },
- executeAlign: function(processor) {
- var tool = this;
- var alignMode = tool.getAlignMode(processor);
- if (alignMode == "tableCell") {
- tool.executeTableCellMode(processor);
- } else if (alignMode == "image") {
- tool.executeAlignImageMode(processor);
- } else {
- tool.executeAlignTextMode(processor);
- }
- },
- getAlignMode: function(processor) {
- var selectedTdArr = (processor.table) ? processor.table.getTdArr() : [];
- if (selectedTdArr.length > 0) {
- return "tableCell";
- } else if (this.imageAlignMode) {
- return "image";
- } else {
- return "text";
- }
- },
- executeTableCellMode: function(processor) {
- if (!this.indenter) {
- var Judge = Trex.Tool.Indent.Judge;
- var ChainHandler = Trex.ChainHandler;
- var self = this;
- function alignBlockNode(node) {
- $tom.applyAttributes(node, self.constructor.__TextModeProps.paragraph);
- }
- var defaultAlign = ChainHandler.connect([
- new ChainHandler(Judge.ListItem, alignBlockNode),
- new ChainHandler(Judge.BlockNode, alignBlockNode)
- ]);
- this.indenter = new Trex.Tool.Indent.TableCellIndenter(defaultAlign);
- }
- this.indenter.indent(processor);
- },
- syncButtonState: function() {
- var self = this;
- var state = self.canvas.query(function(processor) {
- return self.queryCurrentStyle(processor);
- });
- self.button.setState(state);
- },
- queryCurrentStyle: function(processor) {
- if (this.imageAlignMode) {
- return this.queryImageMode(processor)
- }
- return this.queryTextMode(processor);
- },
- queryImageMode: function(processor) {
- var imageModeProps = this.constructor.__ImageModeProps;
- var currentImageFloat = this.queryImageFloat(processor);
- if (currentImageFloat && currentImageFloat != 'none') {
- if (imageModeProps.image && imageModeProps.image.style['float']) {
- return (currentImageFloat == imageModeProps.image.style['float']);
- }
- }
- var currentParaFloat = this.queryParaFloat(processor);
- if (currentParaFloat && currentParaFloat != 'none') {
- if (imageModeProps.paragraph && imageModeProps.paragraph.style['float']) {
- return (currentParaFloat == imageModeProps.paragraph.style['float']);
- }
- }
- var currentTextAlign = this.queryTextAlign(processor);
- if (imageModeProps.paragraph && imageModeProps.paragraph.style.textAlign) {
- return (currentTextAlign == imageModeProps.paragraph.style.textAlign);
- }
- return _FALSE;
- },
- queryTextMode: function(processor) {
- var textModeProps = this.constructor.__TextModeProps;
- var textAlign = textModeProps.paragraph.style.textAlign;
- var controlAlign = this.queryControlAlign(processor);
- if (controlAlign == _NULL) {
- var align = this.queryTextAlign(processor) || 'left';
- return (align == textAlign);
- } else {
- return (controlAlign == textAlign);
- }
- }
- });
|