2018-03-20 12:48:27 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MWMediaContextItem class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2017 VisualEditor Team and others; see http://ve.mit-license.org
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Context item for a MWImageNode.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ui.LinearContextItem
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {ve.ui.Context} context Context item is in
|
|
|
|
* @param {ve.dm.Model} model Model item is related to
|
2023-02-02 09:47:32 +00:00
|
|
|
* @param {Object} [config]
|
2018-03-20 12:48:27 +00:00
|
|
|
*/
|
|
|
|
ve.ui.MWMediaContextItem = function VeUiMWMediaContextItem( context, model ) {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWMediaContextItem.super.apply( this, arguments );
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$element.addClass( 've-ui-mwMediaContextItem' );
|
|
|
|
|
2022-05-30 23:17:46 +00:00
|
|
|
var mediaTag = model.getAttribute( 'mediaTag' ) || 'img';
|
2018-03-20 12:48:27 +00:00
|
|
|
|
2022-05-30 23:17:46 +00:00
|
|
|
this.setIcon( {
|
|
|
|
img: 'image',
|
|
|
|
span: 'imageBroken',
|
2018-03-20 12:48:27 +00:00
|
|
|
// TODO: Better icons for audio/video
|
2022-05-30 23:17:46 +00:00
|
|
|
audio: 'play',
|
|
|
|
video: 'play'
|
|
|
|
}[ mediaTag ] );
|
|
|
|
|
|
|
|
var messagePostfix = ( mediaTag === 'audio' || mediaTag === 'video' ) ? mediaTag : 'image';
|
|
|
|
|
2019-08-28 15:41:19 +00:00
|
|
|
// The following messages are used here:
|
2018-03-20 12:48:27 +00:00
|
|
|
// * visualeditor-media-title-audio
|
|
|
|
// * visualeditor-media-title-image
|
|
|
|
// * visualeditor-media-title-video
|
2022-05-30 23:17:46 +00:00
|
|
|
this.setLabel( ve.msg( 'visualeditor-media-title-' + messagePostfix ) );
|
2018-03-20 12:48:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWMediaContextItem, ve.ui.LinearContextItem );
|
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWMediaContextItem.static.name = 'mwMedia';
|
|
|
|
|
|
|
|
ve.ui.MWMediaContextItem.static.icon = 'image';
|
|
|
|
|
|
|
|
ve.ui.MWMediaContextItem.static.label =
|
|
|
|
OO.ui.deferMsg( 'visualeditor-media-title-image' );
|
|
|
|
|
|
|
|
ve.ui.MWMediaContextItem.static.modelClasses = [ ve.dm.MWBlockImageNode, ve.dm.MWInlineImageNode ];
|
|
|
|
|
|
|
|
ve.ui.MWMediaContextItem.static.commandName = 'media';
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaContextItem.prototype.getDescription = function () {
|
|
|
|
return ve.ce.nodeFactory.getDescription( this.model );
|
|
|
|
};
|
|
|
|
|
2018-03-20 12:49:13 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaContextItem.prototype.renderBody = function () {
|
2020-03-20 17:08:24 +00:00
|
|
|
var title = mw.Title.newFromText( mw.libs.ve.normalizeParsoidResourceName( this.model.getAttribute( 'resource' ) ) );
|
2022-11-24 13:39:23 +00:00
|
|
|
var $link = $( '<a>' )
|
|
|
|
.text( this.getDescription() )
|
|
|
|
.attr( {
|
|
|
|
target: '_blank',
|
|
|
|
rel: 'noopener'
|
|
|
|
} );
|
|
|
|
// T322704
|
|
|
|
ve.setAttributeSafe( $link[ 0 ], 'href', title.getUrl(), '#' );
|
|
|
|
|
|
|
|
this.$body.append( $link );
|
2018-03-20 12:49:13 +00:00
|
|
|
};
|
|
|
|
|
2018-03-20 12:48:27 +00:00
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.contextItemFactory.register( ve.ui.MWMediaContextItem );
|