mediawiki-extensions-Visual.../modules/ve-mw/ui/contextitems/ve.ui.MWReferenceContextItem.js
Moriel Schottlender 1ab496d65a Use the preview widget in context items
Use the newly created preview widget to render consistent previews
of references in the context items and search widget.

Depends on ve-core fix Ia7e96e048e4b

Bug: T93042
Change-Id: I3a7f6402018924a18efbb49ba61a16787c41f1f4
2015-04-16 01:47:16 +00:00

89 lines
2.2 KiB
JavaScript

/*!
* VisualEditor MWReferenceContextItem class.
*
* @copyright 2011-2015 VisualEditor Team and others; see http://ve.mit-license.org
*/
/**
* Context item for a MWReference.
*
* @class
* @extends ve.ui.ContextItem
*
* @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.MWReferenceContextItem = function VeMWReferenceContextItem() {
// Parent constructor
ve.ui.MWReferenceContextItem.super.apply( this, arguments );
this.view = null;
// Initialization
this.$element.addClass( 've-ui-mwReferenceContextItem' );
};
/* Inheritance */
OO.inheritClass( ve.ui.MWReferenceContextItem, ve.ui.ContextItem );
/* Static Properties */
ve.ui.MWReferenceContextItem.static.name = 'reference';
ve.ui.MWReferenceContextItem.static.icon = 'reference';
ve.ui.MWReferenceContextItem.static.label = OO.ui.deferMsg( 'visualeditor-dialogbutton-reference-tooltip' );
ve.ui.MWReferenceContextItem.static.modelClasses = [ ve.dm.MWReferenceNode ];
ve.ui.MWReferenceContextItem.static.commandName = 'reference';
/* Methods */
/**
* Get a DOM rendering of the reference.
*
* @private
* @return {jQuery} DOM rendering of reference
*/
ve.ui.MWReferenceContextItem.prototype.getRendering = function () {
var refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model );
this.view = new ve.ui.PreviewWidget(
refModel.getDocument().getInternalList().getItemNode( refModel.getListIndex() )
);
// WARNING: The $element property may be rendered into asynchronously
return this.view.$element;
};
/**
* @inheritdoc
*/
ve.ui.MWReferenceContextItem.prototype.getDescription = function () {
return this.getRendering().text();
};
/**
* @inheritdoc
*/
ve.ui.MWReferenceContextItem.prototype.renderBody = function () {
this.$body.empty().append( this.getRendering() );
};
/**
* @inheritdoc
*/
ve.ui.MWReferenceContextItem.prototype.teardown = function () {
if ( this.view ) {
this.view.destroy();
}
// Call parent
ve.ui.MWReferenceContextItem.super.prototype.teardown.call( this );
};
/* Registration */
ve.ui.contextItemFactory.register( ve.ui.MWReferenceContextItem );