Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ce/annotations/ve.ce.LanguageAnnotation.js

raw symbols SCIP
1 /*!
2 * VisualEditor ContentEditable LanguageAnnotation class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * ContentEditable language annotation.
9 *
10 * @class
11 * @extends ve.ce.TextStyleAnnotation
12 * @constructor
13 * @param {ve.dm.LanguageAnnotation} model Model to observe
14 * @param {ve.ce.ContentBranchNode} [parentNode] Node rendering this annotation
15 * @param {Object} [config] Configuration options
16 */
17 ve.ce.LanguageAnnotation = function VeCeLanguageAnnotation() {
18 // Parent constructor
19 ve.ce.LanguageAnnotation.super.apply( this, arguments );
20
21 // DOM changes
22 this.$element
23 .addClass( 've-ce-languageAnnotation' )
24 .addClass( 've-ce-bidi-isolate' )
25 .prop( {
26 lang: this.model.getAttribute( 'lang' ) || undefined,
27 dir: this.model.getAttribute( 'dir' ) || undefined,
28 title: this.constructor.static.getDescription( this.model )
29 } );
30 };
31
32 /* Inheritance */
33
34 OO.inheritClass( ve.ce.LanguageAnnotation, ve.ce.TextStyleAnnotation );
35
36 /* Static Properties */
37
38 ve.ce.LanguageAnnotation.static.name = 'meta/language';
39
40 ve.ce.LanguageAnnotation.static.tagName = 'span';
41
42 /* Static Methods */
43
44 /**
45 * @inheritdoc
46 */
47 ve.ce.LanguageAnnotation.static.getDescription = function ( model ) {
48 const lang = ( model.getAttribute( 'lang' ) || '' ).toLowerCase(),
49 name = ve.init.platform.getLanguageName( lang ),
50 dir = ( model.getAttribute( 'dir' ) || '' ).toUpperCase();
51
52 if ( !dir || dir === ve.init.platform.getLanguageDirection( lang ).toUpperCase() ) {
53 return ve.msg( 'visualeditor-languageannotation-description', name );
54 }
55
56 return ve.msg( 'visualeditor-languageannotation-description-with-dir', name, dir );
57 };
58
59 /* Registration */
60
61 ve.ce.annotationFactory.register( ve.ce.LanguageAnnotation );