jenkins-bot has submitted this change and it was merged.
Change subject: Create mwTables with wikitable attribute by default
......................................................................
Create mwTables with wikitable attribute by default
Change-Id: I094b1823248e16dd3b9a0a10ba13104f14798621
---
M VisualEditor.php
A modules/ve-mw/ce/nodes/ve.ce.MWTableNode.js
A modules/ve-mw/dm/nodes/ve.dm.MWTableNode.js
M modules/ve-mw/ui/ve.ui.MWCommandRegistry.js
4 files changed, 130 insertions(+), 0 deletions(-)
Approvals:
Jforrester: Looks good to me, approved
jenkins-bot: Verified
diff --git a/VisualEditor.php b/VisualEditor.php
index 40aa3da..7f8a3ab 100644
--- a/VisualEditor.php
+++ b/VisualEditor.php
@@ -726,6 +726,7 @@
'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 @@
// 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',
diff --git a/modules/ve-mw/ce/nodes/ve.ce.MWTableNode.js
b/modules/ve-mw/ce/nodes/ve.ce.MWTableNode.js
new file mode 100644
index 0000000..f76656b
--- /dev/null
+++ b/modules/ve-mw/ce/nodes/ve.ce.MWTableNode.js
@@ -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 );
diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWTableNode.js
b/modules/ve-mw/dm/nodes/ve.dm.MWTableNode.js
new file mode 100644
index 0000000..b1ca067
--- /dev/null
+++ b/modules/ve-mw/dm/nodes/ve.dm.MWTableNode.js
@@ -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 );
diff --git a/modules/ve-mw/ui/ve.ui.MWCommandRegistry.js
b/modules/ve-mw/ui/ve.ui.MWCommandRegistry.js
index 2fc4e2f..f9ca8b5 100644
--- a/modules/ve-mw/ui/ve.ui.MWCommandRegistry.js
+++ b/modules/ve-mw/ui/ve.ui.MWCommandRegistry.js
@@ -67,3 +67,12 @@
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 }
+ } )
+);
--
To view, visit https://gerrit.wikimedia.org/r/168961
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I094b1823248e16dd3b9a0a10ba13104f14798621
Gerrit-PatchSet: 9
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits