mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-30 00:55:00 +00:00
efafed3231
Change-Id: I8df9226a358a76b661eab6e967ff0d63d361f691
67 lines
1.5 KiB
JavaScript
67 lines
1.5 KiB
JavaScript
/*!
|
|
* VisualEditor ContentEditable TableCellNode class.
|
|
*
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* ContentEditable table cell node.
|
|
*
|
|
* @class
|
|
* @extends ve.ce.BranchNode
|
|
* @constructor
|
|
* @param {ve.dm.TableCellNode} model Model to observe
|
|
* @param {Object} [config] Configuration options
|
|
*/
|
|
ve.ce.TableCellNode = function VeCeTableCellNode( model, config ) {
|
|
// Parent constructor
|
|
ve.ce.BranchNode.call( this, model, config );
|
|
|
|
// Events
|
|
this.model.connect( this, { 'update': 'onUpdate' } );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.ce.TableCellNode, ve.ce.BranchNode );
|
|
|
|
/* Static Properties */
|
|
|
|
ve.ce.TableCellNode.static.name = 'tableCell';
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Get the HTML tag name.
|
|
*
|
|
* Tag name is selected based on the model's style attribute.
|
|
*
|
|
* @returns {string} HTML tag name
|
|
* @throws {Error} If style is invalid
|
|
*/
|
|
ve.ce.TableCellNode.prototype.getTagName = function () {
|
|
var style = this.model.getAttribute( 'style' ),
|
|
types = { 'data': 'td', 'header': 'th' };
|
|
|
|
if ( !( style in types ) ) {
|
|
throw new Error( 'Invalid style' );
|
|
}
|
|
return types[style];
|
|
};
|
|
|
|
/**
|
|
* Handle model update events.
|
|
*
|
|
* If the style changed since last update the DOM wrapper will be replaced with an appropriate one.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ce.TableCellNode.prototype.onUpdate = function () {
|
|
this.updateTagName();
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.ce.nodeFactory.register( ve.ce.TableCellNode );
|