2012-07-19 00:11:26 +00:00
|
|
|
/**
|
|
|
|
* VisualEditor data model TableSelectionNode 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-06-08 05:00:50 +00:00
|
|
|
/**
|
|
|
|
* DataModel node for a table section.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @constructor
|
|
|
|
* @extends {ve.dm.BranchNode}
|
|
|
|
* @param {ve.dm.BranchNode[]} [children] Child nodes to attach
|
|
|
|
* @param {Object} [attributes] Reference to map of attribute key/value pairs
|
2012-08-16 17:53:33 +00:00
|
|
|
* @param {Object} [internal] Reference to internal data object
|
2012-06-08 05:00:50 +00:00
|
|
|
*/
|
2012-08-16 17:53:33 +00:00
|
|
|
ve.dm.TableSectionNode = function ( children, attributes, internal ) {
|
2012-06-08 05:00:50 +00:00
|
|
|
// Inheritance
|
2012-08-16 17:53:33 +00:00
|
|
|
ve.dm.BranchNode.call( this, 'tableSection', children, attributes, internal );
|
2012-06-08 05:00:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Static Members */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Node rules.
|
|
|
|
*
|
|
|
|
* @see ve.dm.NodeFactory
|
|
|
|
* @static
|
|
|
|
* @member
|
|
|
|
*/
|
|
|
|
ve.dm.TableSectionNode.rules = {
|
|
|
|
'isWrapped': true,
|
|
|
|
'isContent': false,
|
|
|
|
'canContainContent': false,
|
|
|
|
'childNodeTypes': ['tableRow'],
|
|
|
|
'parentNodeTypes': ['table']
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Node converters.
|
|
|
|
*
|
|
|
|
* @see {ve.dm.Converter}
|
|
|
|
* @static
|
|
|
|
* @member
|
|
|
|
*/
|
|
|
|
ve.dm.TableSectionNode.converters = {
|
|
|
|
'domElementTypes': ['thead', 'tbody', 'tfoot'],
|
2012-08-07 01:50:44 +00:00
|
|
|
'toDomElement': function ( type, element ) {
|
2012-06-08 05:00:50 +00:00
|
|
|
return element.attributes && ( {
|
|
|
|
'header': document.createElement( 'thead' ),
|
|
|
|
'body': document.createElement( 'tbody' ),
|
|
|
|
'footer': document.createElement( 'tfoot' )
|
2012-07-19 03:40:49 +00:00
|
|
|
} )[element.attributes.style];
|
2012-06-08 05:00:50 +00:00
|
|
|
},
|
2012-08-07 01:50:44 +00:00
|
|
|
'toDataElement': function ( tag, element ) {
|
2012-06-08 05:00:50 +00:00
|
|
|
return ( {
|
|
|
|
'thead': { 'type': 'tableSection', 'attributes': { 'style': 'header' } },
|
|
|
|
'tbody': { 'type': 'tableSection', 'attributes': { 'style': 'body' } },
|
|
|
|
'tfoot': { 'type': 'tableSection', 'attributes': { 'style': 'footer' } }
|
|
|
|
} )[tag];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.dm.nodeFactory.register( 'tableSection', ve.dm.TableSectionNode );
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.extendClass( ve.dm.TableSectionNode, ve.dm.BranchNode );
|