All files / src/ce ve.ce.Annotation.js

80% Statements 20/25
75% Branches 3/4
60% Functions 6/10
80% Lines 20/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137                                            1x   529x     529x   529x               1x       1x         1x                       1x                     1x             1x 117x               1x                 1x 412x               1x                     1x 412x               1x 99x           1x            
/*!
 * VisualEditor ContentEditable Annotation class.
 *
 * @copyright See AUTHORS.txt
 */
 
/**
 * Generic ContentEditable annotation.
 *
 * This is an abstract class, annotations should extend this and call this constructor from their
 * constructor. You should not instantiate this class directly.
 *
 * Subclasses of ve.dm.Annotation should have a corresponding subclass here that controls rendering.
 *
 * @abstract
 * @extends ve.ce.View
 *
 * @constructor
 * @param {ve.dm.Annotation} model Model to observe
 * @param {ve.ce.ContentBranchNode} [parentNode] Node rendering this annotation
 * @param {Object} [config] Configuration options
 */
ve.ce.Annotation = function VeCeAnnotation( model, parentNode, config ) {
	// Parent constructor
	ve.ce.Annotation.super.call( this, model, config );
 
	// Properties
	this.parentNode = parentNode || null;
 
	this.$element
		// Make data available before setup
		.data( 'view', this )
		.addClass( 've-ce-annotation' );
};
 
/* Inheritance */
 
OO.inheritClass( ve.ce.Annotation, ve.ce.View );
 
/* Static Properties */
 
ve.ce.Annotation.static.tagName = 'span';
 
/**
 * Annotations which can be active get a ve-ce-annotation-active class when focused.
 */
ve.ce.Annotation.static.canBeActive = false;
 
/* Static Methods */
 
/**
 * Get a plain text description.
 *
 * @static
 * @inheritable
 * @param {ve.dm.Annotation} annotation Annotation model
 * @return {string} Description of annotation
 */
ve.ce.Annotation.static.getDescription = function () {
	return '';
};
 
/* Methods */
 
/**
 * Get the content branch node this annotation is rendered in, if any.
 *
 * @return {ve.ce.ContentBranchNode|null} Content branch node or null if none
 */
ve.ce.Annotation.prototype.getParentNode = function () {
	return this.parentNode;
};
 
/**
 * @inheritdoc
 */
ve.ce.Annotation.prototype.getModelHtmlDocument = function () {
	return this.parentNode && this.parentNode.getModelHtmlDocument();
};
 
/**
 * Append a child node to the annotation
 *
 * @param {Node} childNode Child node to append
 */
ve.ce.Annotation.prototype.appendChild = function ( childNode ) {
	this.$element[ 0 ].appendChild( childNode );
};
 
/**
 * Get the container into which annotation contents should be appended
 *
 * @return {HTMLElement} Content container
 */
ve.ce.Annotation.prototype.getContentContainer = function () {
	return this.$element[ 0 ];
};
 
/**
 * Attach completed contents to the annotation as descendant nodes, if not already attached
 *
 * No further contents should be appended into the content container after calling this
 */
ve.ce.Annotation.prototype.attachContents = function () {
	// Do nothing; already attached
};
 
/**
 * Append the completed annotation to a parent node
 *
 * #attachContents should have been called first
 *
 * @param {Node} node Parent node
 */
ve.ce.Annotation.prototype.appendTo = function ( node ) {
	node.appendChild( this.$element[ 0 ] );
};
 
/**
 * Check if the annotation can be active
 *
 * @return {boolean}
 */
ve.ce.Annotation.prototype.canBeActive = function () {
	return this.constructor.static.canBeActive;
};
 
/**
 * Release all memory
 */
ve.ce.Annotation.prototype.destroy = function () {
	this.parentNode = null;
 
	// Parent method
	ve.ce.Annotation.super.prototype.destroy.call( this );
};