Debian Codegraph @

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

raw symbols SCIP
1 /*!
2 * VisualEditor ContentEditable MWNumberedExternalLinkNode class.
3 *
4 * @copyright See AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7
8 /**
9 * ContentEditable MediaWiki numbered external link node.
10 *
11 * @class
12 * @extends ve.ce.LeafNode
13 * @mixes ve.ce.FocusableNode
14 * @constructor
15 * @param {ve.dm.MWNumberedExternalLinkNode} model Model to observe
16 * @param {Object} [config] Configuration options
17 */
18 ve.ce.MWNumberedExternalLinkNode = function VeCeMWNumberedExternalLinkNode() {
19 // Parent constructor
20 ve.ce.MWNumberedExternalLinkNode.super.apply( this, arguments );
21
22 // Wrap the link in a span. The link must remain empty to match :empty selectors.
23 // Also move ve-ce-* classes back up to the wrapper.
24 this.$link = this.$element.removeClass( 've-ce-leafNode' )
25 // These attributes are used for styling, so ensure they exists (they should
26 // have been copied from originalDomElements already)
27 .attr( 'rel', 'mw:ExtLink' )
28 .addClass( 'external' );
29 this.$element = $( '<span>' ).append( this.$link ).addClass( 've-ce-leafNode' );
30
31 // Mixin constructors
32 ve.ce.FocusableNode.call( this );
33
34 // DOM changes
35 this.$element
36 // TODO: Test to see whether we can get away with adding unicode-bidi
37 // embed/isolate style on $element. unicode-bidi isolate is more conceptually
38 // correct, but not well supported (e.g. it seems to result in unexpected jumping
39 // on Chromium).
40 .addClass( 've-ce-mwNumberedExternalLinkNode' )
41 // Need some content to make span take up a cursor position, but it must be text
42 // with no directionality, else it can break Chromium cursoring (see
43 // https://code.google.com/p/chromium/issues/detail?id=441056 ). Either a
44 // unicorn-like img tag or the actual apparent link text ("[1]", hitherto shown
45 // with CSS generated content) would fall foul of this bug. Use a zero-width
46 // space so it doesn't change the appearance.
47 .prepend( $( document.createTextNode( '\u200B' ) ) );
48
49 // Events
50 this.model.connect( this, { update: 'onUpdate' } );
51
52 // Initialization
53 this.onUpdate();
54 };
55
56 /* Inheritance */
57
58 OO.inheritClass( ve.ce.MWNumberedExternalLinkNode, ve.ce.LeafNode );
59
60 OO.mixinClass( ve.ce.MWNumberedExternalLinkNode, ve.ce.FocusableNode );
61
62 /* Static Properties */
63
64 ve.ce.MWNumberedExternalLinkNode.static.name = 'link/mwNumberedExternal';
65
66 ve.ce.MWNumberedExternalLinkNode.static.tagName = 'a';
67
68 ve.ce.MWNumberedExternalLinkNode.static.primaryCommandName = 'link';
69
70 /* Static Methods */
71
72 /**
73 * @inheritdoc
74 */
75 ve.ce.MWNumberedExternalLinkNode.static.getDescription = function ( model ) {
76 return model.getAttribute( 'href' );
77 };
78
79 /* Methods */
80
81 /**
82 * Handle model update events.
83 */
84 ve.ce.MWNumberedExternalLinkNode.prototype.onUpdate = function () {
85 // T322704
86 ve.setAttributeSafe( this.$link[ 0 ], 'href', this.model.getAttribute( 'href' ) || '', '#' );
87 };
88
89 /* Registration */
90
91 ve.ce.nodeFactory.register( ve.ce.MWNumberedExternalLinkNode );