2015-02-25 22:56:28 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MWInternalLinkContextItem class.
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2015-02-25 22:56:28 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Context item for a MWInternalLink.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ui.LinkContextItem
|
|
|
|
*
|
|
|
|
* @constructor
|
2023-07-10 13:31:31 +00:00
|
|
|
* @param {ve.ui.LinearContext} context Context the item is in
|
|
|
|
* @param {ve.dm.Model} model Model the item is related to
|
2023-02-02 09:47:32 +00:00
|
|
|
* @param {Object} [config]
|
2015-02-25 22:56:28 +00:00
|
|
|
*/
|
2015-08-18 12:54:51 +00:00
|
|
|
ve.ui.MWInternalLinkContextItem = function VeUiMWInternalLinkContextItem() {
|
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 ];
|
|
|
|
|
2017-08-09 15:18:39 +00:00
|
|
|
/* Static methods */
|
2015-02-25 22:56:28 +00:00
|
|
|
|
|
|
|
/**
|
2017-08-09 15:18:39 +00:00
|
|
|
* 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)
|
2023-07-10 13:31:31 +00:00
|
|
|
* @param {ve.ui.LinearContext} context Context (for resizing)
|
2017-08-09 15:18:39 +00:00
|
|
|
* @return {jQuery} The jQuery object of the link context item
|
2015-02-25 22:56:28 +00:00
|
|
|
*/
|
2018-01-17 16:06:28 +00:00
|
|
|
ve.ui.MWInternalLinkContextItem.static.generateBody = function ( linkCache, model, htmlDoc, context ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const lookupTitle = model.getAttribute( 'lookupTitle' ),
|
2019-09-18 20:54:24 +00:00
|
|
|
normalizedTitle = model.getAttribute( 'normalizedTitle' ),
|
2017-08-09 15:18:39 +00:00
|
|
|
href = model.getHref(),
|
2022-11-24 13:39:23 +00:00
|
|
|
title = mw.Title.newFromText( mw.libs.ve.normalizeParsoidResourceName( href ) ),
|
2017-08-09 15:18:39 +00:00
|
|
|
fragment = model.getFragment(),
|
2019-04-16 23:09:23 +00:00
|
|
|
usePageImages = mw.config.get( 'wgVisualEditorConfig' ).usePageImages,
|
|
|
|
usePageDescriptions = mw.config.get( 'wgVisualEditorConfig' ).usePageDescriptions,
|
2015-04-25 00:36:15 +00:00
|
|
|
$wrapper = $( '<div>' ),
|
2015-03-04 16:17:06 +00:00
|
|
|
$link = $( '<a>' )
|
2019-08-10 13:55:15 +00:00
|
|
|
.addClass( 've-ui-linkContextItem-link' )
|
2019-09-18 20:54:24 +00:00
|
|
|
.text( normalizedTitle )
|
2015-03-04 16:17:06 +00:00
|
|
|
.attr( {
|
2017-11-30 19:15:38 +00:00
|
|
|
target: '_blank',
|
|
|
|
rel: 'noopener'
|
2015-03-04 16:17:06 +00:00
|
|
|
} );
|
2015-02-25 22:56:28 +00:00
|
|
|
|
2022-11-24 13:39:23 +00:00
|
|
|
// T322704
|
|
|
|
ve.setAttributeSafe( $link[ 0 ], 'href', title.getUrl(), '#' );
|
|
|
|
|
2015-02-25 22:56:28 +00:00
|
|
|
// Style based on link cache information
|
2022-11-24 13:39:23 +00:00
|
|
|
ve.init.platform.linkCache.styleElement( lookupTitle, $link, fragment );
|
2017-04-11 16:20:38 +00:00
|
|
|
// Don't style as a self-link in the context menu (but do elsewhere)
|
|
|
|
$link.removeClass( 'mw-selflink' );
|
2015-04-25 00:36:15 +00:00
|
|
|
|
2024-05-21 14:22:56 +00:00
|
|
|
let icon;
|
2015-04-25 00:36:15 +00:00
|
|
|
if ( usePageImages ) {
|
2015-04-28 15:26:42 +00:00
|
|
|
icon = new OO.ui.IconWidget( { icon: 'page-existing' } );
|
2015-04-25 00:36:15 +00:00
|
|
|
$wrapper
|
|
|
|
.addClass( 've-ui-mwInternalLinkContextItem-withImage' )
|
|
|
|
.append( icon.$element );
|
|
|
|
}
|
|
|
|
|
|
|
|
$wrapper.append( $link );
|
|
|
|
|
|
|
|
if ( usePageDescriptions ) {
|
|
|
|
$wrapper.addClass( 've-ui-mwInternalLinkContextItem-withDescription' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( usePageImages || usePageDescriptions ) {
|
2024-04-30 16:44:25 +00:00
|
|
|
linkCache.get( lookupTitle ).then( ( linkData ) => {
|
2015-04-28 15:26:42 +00:00
|
|
|
if ( usePageImages ) {
|
|
|
|
if ( linkData.imageUrl ) {
|
|
|
|
icon.$element
|
2023-08-30 18:02:52 +00:00
|
|
|
.addClass( 've-ui-mwInternalLinkContextItem-hasImage mw-no-invert' )
|
2015-04-28 15:26:42 +00:00
|
|
|
.css( 'background-image', 'url(' + linkData.imageUrl + ')' );
|
|
|
|
} else {
|
|
|
|
icon.setIcon( ve.init.platform.linkCache.constructor.static.getIconForLink( linkData ) );
|
|
|
|
}
|
2015-04-25 00:36:15 +00:00
|
|
|
}
|
|
|
|
if ( usePageDescriptions && linkData.description ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const $description = $( '<span>' )
|
2015-04-25 00:36:15 +00:00
|
|
|
.addClass( 've-ui-mwInternalLinkContextItem-description' )
|
|
|
|
.text( linkData.description );
|
|
|
|
$wrapper.append( $description );
|
2018-01-17 16:06:28 +00:00
|
|
|
// Multiline descriptions may make the context bigger (T183650)
|
|
|
|
context.updateDimensions();
|
2015-04-25 00:36:15 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
2017-08-09 15:18:39 +00:00
|
|
|
return $wrapper;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWInternalLinkContextItem.prototype.getDescription = function () {
|
|
|
|
return this.model.getAttribute( 'normalizedTitle' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWInternalLinkContextItem.prototype.renderBody = function () {
|
2024-05-21 14:22:56 +00:00
|
|
|
const $body = this.constructor.static.generateBody(
|
2017-08-09 15:18:39 +00:00
|
|
|
ve.init.platform.linkCache,
|
|
|
|
this.model,
|
2018-01-17 16:06:28 +00:00
|
|
|
this.context.getSurface().getModel().getDocument().getHtmlDocument(),
|
|
|
|
this.context
|
2021-10-25 15:51:29 +00:00
|
|
|
);
|
|
|
|
this.$body.empty().append( $body );
|
2019-07-05 16:53:10 +00:00
|
|
|
if ( !this.context.isMobile() ) {
|
|
|
|
this.$body.append( this.$labelLayout );
|
|
|
|
}
|
2018-05-30 16:57:03 +00:00
|
|
|
this.updateLabelPreview();
|
2015-02-25 22:56:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.contextItemFactory.register( ve.ui.MWInternalLinkContextItem );
|