Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ui/inspectors/ve.ui.LanguageInspector.js

raw symbols SCIP
1 /*!
2 * VisualEditor UserInterface LanguageInspector class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * Inspector for specifying the language of content.
9 *
10 * @class
11 * @extends ve.ui.AnnotationInspector
12 *
13 * @constructor
14 * @param {Object} [config] Configuration options
15 */
16 ve.ui.LanguageInspector = function VeUiLanguageInspector() {
17 // Parent constructor
18 ve.ui.LanguageInspector.super.apply( this, arguments );
19 };
20
21 /* Inheritance */
22
23 OO.inheritClass( ve.ui.LanguageInspector, ve.ui.AnnotationInspector );
24
25 /* Static properties */
26
27 ve.ui.LanguageInspector.static.name = 'language';
28
29 ve.ui.LanguageInspector.static.title =
30 OO.ui.deferMsg( 'visualeditor-languageinspector-title' );
31
32 ve.ui.LanguageInspector.static.modelClasses = [ ve.dm.LanguageAnnotation ];
33
34 /* Methods */
35
36 /**
37 * @inheritdoc
38 */
39 ve.ui.LanguageInspector.prototype.getAnnotation = function () {
40 const lang = this.languageInput.getLang(),
41 dir = this.languageInput.getDir();
42 return ( lang || dir ?
43 new ve.dm.LanguageAnnotation( {
44 type: 'meta/language',
45 attributes: {
46 lang: lang,
47 dir: dir
48 }
49 } ) :
50 null
51 );
52 };
53
54 /**
55 * @inheritdoc
56 */
57 ve.ui.LanguageInspector.prototype.getAnnotationFromFragment = function ( fragment ) {
58 return new ve.dm.LanguageAnnotation( {
59 type: 'meta/language',
60 attributes: {
61 lang: fragment.getDocument().getLang(),
62 dir: fragment.getDocument().getDir()
63 }
64 } );
65 };
66
67 /**
68 * @inheritdoc
69 */
70 ve.ui.LanguageInspector.prototype.initialize = function () {
71 // Parent method
72 ve.ui.LanguageInspector.super.prototype.initialize.call( this );
73
74 // Properties
75 this.languageInput = new ve.ui.LanguageInputWidget( {
76 dialogManager: this.manager.getSurface().getDialogs()
77 } );
78
79 const languageField = new OO.ui.FieldLayout( this.languageInput, {
80 align: 'left',
81 classes: [ 've-ui-languageInspector-languageField' ],
82 label: ve.msg( 'visualeditor-languageinspector-widget-label-language' )
83 } );
84
85 // Initialization
86 this.form.$element.append( languageField.$element );
87 };
88
89 /**
90 * @inheritdoc
91 */
92 ve.ui.LanguageInspector.prototype.getSetupProcess = function ( data ) {
93 return ve.ui.LanguageInspector.super.prototype.getSetupProcess.call( this, data )
94 .next( () => {
95 this.languageInput.setLangAndDir(
96 this.initialAnnotation.getAttribute( 'lang' ),
97 this.initialAnnotation.getAttribute( 'dir' )
98 ).setReadOnly( this.isReadOnly() );
99 } );
100 };
101
102 /* Registration */
103
104 ve.ui.windowFactory.register( ve.ui.LanguageInspector );