mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 14:56:20 +00:00
e148234c29
Moved annotation rendering from ce.Textnode into the new ce.ContentBranchNode class. This allows us to render annotations that span across multiple nodes. * Add ce.ContentBranchNode, inheriting ce.BranchNode * Make ce.{Paragraph,Heading,Preformatted}Node inherit ce.ContentBranchNode * Made ce.ContentBranchNode render its child nodes with anntations, using .getAnnotatedHtml() on the child nodes * Put a default implementation for .getAnnotatedHtml() in ce.LeafNode * Override this in ce.TextNode to do escaping and whitespace handling * Removed rendering code from ce.TextNode (this.$ is now unused there) * Removed ce.TextNode.onUpdate() and ce.BranchNode.clean(), now unneeded * Have ce.BranchNode propagate update events from children, so ce.ContentBranchNode can rerender when its children change * Update tests, add test case for escaping of &<>'" Change-Id: I4600e984b287c6ff9267f4281d2f09bab9e1ad95
74 lines
1.4 KiB
JavaScript
74 lines
1.4 KiB
JavaScript
/**
|
|
* VisualEditor content editable HeadingNode class.
|
|
*
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
* ContentEditable node for a heading.
|
|
*
|
|
* @class
|
|
* @constructor
|
|
* @extends {ve.ce.BranchNode}
|
|
* @param {ve.dm.HeadingNode} model Model to observe
|
|
*/
|
|
ve.ce.HeadingNode = function VeCeHeadingNode( model ) {
|
|
// Parent constructor
|
|
ve.ce.ContentBranchNode.call(
|
|
this, 'heading', model, ve.ce.BranchNode.getDomWrapper( model, 'level' )
|
|
);
|
|
|
|
// Events
|
|
this.model.addListenerMethod( this, 'update', 'onUpdate' );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
ve.inheritClass( ve.ce.HeadingNode, ve.ce.ContentBranchNode );
|
|
|
|
/* Static Members */
|
|
|
|
/**
|
|
* Node rules.
|
|
*
|
|
* @see ve.ce.NodeFactory
|
|
* @static
|
|
* @member
|
|
*/
|
|
ve.ce.HeadingNode.rules = {
|
|
'canBeSplit': true
|
|
};
|
|
|
|
/**
|
|
* Mapping of heading level values and DOM wrapper element types.
|
|
*
|
|
* @static
|
|
* @member
|
|
*/
|
|
ve.ce.HeadingNode.domWrapperElementTypes = {
|
|
'1': 'h1',
|
|
'2': 'h2',
|
|
'3': 'h3',
|
|
'4': 'h4',
|
|
'5': 'h5',
|
|
'6': 'h6'
|
|
};
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Responds to model update events.
|
|
*
|
|
* If the level changed since last update the DOM wrapper will be replaced with an appropriate one.
|
|
*
|
|
* @method
|
|
*/
|
|
ve.ce.HeadingNode.prototype.onUpdate = function () {
|
|
this.updateDomWrapper( 'level' );
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.ce.nodeFactory.register( 'heading', ve.ce.HeadingNode );
|