Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/ce/annotations/ve.ce.MWInternalLinkAnnotation.js

raw symbols SCIP
1 /*!
2 * VisualEditor ContentEditable MWInternalLinkAnnotation class.
3 *
4 * @copyright See AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7
8 /**
9 * ContentEditable MediaWiki internal link annotation.
10 *
11 * @class
12 * @extends ve.ce.LinkAnnotation
13 * @constructor
14 * @param {ve.dm.MWInternalLinkAnnotation} model Model to observe
15 * @param {ve.ce.ContentBranchNode} [parentNode] Node rendering this annotation
16 * @param {Object} [config] Configuration options
17 */
18 ve.ce.MWInternalLinkAnnotation = function VeCeMWInternalLinkAnnotation() {
19 // Parent constructor
20 ve.ce.MWInternalLinkAnnotation.super.apply( this, arguments );
21
22 // DOM changes
23 this.$anchor.addClass( 've-ce-mwInternalLinkAnnotation' );
24
25 this.updateClasses();
26 };
27
28 /* Inheritance */
29
30 OO.inheritClass( ve.ce.MWInternalLinkAnnotation, ve.ce.LinkAnnotation );
31
32 /* Static Properties */
33
34 ve.ce.MWInternalLinkAnnotation.static.name = 'link/mwInternal';
35
36 /* Static Methods */
37
38 /**
39 * @inheritdoc
40 */
41 ve.ce.MWInternalLinkAnnotation.static.getDescription = function ( model ) {
42 return model.getAttribute( 'title' );
43 };
44
45 /* Methods */
46
47 /**
48 * Update CSS classes form model state
49 */
50 ve.ce.MWInternalLinkAnnotation.prototype.updateClasses = function () {
51 const model = this.getModel();
52
53 if ( model.element.originalDomElementsHash ) {
54 // If the link came from Parsoid, use the 'new' class to
55 // determine if this is a 'missing' link.
56 const entry = {};
57 entry[ model.getAttribute( 'lookupTitle' ) ] = {
58 // eslint-disable-next-line no-jquery/no-class-state
59 missing: this.$anchor.hasClass( 'new' )
60 };
61 ve.init.platform.linkCache.setMissing( entry );
62 } else {
63 // otherwise do an API/cache lookup
64 ve.init.platform.linkCache.styleElement(
65 model.getAttribute( 'lookupTitle' ),
66 this.$anchor,
67 !!model.getFragment()
68 );
69 }
70 };
71
72 /* Registration */
73
74 ve.ce.annotationFactory.register( ve.ce.MWInternalLinkAnnotation );