mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite
synced 2024-11-15 19:10:15 +00:00
18f616b9b8
This code has been developed over three years now in the repo of MediaWiki's integration of VisualEditor. It has grown and developed significantly during that time, but now is pretty stable. A number of hacks inside the MediaWiki- VisualEditor code base have been used to prevent this code from being loaded on wikis where the Cite extension is not deployed, but this state of affairs is and always was meant to be temporary. This code is under the MIT licence which is a tad messy, but not impossible. It's clearly labelled as such. The list of authors has been updated to take into account the influx of new functionality. Bug: T41621 Bug: T104928 Change-Id: I39936ed83d5a60471a0a75da753f498e80aef234
113 lines
3 KiB
JavaScript
113 lines
3 KiB
JavaScript
/*!
|
|
* VisualEditor MWReferenceContextItem class.
|
|
*
|
|
* @copyright 2011-2016 VisualEditor Team and others; see http://ve.mit-license.org
|
|
*/
|
|
|
|
/**
|
|
* Context item for a MWReference.
|
|
*
|
|
* @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.MWReferenceContextItem = function VeUiMWReferenceContextItem() {
|
|
// 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.LinearContextItem );
|
|
|
|
/* Static Properties */
|
|
|
|
ve.ui.MWReferenceContextItem.static.name = 'reference';
|
|
|
|
ve.ui.MWReferenceContextItem.static.icon = 'reference';
|
|
|
|
ve.ui.MWReferenceContextItem.static.label = OO.ui.deferMsg( 'cite-ve-dialogbutton-reference-title' );
|
|
|
|
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 refNode = this.getReferenceNode();
|
|
if ( refNode ) {
|
|
this.view = new ve.ui.MWPreviewElement( refNode );
|
|
|
|
// 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( 'cite-ve-referenceslist-missingref' ) );
|
|
}
|
|
};
|
|
|
|
/**
|
|
* 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;
|
|
};
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
ve.ui.MWReferenceContextItem.prototype.getDescription = function () {
|
|
return this.model.isEditable() ? this.getRendering().text() : ve.msg( 'cite-ve-referenceslist-missingref' );
|
|
};
|
|
|
|
/**
|
|
* @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 );
|