| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
ve.ce.TableCellNode = function VeCeTableCellNode() { |
| 19 |
|
| 20 |
ve.ce.TableCellNode.super.apply( this, arguments ); |
| 21 |
|
| 22 |
|
| 23 |
ve.ce.TableCellableNode.call( this ); |
| 24 |
ve.ce.ContentEditableNode.call( this ); |
| 25 |
|
| 26 |
this.setEditing( false ); |
| 27 |
|
| 28 |
|
| 29 |
this.model.connect( this, { |
| 30 |
update: 'onUpdate', |
| 31 |
attributeChange: 'onAttributeChange' |
| 32 |
} ); |
| 33 |
this.connect( this, { |
| 34 |
teardown: 'onTableCellTeardown' |
| 35 |
} ); |
| 36 |
}; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
OO.inheritClass( ve.ce.TableCellNode, ve.ce.BranchNode ); |
| 41 |
|
| 42 |
OO.mixinClass( ve.ce.TableCellNode, ve.ce.TableCellableNode ); |
| 43 |
OO.mixinClass( ve.ce.TableCellNode, ve.ce.ContentEditableNode ); |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
ve.ce.TableCellNode.static.name = 'tableCell'; |
| 48 |
|
| 49 |
ve.ce.TableCellNode.static.trapsCursor = true; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
ve.ce.TableCellNode.prototype.initialize = function () { |
| 57 |
|
| 58 |
ve.ce.TableCellNode.super.prototype.initialize.call( this ); |
| 59 |
|
| 60 |
const rowspan = this.model.getRowspan(); |
| 61 |
const colspan = this.model.getColspan(); |
| 62 |
|
| 63 |
|
| 64 |
this.$element |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
.addClass( 've-ce-tableCellNode ve-ce-tableCellNode-' + this.model.getAttribute( 'style' ) ); |
| 69 |
|
| 70 |
|
| 71 |
if ( rowspan > 1 ) { |
| 72 |
this.$element.attr( 'rowspan', rowspan ); |
| 73 |
} |
| 74 |
if ( colspan > 1 ) { |
| 75 |
this.$element.attr( 'colspan', colspan ); |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
this.$element.attr( 'title', ve.msg( 'visualeditor-tablecell-tooltip' ) ); |
| 80 |
}; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
ve.ce.TableCellNode.prototype.setEditing = function ( enable ) { |
| 88 |
this.editing = enable; |
| 89 |
this.$element.toggleClass( 've-ce-tableCellNode-editing', enable ); |
| 90 |
this.setContentEditable(); |
| 91 |
if ( this.getRoot() ) { |
| 92 |
this.getRoot().getSurface().setActiveNode( enable ? this : null ); |
| 93 |
} |
| 94 |
if ( enable ) { |
| 95 |
this.$element.removeAttr( 'title' ); |
| 96 |
} else { |
| 97 |
this.$element.attr( 'title', ve.msg( 'visualeditor-tablecell-tooltip' ) ); |
| 98 |
} |
| 99 |
}; |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
ve.ce.TableCellNode.prototype.onTableCellTeardown = function () { |
| 107 |
|
| 108 |
|
| 109 |
if ( this.getRoot() ) { |
| 110 |
const surface = this.getRoot().getSurface(); |
| 111 |
if ( surface.getActiveNode() === this ) { |
| 112 |
surface.setActiveNode( null ); |
| 113 |
} |
| 114 |
} |
| 115 |
}; |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
ve.ce.TableCellNode.prototype.setContentEditable = function () { |
| 122 |
|
| 123 |
|
| 124 |
return ve.ce.ContentEditableNode.prototype.setContentEditable.call( this, this.editing ); |
| 125 |
}; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
ve.ce.TableCellNode.prototype.onUpdate = function () { |
| 133 |
this.updateTagName(); |
| 134 |
}; |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
ve.ce.TableCellNode.prototype.onAttributeChange = function ( key, from, to ) { |
| 144 |
switch ( key ) { |
| 145 |
case 'colspan': |
| 146 |
case 'rowspan': |
| 147 |
if ( to > 1 ) { |
| 148 |
this.$element.attr( key, to ); |
| 149 |
} else { |
| 150 |
this.$element.removeAttr( key ); |
| 151 |
} |
| 152 |
break; |
| 153 |
case 'style': |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
this.$element |
| 158 |
.removeClass( 've-ce-tableCellNode-' + from ) |
| 159 |
.addClass( 've-ce-tableCellNode-' + to ); |
| 160 |
this.updateTagName(); |
| 161 |
break; |
| 162 |
} |
| 163 |
}; |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
ve.ce.nodeFactory.register( ve.ce.TableCellNode ); |