2012-07-19 00:11:26 +00:00
|
|
|
/**
|
|
|
|
* VisualEditor data model TableCellNode class.
|
2012-07-19 21:25:16 +00:00
|
|
|
*
|
2012-07-19 00:11:26 +00:00
|
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
/**
|
2012-06-20 01:20:28 +00:00
|
|
|
* DataModel node for a table cell.
|
|
|
|
*
|
2012-02-06 23:50:56 +00:00
|
|
|
* @class
|
|
|
|
* @constructor
|
|
|
|
* @extends {ve.dm.BranchNode}
|
2012-06-20 01:20:28 +00:00
|
|
|
* @param {ve.dm.BranchNode[]} [children] Child nodes to attach
|
|
|
|
* @param {Object} [attributes] Reference to map of attribute key/value pairs
|
2012-02-06 23:50:56 +00:00
|
|
|
*/
|
2012-06-20 01:20:28 +00:00
|
|
|
ve.dm.TableCellNode = function( children, attributes ) {
|
2012-02-06 23:50:56 +00:00
|
|
|
// Inheritance
|
2012-06-20 01:20:28 +00:00
|
|
|
ve.dm.BranchNode.call( this, 'tableCell', children, attributes );
|
2012-02-06 23:50:56 +00:00
|
|
|
};
|
|
|
|
|
2012-06-20 01:20:28 +00:00
|
|
|
/* Static Members */
|
2012-02-06 23:50:56 +00:00
|
|
|
|
|
|
|
/**
|
2012-06-20 01:20:28 +00:00
|
|
|
* Node rules.
|
|
|
|
*
|
|
|
|
* @see ve.dm.NodeFactory
|
|
|
|
* @static
|
|
|
|
* @member
|
2012-02-06 23:50:56 +00:00
|
|
|
*/
|
2012-06-20 01:20:28 +00:00
|
|
|
ve.dm.TableCellNode.rules = {
|
|
|
|
'isWrapped': true,
|
|
|
|
'isContent': false,
|
|
|
|
'canContainContent': false,
|
|
|
|
'childNodeTypes': null,
|
|
|
|
'parentNodeTypes': ['tableRow']
|
2012-02-06 23:50:56 +00:00
|
|
|
};
|
|
|
|
|
2012-06-20 01:20:28 +00:00
|
|
|
/**
|
|
|
|
* Node converters.
|
|
|
|
*
|
|
|
|
* @see {ve.dm.Converter}
|
|
|
|
* @static
|
|
|
|
* @member
|
|
|
|
*/
|
|
|
|
ve.dm.TableCellNode.converters = {
|
|
|
|
'domElementTypes': ['td', 'th'],
|
|
|
|
'toDomElement': function( type, element ) {
|
|
|
|
return element.attributes && ( {
|
|
|
|
'data': document.createElement( 'td' ),
|
|
|
|
'header': document.createElement( 'th' )
|
2012-07-19 03:40:49 +00:00
|
|
|
} )[element.attributes.style];
|
2012-06-20 01:20:28 +00:00
|
|
|
},
|
|
|
|
'toDataElement': function( tag, element ) {
|
|
|
|
return ( {
|
|
|
|
'td': { 'type': 'tableCell', 'attributes': { 'style': 'data' } },
|
|
|
|
'th': { 'type': 'tableCell', 'attributes': { 'style': 'header' } }
|
|
|
|
} )[tag];
|
|
|
|
}
|
|
|
|
};
|
2012-02-06 23:50:56 +00:00
|
|
|
|
2012-06-20 01:20:28 +00:00
|
|
|
/* Registration */
|
2012-02-06 23:50:56 +00:00
|
|
|
|
2012-06-20 01:20:28 +00:00
|
|
|
ve.dm.nodeFactory.register( 'tableCell', ve.dm.TableCellNode );
|
2012-02-06 23:50:56 +00:00
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.extendClass( ve.dm.TableCellNode, ve.dm.BranchNode );
|