2014-10-27 14:26:47 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor DataModel MWTable class.
|
|
|
|
*
|
2017-01-03 16:58:33 +00:00
|
|
|
* @copyright 2011-2017 VisualEditor Team and others; see AUTHORS.txt
|
2014-10-27 14:26:47 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DataModel MediaWiki table node.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.dm.TableNode
|
|
|
|
* @mixins ve.dm.ClassAttributeNode
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [element] Reference to element in linear model
|
|
|
|
* @param {ve.dm.Node[]} [children]
|
|
|
|
*/
|
|
|
|
ve.dm.MWTableNode = function VeDmMWTableNode() {
|
|
|
|
// Parent constructor
|
|
|
|
ve.dm.MWTableNode.super.apply( this, arguments );
|
|
|
|
|
|
|
|
// Mixin constructors
|
|
|
|
ve.dm.ClassAttributeNode.call( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.dm.MWTableNode, ve.dm.TableNode );
|
|
|
|
|
|
|
|
OO.mixinClass( ve.dm.MWTableNode, ve.dm.ClassAttributeNode );
|
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.dm.MWTableNode.static.name = 'mwTable';
|
|
|
|
|
|
|
|
ve.dm.MWTableNode.static.classAttributes = {
|
|
|
|
wikitable: { wikitable: true },
|
2017-02-03 21:36:52 +00:00
|
|
|
sortable: { sortable: true },
|
|
|
|
'mw-collapsible': { collapsible: true },
|
|
|
|
'mw-collapsed': { collapsed: true }
|
2014-10-27 14:26:47 +00:00
|
|
|
};
|
|
|
|
|
2017-04-27 17:30:23 +00:00
|
|
|
// Tables in wikitext only work in some contexts, they're impossible e.g. in list items
|
|
|
|
ve.dm.MWTableNode.static.suggestedParentNodeTypes = [ 'document', 'div', 'tableCell', 'tableCaption', 'mwImageCaption' ];
|
|
|
|
|
2014-10-27 14:26:47 +00:00
|
|
|
// HACK: users of parentNodeTypes should be fixed to check for inherited classes.
|
|
|
|
ve.dm.TableSectionNode.static.parentNodeTypes.push( 'mwTable' );
|
2014-10-30 18:38:26 +00:00
|
|
|
ve.dm.TableCaptionNode.static.parentNodeTypes.push( 'mwTable' );
|
2015-08-03 14:25:03 +00:00
|
|
|
ve.dm.TableRowNode.static.childNodeTypes.push( 'mwTransclusionTableCell' );
|
2014-10-27 14:26:47 +00:00
|
|
|
|
2016-01-29 17:44:02 +00:00
|
|
|
ve.dm.MWTableNode.static.toDataElement = function ( domElements ) {
|
2014-10-27 14:26:47 +00:00
|
|
|
var attributes = {},
|
|
|
|
dataElement = { type: this.name },
|
2015-08-19 17:33:02 +00:00
|
|
|
classAttr = domElements[ 0 ].getAttribute( 'class' );
|
2014-10-27 14:26:47 +00:00
|
|
|
|
|
|
|
this.setClassAttributes( attributes, classAttr );
|
|
|
|
|
|
|
|
if ( !ve.isEmptyObject( attributes ) ) {
|
|
|
|
dataElement.attributes = attributes;
|
|
|
|
}
|
|
|
|
return dataElement;
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.dm.MWTableNode.static.toDomElements = function ( dataElement, doc ) {
|
|
|
|
var element = doc.createElement( 'table' ),
|
2014-10-29 21:50:50 +00:00
|
|
|
classAttr = dataElement.attributes && this.getClassAttrFromAttributes( dataElement.attributes );
|
2014-10-27 14:26:47 +00:00
|
|
|
|
|
|
|
if ( classAttr ) {
|
|
|
|
element.className = classAttr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [ element ];
|
|
|
|
};
|
|
|
|
|
2016-01-29 17:44:02 +00:00
|
|
|
ve.dm.MWTableNode.static.sanitize = function ( dataElement ) {
|
|
|
|
// Mixin method
|
|
|
|
ve.dm.ClassAttributeNode.static.sanitize.call( this, dataElement );
|
|
|
|
|
|
|
|
ve.setProp( dataElement, 'attributes', 'wikitable', true );
|
|
|
|
};
|
|
|
|
|
2014-10-27 14:26:47 +00:00
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.MWTableNode );
|