Debian Codegraph @

extensions/VisualEditor/modules/ve-mw/ui/contextitems/ve.ui.MWMediaContextItem.js

raw symbols SCIP
1 /*!
2 * VisualEditor MWMediaContextItem class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * Context item for a MWImageNode.
9 *
10 * @class
11 * @extends ve.ui.LinearContextItem
12 *
13 * @constructor
14 * @param {ve.ui.LinearContext} context Context the item is in
15 * @param {ve.dm.Model} model Model the item is related to
16 * @param {Object} [config]
17 */
18 ve.ui.MWMediaContextItem = function VeUiMWMediaContextItem( context, model ) {
19 // Parent constructor
20 ve.ui.MWMediaContextItem.super.apply( this, arguments );
21
22 // Initialization
23 this.$element.addClass( 've-ui-mwMediaContextItem' );
24
25 const mediaTag = model.getAttribute( 'mediaTag' ) || 'img';
26
27 this.setIcon( {
28 img: 'image',
29 span: 'imageBroken',
30 // TODO: Better icons for audio/video
31 audio: 'play',
32 video: 'play'
33 }[ mediaTag ] );
34
35 const messagePostfix = ( mediaTag === 'audio' || mediaTag === 'video' ) ? mediaTag : 'image';
36
37 // The following messages are used here:
38 // * visualeditor-media-title-audio
39 // * visualeditor-media-title-image
40 // * visualeditor-media-title-video
41 this.setLabel( ve.msg( 'visualeditor-media-title-' + messagePostfix ) );
42 };
43
44 /* Inheritance */
45
46 OO.inheritClass( ve.ui.MWMediaContextItem, ve.ui.LinearContextItem );
47
48 /* Static Properties */
49
50 ve.ui.MWMediaContextItem.static.name = 'mwMedia';
51
52 ve.ui.MWMediaContextItem.static.icon = 'image';
53
54 ve.ui.MWMediaContextItem.static.label =
55 OO.ui.deferMsg( 'visualeditor-media-title-image' );
56
57 ve.ui.MWMediaContextItem.static.modelClasses = [ ve.dm.MWBlockImageNode, ve.dm.MWInlineImageNode ];
58
59 ve.ui.MWMediaContextItem.static.commandName = 'media';
60
61 /* Methods */
62
63 /**
64 * @inheritdoc
65 */
66 ve.ui.MWMediaContextItem.prototype.getDescription = function () {
67 return ve.ce.nodeFactory.getDescription( this.model );
68 };
69
70 /**
71 * @inheritdoc
72 */
73 ve.ui.MWMediaContextItem.prototype.renderBody = function () {
74 const title = mw.Title.newFromText( mw.libs.ve.normalizeParsoidResourceName( this.model.getAttribute( 'resource' ) ) );
75 const $link = $( '<a>' )
76 .text( this.getDescription() )
77 .attr( {
78 target: '_blank',
79 rel: 'noopener'
80 } );
81 // T322704
82 ve.setAttributeSafe( $link[ 0 ], 'href', title.getUrl(), '#' );
83
84 this.$body.append( $link );
85 };
86
87 /* Registration */
88
89 ve.ui.contextItemFactory.register( ve.ui.MWMediaContextItem );