All files / src/ui/inspectors ve.ui.LanguageInspector.js

100% Statements 21/21
50% Branches 2/4
100% Functions 6/6
100% Lines 21/21

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                              1x   1x         1x       1x   1x     1x             1x 2x 2x 2x                             1x 2x                       1x   1x     1x       1x             1x           1x 2x   2x                 1x  
/*!
 * VisualEditor UserInterface LanguageInspector class.
 *
 * @copyright See AUTHORS.txt
 */
 
/**
 * Inspector for specifying the language of content.
 *
 * @class
 * @extends ve.ui.AnnotationInspector
 *
 * @constructor
 * @param {Object} [config] Configuration options
 */
ve.ui.LanguageInspector = function VeUiLanguageInspector() {
	// Parent constructor
	ve.ui.LanguageInspector.super.apply( this, arguments );
};
 
/* Inheritance */
 
OO.inheritClass( ve.ui.LanguageInspector, ve.ui.AnnotationInspector );
 
/* Static properties */
 
ve.ui.LanguageInspector.static.name = 'language';
 
ve.ui.LanguageInspector.static.title =
	OO.ui.deferMsg( 'visualeditor-languageinspector-title' );
 
ve.ui.LanguageInspector.static.modelClasses = [ ve.dm.LanguageAnnotation ];
 
/* Methods */
 
/**
 * @inheritdoc
 */
ve.ui.LanguageInspector.prototype.getAnnotation = function () {
	var lang = this.languageInput.getLang(),
		dir = this.languageInput.getDir();
	return ( lang || dir ?
		new ve.dm.LanguageAnnotation( {
			type: 'meta/language',
			attributes: {
				lang: lang,
				dir: dir
			}
		} ) :
		null
	);
};
 
/**
 * @inheritdoc
 */
ve.ui.LanguageInspector.prototype.getAnnotationFromFragment = function ( fragment ) {
	return new ve.dm.LanguageAnnotation( {
		type: 'meta/language',
		attributes: {
			lang: fragment.getDocument().getLang(),
			dir: fragment.getDocument().getDir()
		}
	} );
};
 
/**
 * @inheritdoc
 */
ve.ui.LanguageInspector.prototype.initialize = function () {
	// Parent method
	ve.ui.LanguageInspector.super.prototype.initialize.call( this );
 
	// Properties
	this.languageInput = new ve.ui.LanguageInputWidget( {
		dialogManager: this.manager.getSurface().getDialogs()
	} );
 
	var languageField = new OO.ui.FieldLayout( this.languageInput, {
		align: 'left',
		classes: [ 've-ui-languageInspector-languageField' ],
		label: ve.msg( 'visualeditor-languageinspector-widget-label-language' )
	} );
 
	// Initialization
	this.form.$element.append( languageField.$element );
};
 
/**
 * @inheritdoc
 */
ve.ui.LanguageInspector.prototype.getSetupProcess = function ( data ) {
	return ve.ui.LanguageInspector.super.prototype.getSetupProcess.call( this, data )
		.next( function () {
			this.languageInput.setLangAndDir(
				this.initialAnnotation.getAttribute( 'lang' ),
				this.initialAnnotation.getAttribute( 'dir' )
			).setReadOnly( this.isReadOnly() );
		}, this );
};
 
/* Registration */
 
ve.ui.windowFactory.register( ve.ui.LanguageInspector );