All files / src/ce/annotations ve.ce.NailedAnnotation.js

95.45% Statements 21/22
50% Branches 4/8
100% Functions 5/5
95.45% Lines 21/22

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                          1x   117x   117x         1x       1x                   1x 468x         468x               468x 468x               1x 117x           1x 117x   117x 117x 117x           1x   117x 117x 117x    
/*!
 * VisualEditor ContentEditable NailedAnnotation class.
 *
 * @copyright See AUTHORS.txt
 */
 
/**
 * ContentEditable nailed annotation.
 *
 * @class
 * @abstract
 * @constructor
 */
ve.ce.NailedAnnotation = function VeCeNailedAnnotation() {
	// Initialization
	this.contentFragment = document.createDocumentFragment();
 
	this.$element.addClass( 've-ce-nailedAnnotation' );
};
 
/* Inheritance */
 
OO.initClass( ve.ce.NailedAnnotation );
 
/* Static Properties */
 
ve.ce.NailedAnnotation.static.canBeActive = true;
 
/* Static Methods */
 
/**
 * Create a nail (a zero-width image) to add extra cursor positions around annotations
 *
 * @param {string} type Nail type, one of 'pre-open', 'pre-close', 'post-open' and 'post-close'
 * @return {HTMLElement} The new nail
 */
ve.ce.NailedAnnotation.static.makeNail = function ( type ) {
	var nail = document.createElement( 'img' );
	// Support: Firefox
	// Firefox <=37 misbehaves if we don't set an src: https://bugzilla.mozilla.org/show_bug.cgi?id=989012
	// Firefox misbehaves if we don't set an src and there is no sizing at node creation time: https://bugzilla.mozilla.org/show_bug.cgi?id=1267906
	// Setting an src in Chrome is slow, so only set it in affected versions of Firefox
	Iif ( $.client.profile().layout === 'gecko' || ve.inputDebug ) {
		nail.src = ve.inputDebug ? ve.ce.nailImgDataUri : ve.ce.minImgDataUri;
	}
	// The following classes are used here:
	// * ve-ce-nail-pre-open
	// * ve-ce-nail-pre-close
	// * ve-ce-nail-post-open
	// * ve-ce-nail-post-close
	nail.className = 've-ce-nail ve-ce-nail-' + type + ( ve.inputDebug ? ' ve-ce-nail-debug' : '' );
	return nail;
};
 
/* Methods */
 
/**
 * @inheritdoc ve.ce.Annotation
 */
ve.ce.NailedAnnotation.prototype.getContentContainer = function () {
	return this.contentFragment;
};
 
/**
 * @inheritdoc ve.ce.Annotation
 */
ve.ce.NailedAnnotation.prototype.attachContents = function () {
	var element = this.$element[ 0 ];
	// Insert post-open nail, annotation contents, and pre-close nail into the element
	element.appendChild( this.constructor.static.makeNail( 'post-open' ) );
	element.appendChild( this.contentFragment );
	element.appendChild( this.constructor.static.makeNail( 'pre-close' ) );
};
 
/**
 * @inheritdoc ve.ce.Annotation
 */
ve.ce.NailedAnnotation.prototype.appendTo = function ( node ) {
	// Insert pre-open nail, element, and post-close nail into a parent node
	node.appendChild( this.constructor.static.makeNail( 'pre-open' ) );
	node.appendChild( this.$element[ 0 ] );
	node.appendChild( this.constructor.static.makeNail( 'post-close' ) );
};