2015-02-25 22:56:28 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MWInternalLinkContextItem class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2015 VisualEditor Team and others; see http://ve.mit-license.org
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Context item for a MWInternalLink.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ui.LinkContextItem
|
|
|
|
*
|
|
|
|
* @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-03-27 18:56:16 +00:00
|
|
|
ve.ui.MWInternalLinkContextItem = function VeMWInternalLinkContextItem() {
|
2015-02-25 22:56:28 +00:00
|
|
|
// Parent constructor
|
2015-03-27 18:56:16 +00:00
|
|
|
ve.ui.MWInternalLinkContextItem.super.apply( this, arguments );
|
2015-02-25 22:56:28 +00:00
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$element.addClass( 've-ui-mwInternalLinkContextItem' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWInternalLinkContextItem, ve.ui.LinkContextItem );
|
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.ui.MWInternalLinkContextItem.static.name = 'link/internal';
|
|
|
|
|
|
|
|
ve.ui.MWInternalLinkContextItem.static.modelClasses = [ ve.dm.MWInternalLinkAnnotation ];
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWInternalLinkContextItem.prototype.getDescription = function () {
|
|
|
|
return this.model.getAttribute( 'normalizedTitle' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWInternalLinkContextItem.prototype.renderBody = function () {
|
2015-03-04 16:17:06 +00:00
|
|
|
var htmlDoc = this.context.getSurface().getModel().getDocument().getHtmlDocument(),
|
|
|
|
$link = $( '<a>' )
|
|
|
|
.text( this.getDescription() )
|
|
|
|
.attr( {
|
|
|
|
href: ve.resolveUrl( this.model.getHref(), htmlDoc ),
|
|
|
|
target: '_blank'
|
|
|
|
} );
|
2015-02-25 22:56:28 +00:00
|
|
|
this.$body.empty().append( $link );
|
|
|
|
|
|
|
|
// Style based on link cache information
|
|
|
|
ve.init.platform.linkCache.styleElement( this.model.getAttribute( 'lookupTitle' ), $link );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.contextItemFactory.register( ve.ui.MWInternalLinkContextItem );
|