mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 18:39:52 +00:00
34da7d56b8
New changes: 04a5947 Localisation updates from https://translatewiki.net. dd4691b Update OOjs to v1.1.5 2e1a0bb Context refactor Local changes: Add context item support for references, citations, templates and links Change-Id: I5d488ecbf9768dc63de6e545505dbfd5eb84cc61
87 lines
2.3 KiB
JavaScript
87 lines
2.3 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( context, model, config ) {
|
|
// Parent constructor
|
|
ve.ui.MWReferenceContextItem.super.call( this, context, model, config );
|
|
|
|
// 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 ref = ve.dm.MWReferenceModel.static.newFromReferenceNode( this.model ),
|
|
view = new ve.ce.InternalItemNode(
|
|
this.model.getDocument().getInternalList().getItemNode( ref.getListIndex() )
|
|
);
|
|
|
|
// HACK: PHP parser doesn't wrap single lines in a paragraph
|
|
if ( view.$element.children().length === 1 && view.$element.children( 'p' ).length === 1 ) {
|
|
// unwrap inner
|
|
view.$element.children().replaceWith( view.$element.children().contents() );
|
|
}
|
|
|
|
// Make all links open in a new window
|
|
view.$element.find( 'a' ).attr( 'target', '_blank' );
|
|
|
|
view.destroy();
|
|
|
|
return 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() );
|
|
};
|
|
|
|
/* Registration */
|
|
|
|
ve.ui.contextItemFactory.register( ve.ui.MWReferenceContextItem );
|