2 * MediaWiki Widgets - TitleOptionWidget class.
4 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
10 * @classdesc Title option widget.
13 * @extends OO.ui.MenuOptionWidget
16 * @description Create a mw.widgets.TitleOptionWidget object.
17 * @param {Object} config Configuration options
18 * @param {string} config.data Label to display
19 * @param {string} config.url URL of page
20 * @param {boolean} [config.showImages] Whether to attempt to show images
21 * @param {string} [config.imageUrl] Thumbnail image URL with URL encoding
22 * @param {string} [config.description] Page description
23 * @param {boolean} [config.missing] Page doesn't exist
24 * @param {boolean} [config.redirect] Page is a redirect
25 * @param {boolean} [config.disambiguation] Page is a disambiguation page
26 * @param {string} [config.query] Matching query string to highlight
27 * @param {Function} [config.compare] String comparison function for query highlighting
29 mw.widgets.TitleOptionWidget = function MwWidgetsTitleOptionWidget( config ) {
32 if ( !config.showImages ) {
34 } else if ( config.missing ) {
35 icon = 'articleNotFound';
36 } else if ( config.redirect ) {
37 icon = 'articleRedirect';
38 } else if ( config.disambiguation ) {
39 icon = 'articleDisambiguation';
44 // Config initialization
45 config = Object.assign( {
53 mw.widgets.TitleOptionWidget.super.call( this, config );
56 this.checkIcon.$element.remove();
59 this.$label.attr( 'href', config.url );
60 this.$element.addClass( 'mw-widget-titleOptionWidget' );
62 // OOUI OptionWidgets make an effort to not be tab accessible, but
63 // adding a link inside them would undo that. So, explicitly make it
65 this.$label.attr( 'tabindex', '-1' );
67 // Allow opening the link in new tab, but not regular navigation.
68 this.$label.on( 'click', ( e ) => {
69 // Don't interfere with special clicks (e.g. to open in new tab)
70 if ( !( e.which !== 1 || e.altKey || e.ctrlKey || e.shiftKey || e.metaKey ) ) {
75 // Highlight matching parts of link suggestion
77 this.setHighlightedQuery( config.data, config.query, config.compare, true );
79 this.$label.attr( 'title', config.data );
81 if ( config.missing ) {
82 this.$label.addClass( 'new' );
83 } else if ( config.redirect ) {
84 this.$label.addClass( 'mw-redirect' );
85 } else if ( config.disambiguation ) {
86 this.$label.addClass( 'mw-disambig' );
89 if ( config.showImages && config.imageUrl ) {
91 .addClass( 'mw-widget-titleOptionWidget-hasImage mw-no-invert' )
92 .css( 'background-image', 'url(' + config.imageUrl + ')' );
95 if ( config.description ) {
98 .addClass( 'mw-widget-titleOptionWidget-description' )
99 .text( config.description )
100 .attr( 'title', config.description )
107 OO.inheritClass( mw.widgets.TitleOptionWidget, OO.ui.MenuOptionWidget );