Debian Codegraph @

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

raw symbols SCIP
1 /*!
2 * VisualEditor ContentEditable LinkAnnotation class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * ContentEditable link annotation.
9 *
10 * @class
11 * @extends ve.ce.Annotation
12 * @mixes ve.ce.NailedAnnotation
13 * @constructor
14 * @param {ve.dm.LinkAnnotation} model Model to observe
15 * @param {ve.ce.ContentBranchNode} [parentNode] Node rendering this annotation
16 * @param {Object} [config] Configuration options
17 */
18 ve.ce.LinkAnnotation = function VeCeLinkAnnotation( model, parentNode, config ) {
19 // Parent constructor
20 ve.ce.LinkAnnotation.super.call( this, model, parentNode, ve.extendObject( { $element: $( '<a>' ) }, config ) );
21
22 // Mixin constructor
23 ve.ce.NailedAnnotation.call( this );
24
25 this.$element.addClass( 've-ce-linkAnnotation' )
26 .prop( {
27 title: this.constructor.static.getDescription( this.model )
28 } );
29 // T322704
30 ve.setAttributeSafe( this.$element[ 0 ], 'href', ve.resolveUrl( this.model.getHref(), this.getModelHtmlDocument() ), '#' );
31
32 this.$element.on( 'click', this.onClick.bind( this ) );
33 // Deprecated, use this.$element
34 this.$anchor = this.$element;
35 };
36
37 /* Inheritance */
38
39 OO.inheritClass( ve.ce.LinkAnnotation, ve.ce.Annotation );
40
41 OO.mixinClass( ve.ce.LinkAnnotation, ve.ce.NailedAnnotation );
42
43 /* Static Properties */
44
45 ve.ce.LinkAnnotation.static.name = 'link';
46
47 ve.ce.LinkAnnotation.static.tagName = 'span';
48
49 /* Static Methods */
50
51 /**
52 * @inheritdoc
53 */
54 ve.ce.LinkAnnotation.static.getDescription = function ( model ) {
55 return model.getHref();
56 };
57
58 /* Methods */
59
60 /* istanbul ignore next */
61 /**
62 * Handle click events.
63 *
64 * @param {jQuery.Event} e Mouse click event
65 */
66 ve.ce.LinkAnnotation.prototype.onClick = function ( e ) {
67 if ( e.which === OO.ui.MouseButtons.LEFT && ( e.ctrlKey || e.metaKey ) ) {
68 window.open( this.$element.prop( 'href' ) );
69 // Prevent multiple windows being opened, or other action being performed (e.g. middle click paste)
70 e.preventDefault();
71 }
72 };
73
74 /* Registration */
75
76 ve.ce.annotationFactory.register( ve.ce.LinkAnnotation );