all files / src/ce/ ve.ce.LeafNode.js

100% Statements 12/12
100% Branches 2/2
100% Functions 3/3
100% Lines 12/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72                                        1486×     1486×                               1528×   1528× 171×                                         78×    
/*!
 * VisualEditor ContentEditable LeafNode class.
 *
 * @copyright 2011-2019 VisualEditor Team and others; see http://ve.mit-license.org
 */
 
/**
 * ContentEditable leaf node.
 *
 * Leaf nodes can not have any children.
 *
 * @abstract
 * @extends ve.ce.Node
 * @mixins ve.LeafNode
 *
 * @constructor
 * @param {ve.dm.LeafNode} model
 * @param {Object} [config]
 */
ve.ce.LeafNode = function VeCeLeafNode() {
	// Mixin constructor
	ve.LeafNode.call( this );
 
	// Parent constructor
	ve.ce.LeafNode.super.apply( this, arguments );
};
 
/* Inheritance */
 
OO.inheritClass( ve.ce.LeafNode, ve.ce.Node );
 
OO.mixinClass( ve.ce.LeafNode, ve.LeafNode );
 
/* Static Properties */
 
ve.ce.LeafNode.static.tagName = 'span';
 
/* Methods */
 
/**
 * @inheritdoc
 */
ve.ce.LeafNode.prototype.initialize = function () {
	// Parent method
	ve.ce.LeafNode.super.prototype.initialize.call( this );
 
	if ( this.model.isWrapped() ) {
		this.$element.addClass( 've-ce-leafNode' );
	}
};
 
/**
 * Get annotated HTML fragments.
 *
 * @see ve.ce.ContentBranchNode
 *
 * An HTML fragment can be:
 * - a plain text string
 * - a jQuery object
 * - an array with a plain text string or jQuery object at index 0 and a ve.dm.AnnotationSet at index 1,
 *   i.e. ['textstring', ve.dm.AnnotationSet] or [$jQueryObj, ve.dm.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).
 *
 * @return {Array} Array of HTML fragments, i.e.
 *  [ string | jQuery | [string|jQuery, ve.dm.AnnotationSet] ]
 */
ve.ce.LeafNode.prototype.getAnnotatedHtml = function () {
	return [ [ this.$element, this.getModel().getAnnotations() ] ];
};