2015-02-25 22:56:28 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MWTransclusionContextItem class.
|
|
|
|
*
|
2019-01-01 13:24:23 +00:00
|
|
|
* @copyright 2011-2019 VisualEditor Team and others; see http://ve.mit-license.org
|
2015-02-25 22:56:28 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Context item for a MWTransclusion.
|
|
|
|
*
|
|
|
|
* @class
|
2015-08-18 15:55:13 +00:00
|
|
|
* @extends ve.ui.LinearContextItem
|
2015-02-25 22:56:28 +00:00
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*/
|
2015-08-18 12:54:51 +00:00
|
|
|
ve.ui.MWTransclusionContextItem = function VeUiMWTransclusionContextItem() {
|
2015-02-25 22:56:28 +00:00
|
|
|
// Parent constructor
|
2015-03-27 18:56:16 +00:00
|
|
|
ve.ui.MWTransclusionContextItem.super.apply( this, arguments );
|
2015-02-25 22:56:28 +00:00
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$element.addClass( 've-ui-mwTransclusionContextItem' );
|
|
|
|
if ( !this.model.isSingleTemplate() ) {
|
|
|
|
this.setLabel( ve.msg( 'visualeditor-dialogbutton-transclusion-tooltip' ) );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2015-08-18 15:55:13 +00:00
|
|
|
OO.inheritClass( ve.ui.MWTransclusionContextItem, ve.ui.LinearContextItem );
|
2015-02-25 22:56:28 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWTransclusionContextItem.static.name = 'transclusion';
|
|
|
|
|
2017-07-06 16:52:56 +00:00
|
|
|
ve.ui.MWTransclusionContextItem.static.icon = 'puzzle';
|
2015-02-25 22:56:28 +00:00
|
|
|
|
|
|
|
ve.ui.MWTransclusionContextItem.static.label =
|
|
|
|
OO.ui.deferMsg( 'visualeditor-dialogbutton-template-tooltip' );
|
|
|
|
|
|
|
|
ve.ui.MWTransclusionContextItem.static.modelClasses = [ ve.dm.MWTransclusionNode ];
|
|
|
|
|
|
|
|
ve.ui.MWTransclusionContextItem.static.commandName = 'transclusion';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Only display item for single-template transclusions of these templates.
|
|
|
|
*
|
|
|
|
* @property {string|string[]|null}
|
|
|
|
* @static
|
|
|
|
* @inheritable
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionContextItem.static.template = null;
|
|
|
|
|
|
|
|
/* Static Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @static
|
|
|
|
* @localdoc Sharing implementation with ve.ui.MWTransclusionDialogTool
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionContextItem.static.isCompatibleWith =
|
|
|
|
ve.ui.MWTransclusionDialogTool.static.isCompatibleWith;
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionContextItem.prototype.getDescription = function () {
|
|
|
|
return ve.msg(
|
|
|
|
'visualeditor-dialog-transclusion-contextitem-description',
|
2015-08-19 16:05:17 +00:00
|
|
|
ve.ce.MWTransclusionNode.static.getDescription( this.model ),
|
|
|
|
ve.ce.MWTransclusionNode.static.getTemplatePartDescriptions( this.model ).length
|
2015-02-25 22:56:28 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2018-11-15 19:16:44 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2019-02-06 21:36:52 +00:00
|
|
|
ve.ui.MWTransclusionContextItem.prototype.renderDescription = function () {
|
2018-11-15 19:16:44 +00:00
|
|
|
// No "Generated from" prefix in mobile context
|
|
|
|
this.$description.text( ve.ce.MWTransclusionNode.static.getDescription( this.model ) );
|
|
|
|
};
|
|
|
|
|
2015-08-03 14:25:03 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWTransclusionContextItem.prototype.onEditButtonClick = function () {
|
|
|
|
var surfaceModel = this.context.getSurface().getModel(),
|
|
|
|
selection = surfaceModel.getSelection();
|
|
|
|
|
|
|
|
if ( selection instanceof ve.dm.TableSelection ) {
|
2018-10-29 19:40:44 +00:00
|
|
|
surfaceModel.setLinearSelection( selection.getOuterRanges(
|
|
|
|
surfaceModel.getDocument()
|
|
|
|
)[ 0 ] );
|
2015-08-03 14:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWTransclusionContextItem.super.prototype.onEditButtonClick.apply( this, arguments );
|
|
|
|
};
|
|
|
|
|
2015-02-25 22:56:28 +00:00
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.contextItemFactory.register( ve.ui.MWTransclusionContextItem );
|