mediawiki-extensions-Visual.../modules/ve/ce/ve.ce.LeafNode.js
Catrope e148234c29 Render inline annotations in CE
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
2012-11-28 11:21:59 -08:00

59 lines
1.6 KiB
JavaScript

/**
* VisualEditor content editable LeafNode class.
*
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* ContentEditable node that can not have any children.
*
* @class
* @abstract
* @constructor
* @extends {ve.ce.Node}
* @param {String} type Symbolic name of node type
* @param {ve.dm.LeafNode} model Model to observe
* @param {jQuery} [$element] Element to use as a container
*/
ve.ce.LeafNode = function VeCeLeafNode( type, model, $element ) {
// Mixin constructor
ve.LeafNode.call( this );
// Parent constructor
ve.ce.Node.call( this, type, model, $element );
// DOM Changes
if ( model.isWrapped() ) {
this.$.addClass( 've-ce-leafNode' );
}
};
/* Inheritance */
ve.inheritClass( ve.ce.LeafNode, ve.ce.Node );
ve.mixinClass( ve.ce.LeafNode, ve.LeafNode );
/* Methods */
/**
* Gets an sets of annotated HTML fragments for rendering by ve.ce.ContentBranchNode.
*
* An HTML fragment can be:
* - an HTML string
* - a jQuery object
* - an array with an HTML string or jQuery object at index 0 and a ve.AnnotationSet at index 1,
* i.e. ['htmlstring', ve.AnnotationSet] or [$jQueryObj, ve.AnnotationSet]
*
* The default implementation should be fine in most cases. A subclass only needs to override this
* if the annotations aren't necessarily the same across the entire node (like in ve.ce.TextNode).
*
* @method
* @returns {Array} Array of HTML fragments, i.e
* [ string | jQuery | [string|jQuery, ve.AnnotationSet] ]
*/
ve.ce.LeafNode.prototype.getAnnotatedHtml = function () {
return [ [ this.$, this.getModel().getAnnotations() ] ];
};