Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ce/ve.ce.AnnotationFactory.js

raw symbols SCIP
1 /*!
2 * VisualEditor ContentEditable AnnotationFactory class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * ContentEditable annotation factory.
9 *
10 * @class
11 * @extends OO.Factory
12 * @constructor
13 */
14 ve.ce.AnnotationFactory = function VeCeAnnotationFactory() {
15 // Parent constructor
16 OO.Factory.call( this );
17 };
18
19 /* Inheritance */
20
21 OO.inheritClass( ve.ce.AnnotationFactory, OO.Factory );
22
23 /* Methods */
24
25 /**
26 * Get a plain text description of an annotation model.
27 *
28 * @param {ve.dm.Annotation} annotation Annotation to describe
29 * @return {string} Description of the annotation
30 * @throws {Error} Unknown annotation type
31 */
32 ve.ce.AnnotationFactory.prototype.getDescription = function ( annotation ) {
33 const type = annotation.constructor.static.name;
34 if ( Object.prototype.hasOwnProperty.call( this.registry, type ) ) {
35 return this.registry[ type ].static.getDescription( annotation );
36 }
37 throw new Error( 'Unknown annotation type: ' + type );
38 };
39
40 /**
41 * Check if an annotation can be active
42 *
43 * @param {string} type Annotation type
44 * @return {boolean}
45 */
46 ve.ce.AnnotationFactory.prototype.canAnnotationBeActive = function ( type ) {
47 if ( Object.prototype.hasOwnProperty.call( this.registry, type ) ) {
48 return this.registry[ type ].static.canBeActive;
49 }
50 throw new Error( 'Unknown annotation type: ' + type );
51 };
52
53 /* Initialization */
54
55 // TODO: Move instantiation to a different file
56 ve.ce.annotationFactory = new ve.ce.AnnotationFactory();