Merge "Expose ve.ui.MWInternalLinkContextItem generateBody logic"

This commit is contained in:
jenkins-bot 2017-08-09 18:07:33 +00:00 committed by Gerrit Code Review
commit 430fa82774

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 */