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

100% Statements 14/14
100% Branches 12/12
100% Functions 2/2
100% Lines 14/14

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                                1x   8x     8x                       1x       1x   1x             1x 11x 11x 11x   11x 9x     2x         1x  
/*!
 * VisualEditor ContentEditable LanguageAnnotation class.
 *
 * @copyright See AUTHORS.txt
 */
 
/**
 * ContentEditable language annotation.
 *
 * @class
 * @extends ve.ce.TextStyleAnnotation
 * @constructor
 * @param {ve.dm.LanguageAnnotation} model Model to observe
 * @param {ve.ce.ContentBranchNode} [parentNode] Node rendering this annotation
 * @param {Object} [config] Configuration options
 */
ve.ce.LanguageAnnotation = function VeCeLanguageAnnotation() {
	// Parent constructor
	ve.ce.LanguageAnnotation.super.apply( this, arguments );
 
	// DOM changes
	this.$element
		.addClass( 've-ce-languageAnnotation' )
		.addClass( 've-ce-bidi-isolate' )
		.prop( {
			lang: this.model.getAttribute( 'lang' ) || undefined,
			dir: this.model.getAttribute( 'dir' ) || undefined,
			title: this.constructor.static.getDescription( this.model )
		} );
};
 
/* Inheritance */
 
OO.inheritClass( ve.ce.LanguageAnnotation, ve.ce.TextStyleAnnotation );
 
/* Static Properties */
 
ve.ce.LanguageAnnotation.static.name = 'meta/language';
 
ve.ce.LanguageAnnotation.static.tagName = 'span';
 
/* Static Methods */
 
/**
 * @inheritdoc
 */
ve.ce.LanguageAnnotation.static.getDescription = function ( model ) {
	var lang = ( model.getAttribute( 'lang' ) || '' ).toLowerCase(),
		name = ve.init.platform.getLanguageName( lang ),
		dir = ( model.getAttribute( 'dir' ) || '' ).toUpperCase();
 
	if ( !dir || dir === ve.init.platform.getLanguageDirection( lang ).toUpperCase() ) {
		return ve.msg( 'visualeditor-languageannotation-description', name );
	}
 
	return ve.msg( 'visualeditor-languageannotation-description-with-dir', name, dir );
};
 
/* Registration */
 
ve.ce.annotationFactory.register( ve.ce.LanguageAnnotation );