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
|
|
|
|
* @param {Object} config Configuration options
|
|
|
|
*/
|
|
|
|
ve.ui.MWMediaContextItem = function VeUiMWMediaContextItem( context, model ) {
|
|
|
|
var mediaClass;
|
|
|
|
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWMediaContextItem.super.apply( this, arguments );
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$element.addClass( 've-ui-mwMediaContextItem' );
|
|
|
|
|
|
|
|
mediaClass = model.getAttribute( 'mediaClass' ) || 'Image';
|
|
|
|
|
2018-04-06 14:32:55 +00:00
|
|
|
this.setIcon( model.getAttribute( 'isError' ) ? 'imageBroken' : {
|
2018-03-20 12:48:27 +00:00
|
|
|
Image: 'image',
|
|
|
|
// TODO: Better icons for audio/video
|
|
|
|
Audio: 'play',
|
|
|
|
Video: 'play'
|
|
|
|
}[ mediaClass ] );
|
|
|
|
// The following messages can be used here
|
|
|
|
// * visualeditor-media-title-audio
|
|
|
|
// * visualeditor-media-title-image
|
|
|
|
// * visualeditor-media-title-video
|
|
|
|
this.setLabel( ve.msg( 'visualeditor-media-title-' + mediaClass.toLowerCase() ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* 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 () {
|
2018-05-05 13:03:48 +00:00
|
|
|
var htmlDoc = this.context.getSurface().getModel().getDocument().getHtmlDocument();
|
2018-03-20 12:49:13 +00:00
|
|
|
this.$body.append(
|
|
|
|
$( '<a>' )
|
|
|
|
.text( this.getDescription() )
|
|
|
|
.attr( {
|
2018-05-05 13:03:48 +00:00
|
|
|
href: ve.resolveUrl( this.model.getAttribute( 'resource' ), htmlDoc ),
|
2018-03-20 12:49:13 +00:00
|
|
|
target: '_blank',
|
|
|
|
rel: 'noopener'
|
|
|
|
} )
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2018-03-20 12:48:27 +00:00
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.contextItemFactory.register( ve.ui.MWMediaContextItem );
|