Expose ve.ui.MWInternalLinkContextItem generateBody logic

Change-Id: I94912ac2c471cc5d227fa8b9cb29c302ca29814d
This commit is contained in:
David Chan 2017-08-09 23:18:39 +08:00 committed by Jforrester
parent dc99384c06
commit c03d69b761

View file

@ -33,35 +33,35 @@ ve.ui.MWInternalLinkContextItem.static.name = 'link/internal';
ve.ui.MWInternalLinkContextItem.static.modelClasses = [ ve.dm.MWInternalLinkAnnotation ];
/* Methods */
/* Static methods */
/**
* @inheritdoc
* Generate the body of the link context item
*
* @param {ve.init.mw.LinkCache} linkCache The link cache to use
* @param {ve.dm.MWInternalLinkAnnotation} model The annotation model
* @param {HTMLDocument} htmlDoc The HTML document (for URL resolution)
* @return {jQuery} The jQuery object of the link context item
*/
ve.ui.MWInternalLinkContextItem.prototype.getDescription = function () {
return this.model.getAttribute( 'normalizedTitle' );
};
/**
* @inheritdoc
*/
ve.ui.MWInternalLinkContextItem.prototype.renderBody = function () {
ve.ui.MWInternalLinkContextItem.static.generateBody = function ( linkCache, model, htmlDoc ) {
var icon, $description,
title = model.getAttribute( 'lookupTitle' ),
description = model.getAttribute( 'normalizedTitle' ),
href = model.getHref(),
fragment = model.getFragment(),
usePageImages = mw.config.get( 'wgVisualEditor' ).usePageImages,
usePageDescriptions = mw.config.get( 'wgVisualEditor' ).usePageDescriptions,
title = this.model.getAttribute( 'lookupTitle' ),
htmlDoc = this.context.getSurface().getModel().getDocument().getHtmlDocument(),
$wrapper = $( '<div>' ),
$link = $( '<a>' )
.addClass( 've-ui-mwInternalLinkContextItem-link' )
.text( this.getDescription() )
.text( description )
.attr( {
href: ve.resolveUrl( this.model.getHref(), htmlDoc ),
href: ve.resolveUrl( href, htmlDoc ),
target: '_blank'
} );
// Style based on link cache information
ve.init.platform.linkCache.styleElement( title, $link, this.model.getFragment() );
ve.init.platform.linkCache.styleElement( title, $link, fragment );
// Don't style as a self-link in the context menu (but do elsewhere)
$link.removeClass( 'mw-selflink' );
@ -78,10 +78,8 @@ ve.ui.MWInternalLinkContextItem.prototype.renderBody = function () {
$wrapper.addClass( 've-ui-mwInternalLinkContextItem-withDescription' );
}
this.$body.empty().append( $wrapper );
if ( usePageImages || usePageDescriptions ) {
ve.init.platform.linkCache.get( title ).then( function ( linkData ) {
linkCache.get( title ).then( function ( linkData ) {
if ( usePageImages ) {
if ( linkData.imageUrl ) {
icon.$element
@ -99,6 +97,27 @@ ve.ui.MWInternalLinkContextItem.prototype.renderBody = function () {
}
} );
}
return $wrapper;
};
/* Methods */
/**
* @inheritdoc
*/
ve.ui.MWInternalLinkContextItem.prototype.getDescription = function () {
return this.model.getAttribute( 'normalizedTitle' );
};
/**
* @inheritdoc
*/
ve.ui.MWInternalLinkContextItem.prototype.renderBody = function () {
this.$body.empty().append( this.constructor.static.generateBody(
ve.init.platform.linkCache,
this.model,
this.context.getSurface().getModel().getDocument().getHtmlDocument()
) );
};
/* Registration */