2015-02-25 22:56:28 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MWReferenceContextItem class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2015 VisualEditor Team and others; see http://ve.mit-license.org
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Context item for a MWReference.
|
|
|
|
*
|
|
|
|
* @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.MWReferenceContextItem = function VeUiMWReferenceContextItem() {
|
2015-02-25 22:56:28 +00:00
|
|
|
// Parent constructor
|
2015-03-27 18:56:16 +00:00
|
|
|
ve.ui.MWReferenceContextItem.super.apply( this, arguments );
|
2015-03-30 21:45:34 +00:00
|
|
|
this.view = null;
|
2015-02-25 22:56:28 +00:00
|
|
|
// Initialization
|
|
|
|
this.$element.addClass( 've-ui-mwReferenceContextItem' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2015-08-18 15:55:13 +00:00
|
|
|
OO.inheritClass( ve.ui.MWReferenceContextItem, ve.ui.LinearContextItem );
|
2015-02-25 22:56:28 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWReferenceContextItem.static.name = 'reference';
|
|
|
|
|
|
|
|
ve.ui.MWReferenceContextItem.static.icon = 'reference';
|
|
|
|
|
2015-07-24 12:40:15 +00:00
|
|
|
ve.ui.MWReferenceContextItem.static.label = OO.ui.deferMsg( 'visualeditor-dialogbutton-reference-title' );
|
2015-02-25 22:56:28 +00:00
|
|
|
|
|
|
|
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 () {
|
2015-10-05 15:01:54 +00:00
|
|
|
var refNode = this.getReferenceNode();
|
|
|
|
if ( refNode ) {
|
2015-11-23 22:28:57 +00:00
|
|
|
this.view = new ve.ui.MWPreviewElement( refNode );
|
2015-07-24 12:17:41 +00:00
|
|
|
|
|
|
|
// The $element property may be rendered into asynchronously, update the context's size when the
|
|
|
|
// rendering is complete if that's the case
|
|
|
|
this.view.once( 'render', this.context.updateDimensions.bind( this.context ) );
|
|
|
|
|
|
|
|
return this.view.$element;
|
|
|
|
} else {
|
|
|
|
return $( '<div>' )
|
|
|
|
.addClass( 've-ui-mwReferenceContextItem-muted' )
|
|
|
|
.text( ve.msg( 'visualeditor-referenceslist-missingref' ) );
|
|
|
|
}
|
2015-02-25 22:56:28 +00:00
|
|
|
};
|
|
|
|
|
2015-10-05 15:01:54 +00:00
|
|
|
/**
|
|
|
|
* Get the reference node in the containing document (not the internal list document)
|
|
|
|
*
|
|
|
|
* @return {ve.dm.Node} Reference node
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceContextItem.prototype.getReferenceNode = function () {
|
|
|
|
var refModel;
|
|
|
|
if ( !this.model.isEditable() ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if ( !this.referenceNode ) {
|
|
|
|
refModel = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model );
|
|
|
|
this.referenceNode = this.getFragment().getDocument().getInternalList().getItemNode( refModel.getListIndex() );
|
|
|
|
}
|
|
|
|
return this.referenceNode;
|
|
|
|
};
|
|
|
|
|
2015-02-25 22:56:28 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceContextItem.prototype.getDescription = function () {
|
2015-07-24 12:17:41 +00:00
|
|
|
return this.model.isEditable() ? this.getRendering().text() : ve.msg( 'visualeditor-referenceslist-missingref' );
|
2015-02-25 22:56:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceContextItem.prototype.renderBody = function () {
|
|
|
|
this.$body.empty().append( this.getRendering() );
|
|
|
|
};
|
|
|
|
|
2015-03-30 21:45:34 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWReferenceContextItem.prototype.teardown = function () {
|
|
|
|
if ( this.view ) {
|
|
|
|
this.view.destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call parent
|
|
|
|
ve.ui.MWReferenceContextItem.super.prototype.teardown.call( this );
|
|
|
|
};
|
|
|
|
|
2015-02-25 22:56:28 +00:00
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.contextItemFactory.register( ve.ui.MWReferenceContextItem );
|