mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-01 17:36:35 +00:00
370070dfa2
* Fixed constructor of ve.ce.BranchNode which was calling the wrong method to perform an onSplice and with the wrong arguments * Removed/renamed events emitted from ve.ce.BranchNode.onSplice * Reintroduced .$ to all ce nodes * Ported over functionality for DOM node type variance used in headings, lists and list items * Moved the old ve.ce.Content guts to ve.ce.TextNode * Added getOffsetFromNode and getDataFromNode to ve.dm.DocumentFragment * Added setDocument and getDocument to dm nodes Change-Id: I185423ba2f1a858dde562cb2f5bc3852aec930db
52 lines
1 KiB
JavaScript
52 lines
1 KiB
JavaScript
/**
|
|
* ContentEditable node for a heading.
|
|
*
|
|
* @class
|
|
* @constructor
|
|
* @extends {ve.ce.BranchNode}
|
|
* @param model {ve.dm.HeadingNode} Model to observe
|
|
*/
|
|
ve.ce.HeadingNode = function( model ) {
|
|
// Inheritance
|
|
ve.ce.BranchNode.call( this, model, ve.ce.HeadingNode.getDomElement( model ) );
|
|
};
|
|
|
|
/* Static Members */
|
|
|
|
/**
|
|
* @see ve.ce.NodeFactory
|
|
*/
|
|
ve.ce.HeadingNode.rules = {
|
|
'canHaveChildren': true,
|
|
'canHaveGrandchildren': false,
|
|
'canBeSplit': true
|
|
};
|
|
|
|
ve.ce.HeadingNode.domNodeTypes = {
|
|
'1': 'h1',
|
|
'2': 'h2',
|
|
'3': 'h3',
|
|
'4': 'h4',
|
|
'5': 'h5',
|
|
'6': 'h6'
|
|
};
|
|
|
|
/* Static Methods */
|
|
|
|
ve.ce.HeadingNode.getDomElement = function( model ) {
|
|
var level = model.getElementAttribute( 'level' ),
|
|
type = ve.ce.HeadingNode.domNodeTypes[level];
|
|
if ( type === undefined ) {
|
|
throw 'Invalid level attribute in heading node model: ' + level;
|
|
}
|
|
return $( '<' + type + '></' + type + '>' );
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.ce.factory.register( 'heading', ve.ce.HeadingNode );
|
|
|
|
/* Inheritance */
|
|
|
|
ve.extendClass( ve.ce.HeadingNode, ve.ce.BranchNode );
|