mediawiki-extensions-Visual.../modules/ve-mw/dm/nodes/ve.dm.MWTableNode.js
James D. Forrester 2f8b3e0d96 build: Bump copyright notices to 2015
Change-Id: Ie92dab7411116d3410195c3fb0a3513c664c0c30
2015-01-12 20:34:19 -08:00

73 lines
1.8 KiB
JavaScript

/*!
* VisualEditor DataModel MWTable class.
*
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
* @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 },
sortable: { sortable: true }
};
// HACK: users of parentNodeTypes should be fixed to check for inherited classes.
ve.dm.TableSectionNode.static.parentNodeTypes.push( 'mwTable' );
ve.dm.TableCaptionNode.static.parentNodeTypes.push( 'mwTable' );
ve.dm.MWTableNode.static.toDataElement = function ( domElements ) {
var attributes = {},
dataElement = { type: this.name },
classAttr = domElements[0].getAttribute( 'class' );
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' ),
classAttr = dataElement.attributes && this.getClassAttrFromAttributes( dataElement.attributes );
if ( classAttr ) {
element.className = classAttr;
}
return [ element ];
};
/* Registration */
ve.dm.modelRegistry.register( ve.dm.MWTableNode );