| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
ve.dm.MWTableNode = function VeDmMWTableNode() { |
| 20 |
|
| 21 |
ve.dm.MWTableNode.super.apply( this, arguments ); |
| 22 |
|
| 23 |
|
| 24 |
ve.dm.ClassAttributeNode.call( this ); |
| 25 |
}; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
OO.inheritClass( ve.dm.MWTableNode, ve.dm.TableNode ); |
| 30 |
|
| 31 |
OO.mixinClass( ve.dm.MWTableNode, ve.dm.ClassAttributeNode ); |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
ve.dm.MWTableNode.static.name = 'mwTable'; |
| 36 |
|
| 37 |
ve.dm.MWTableNode.static.allowedRdfaTypes = [ 'mw:ExpandedAttrs' ]; |
| 38 |
|
| 39 |
ve.dm.MWTableNode.static.classAttributes = { |
| 40 |
wikitable: { wikitable: true }, |
| 41 |
sortable: { sortable: true }, |
| 42 |
'mw-collapsible': { collapsible: true }, |
| 43 |
'mw-collapsed': { collapsed: true } |
| 44 |
}; |
| 45 |
|
| 46 |
|
| 47 |
ve.dm.MWTableNode.static.suggestedParentNodeTypes = [ |
| 48 |
'document', 'div', 'tableCell', 'tableCaption', 'mwImageCaption', 'section', |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
'paragraph' |
| 54 |
]; |
| 55 |
|
| 56 |
|
| 57 |
ve.dm.TableSectionNode.static.parentNodeTypes.push( 'mwTable' ); |
| 58 |
ve.dm.TableCaptionNode.static.parentNodeTypes.push( 'mwTable' ); |
| 59 |
ve.dm.TableRowNode.static.childNodeTypes.push( 'mwTransclusionTableCell' ); |
| 60 |
|
| 61 |
ve.dm.MWTableNode.static.toDataElement = function ( domElements ) { |
| 62 |
const dataElement = { type: this.name }, |
| 63 |
domElement = domElements[ 0 ], |
| 64 |
classAttr = domElement.getAttribute( 'class' ); |
| 65 |
|
| 66 |
const attributes = { |
| 67 |
hasExpandedAttrs: ( domElement.getAttribute( 'typeof' ) || '' ).indexOf( 'mw:ExpandedAttrs' ) !== -1 |
| 68 |
}; |
| 69 |
|
| 70 |
this.setClassAttributes( attributes, classAttr ); |
| 71 |
|
| 72 |
dataElement.attributes = attributes; |
| 73 |
|
| 74 |
return dataElement; |
| 75 |
}; |
| 76 |
|
| 77 |
ve.dm.MWTableNode.static.toDomElements = function ( dataElement, doc ) { |
| 78 |
const element = doc.createElement( 'table' ), |
| 79 |
classAttr = dataElement.attributes && this.getClassAttrFromAttributes( dataElement.attributes ); |
| 80 |
|
| 81 |
if ( classAttr ) { |
| 82 |
|
| 83 |
element.className = classAttr; |
| 84 |
} |
| 85 |
|
| 86 |
return [ element ]; |
| 87 |
}; |
| 88 |
|
| 89 |
ve.dm.MWTableNode.static.sanitize = function ( dataElement ) { |
| 90 |
|
| 91 |
ve.dm.ClassAttributeNode.static.sanitize.call( this, dataElement ); |
| 92 |
|
| 93 |
ve.setProp( dataElement, 'attributes', 'wikitable', true ); |
| 94 |
}; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
ve.dm.modelRegistry.register( ve.dm.MWTableNode ); |