mediawiki-extensions-Cite/modules/ve-cite/ve.ui.MWReferenceResultWidget.js
WMDE-Fisch 14d87b1e04 Add a submenu to offer a re-use with different details
Adding a submenu to the results of the reference re-use search.
This allows the user to either create a direct reuse or a reuse with
different details.

Hide the menu when there's a sub-reference.

Known Issues:
- Ref name is hidden (conditionally when our feature is enabled) as a
  quick fix to not having a good layout choice yet.
- Submenu is clipped at the dialog bounds.
- Submenu highlight should vanish when the submenu is closed
- Instrument action with metrics.

Bug: T375053
Change-Id: I3eddd6bad328aaf9bb99eb2783ba66d4e08f862d
2024-10-01 13:26:52 +02:00

56 lines
1.6 KiB
JavaScript

'use strict';
/*!
* VisualEditor UserInterface MWReferenceResultWidget class.
*
* @copyright 2011-2018 VisualEditor Team's Cite sub-team and others; see AUTHORS.txt
* @license MIT
*/
/**
* Creates an ve.ui.MWReferenceResultWidget object.
*
* @constructor
* @extends OO.ui.OptionWidget
* @param {Object} config Configuration options
* @param {Object} config.item Result item
* @param {Object} config.reuseMenu
*/
ve.ui.MWReferenceResultWidget = function VeUiMWReferenceResultWidget( config ) {
config = ve.extendObject( {
title: ve.msg( 'cite-ve-dialog-reference-useexisting-long-tool' )
}, config );
// Parent constructor
ve.ui.MWReferenceResultWidget.super.apply( this, arguments );
// Initialization
const item = config.item;
this.$element
.addClass( 've-ui-mwReferenceResultWidget' );
if ( item.reference.extendsRef !== undefined ) {
this.$element.addClass( 've-ui-mwReferenceResultWidget-sub' );
}
const $footnoteLabel = $( '<div>' )
.addClass( 've-ui-mwReferenceResultWidget-footnote' )
.text( '[' + item.footnoteLabel + ']' );
const $name = $( '<div>' )
.addClass( 've-ui-mwReferenceResultWidget-name' )
.toggleClass( 've-ui-mwReferenceResultWidget-name-autogenerated', /^:\d+$/.test( item.name ) )
.text( item.name );
this.setLabel( $footnoteLabel.add( $name ).add( item.$refContent ) );
this.setData( item.reference );
if ( mw.config.get( 'wgCiteBookReferencing' ) && config.reuseMenu ) {
this.$element.append( config.reuseMenu.$element );
}
};
/* Inheritance */
OO.inheritClass( ve.ui.MWReferenceResultWidget, OO.ui.OptionWidget );