mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-25 12:33:19 +00:00
9337e6ecbd
We don't support editing <div>s right now (as they're BranchNodes) nor <span>s (as they're annotations), but most of those are inside templates and so not editable in VE anyway. Bug: T157989 Change-Id: I647b2a544fd16952696d0de8d07cb72189b27ecb
83 lines
2.2 KiB
JavaScript
83 lines
2.2 KiB
JavaScript
/*!
|
|
* VisualEditor DataModel MWTable class.
|
|
*
|
|
* @copyright 2011-2017 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 },
|
|
'mw-collapsible': { collapsible: true },
|
|
'mw-collapsed': { collapsed: 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.TableRowNode.static.childNodeTypes.push( 'mwTransclusionTableCell' );
|
|
|
|
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 ];
|
|
};
|
|
|
|
ve.dm.MWTableNode.static.sanitize = function ( dataElement ) {
|
|
// Mixin method
|
|
ve.dm.ClassAttributeNode.static.sanitize.call( this, dataElement );
|
|
|
|
ve.setProp( dataElement, 'attributes', 'wikitable', true );
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.MWTableNode );
|