Create mwTables with wikitable attribute by default

Change-Id: I094b1823248e16dd3b9a0a10ba13104f14798621
This commit is contained in:
Ed Sanders 2014-10-27 14:26:47 +00:00 committed by James D. Forrester
parent cc8f6970a5
commit e0981a327f
4 changed files with 130 additions and 0 deletions

View file

@ -726,6 +726,7 @@ $wgResourceModules += array(
'modules/ve-mw/dm/nodes/ve.dm.MWEntityNode.js',
'modules/ve-mw/dm/nodes/ve.dm.MWExtensionNode.js',
'modules/ve-mw/dm/nodes/ve.dm.MWTableNode.js',
'modules/ve-mw/dm/annotations/ve.dm.MWNowikiAnnotation.js',
@ -734,6 +735,7 @@ $wgResourceModules += array(
// ce
'modules/ve-mw/ce/nodes/ve.ce.MWEntityNode.js',
'modules/ve-mw/ce/nodes/ve.ce.MWExtensionNode.js',
'modules/ve-mw/ce/nodes/ve.ce.MWTableNode.js',
'modules/ve-mw/ce/annotations/ve.ce.MWNowikiAnnotation.js',

View file

@ -0,0 +1,48 @@
/*!
* VisualEditor ContentEditable MWTableNode class.
*
* @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* ContentEditable MW table node.
*
* @class
* @extends ve.ce.TableNode
*
* @constructor
* @param {ve.dm.MWTableNode} model Model to observe
* @param {Object} [config] Configuration options
*/
ve.ce.MWTableNode = function VeCeMWTableNode() {
// Parent constructor
ve.ce.MWTableNode.super.apply( this, arguments );
this.model.connect( this, { attributeChange: 'onAttributeChange' } );
};
/* Inheritance */
OO.inheritClass( ve.ce.MWTableNode, ve.ce.TableNode );
/* Static Properties */
ve.ce.MWTableNode.static.name = 'mwTable';
/* Methods */
ve.ce.MWTableNode.prototype.onAttributeChange = function ( key, from, to ) {
switch ( key ) {
case 'wikitable':
this.$element.toggleClass( 'wikitable', !!to );
break;
case 'sortable':
this.$element.toggleClass( 'sortable', !!to );
break;
}
};
/* Registration */
ve.ce.nodeFactory.register( ve.ce.MWTableNode );

View file

@ -0,0 +1,71 @@
/*!
* VisualEditor DataModel MWTable class.
*
* @copyright 2011-2014 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.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 = this.getClassAttrFromAttributes( dataElement.attributes );
if ( classAttr ) {
element.className = classAttr;
}
return [ element ];
};
/* Registration */
ve.dm.modelRegistry.register( ve.dm.MWTableNode );

View file

@ -67,3 +67,12 @@ ve.ui.commandRegistry.register(
ve.ui.commandRegistry.register(
new ve.ui.Command( 'preformatted', 'format', 'convert', 'mwPreformatted' )
);
ve.ui.commandRegistry.register(
new ve.ui.Command( 'insertTable', 'table', 'create', {
header: true,
rows: 3,
cols: 4,
type: 'mwTable',
attributes: { wikitable: true }
} )
);