Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/ce/nodes/ve.ce.MWMagicLinkNode.js

raw symbols SCIP
1 /*!
2 * VisualEditor ContentEditable MWMagicLinkNode class.
3 *
4 * @copyright See AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7
8 /**
9 * ContentEditable MediaWiki magic link node.
10 *
11 * @class
12 * @extends ve.ce.LeafNode
13 * @mixes ve.ce.FocusableNode
14 * @constructor
15 * @param {ve.dm.MWMagicLinkNode} model Model to observe
16 * @param {Object} [config] Configuration options
17 */
18 ve.ce.MWMagicLinkNode = function VeCeMWMagicLinkNode() {
19 // Parent constructor
20 ve.ce.MWMagicLinkNode.super.apply( this, arguments );
21
22 // Mixin constructors
23 ve.ce.FocusableNode.call( this );
24
25 // DOM changes
26 this.$element.addClass( 've-ce-mwMagicLinkNode' );
27
28 // Add link
29 this.$link = $( '<a>' ).appendTo( this.$element );
30
31 // Events
32 this.model.connect( this, { update: 'onUpdate' } );
33
34 // Initialization
35 this.onUpdate();
36 };
37
38 /* Inheritance */
39
40 OO.inheritClass( ve.ce.MWMagicLinkNode, ve.ce.LeafNode );
41
42 OO.mixinClass( ve.ce.MWMagicLinkNode, ve.ce.FocusableNode );
43
44 /* Static Properties */
45
46 ve.ce.MWMagicLinkNode.static.name = 'link/mwMagic';
47
48 ve.ce.MWMagicLinkNode.static.tagName = 'span';
49
50 ve.ce.MWMagicLinkNode.static.primaryCommandName = 'link';
51
52 /* Static Methods */
53
54 /**
55 * @inheritdoc
56 */
57 ve.ce.MWMagicLinkNode.static.getDescription = function ( model ) {
58 return model.getAttribute( 'content' );
59 };
60
61 /* Methods */
62
63 /**
64 * Handle model update events.
65 */
66 ve.ce.MWMagicLinkNode.prototype.onUpdate = function () {
67 this.$link
68 .attr( 'rel', this.model.getRel() )
69 .text( this.model.getAttribute( 'content' ) );
70
71 // T322704
72 ve.setAttributeSafe( this.$link[ 0 ], 'href', this.model.getHref(), '#' );
73 };
74
75 /* Registration */
76
77 ve.ce.nodeFactory.register( ve.ce.MWMagicLinkNode );