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 * Creates a mw.widgets.TitleOptionWidget object.
13 * @extends OO.ui.MenuOptionWidget
16 * @param {Object} config Configuration options
17 * @cfg {string} data Label to display
18 * @cfg {string} url URL of page
19 * @cfg {boolean} [showImages] Whether to attempt to show images
20 * @cfg {string} [imageUrl] Thumbnail image URL with URL encoding
21 * @cfg {string} [description] Page description
22 * @cfg {boolean} [missing] Page doesn't exist
23 * @cfg {boolean} [redirect] Page is a redirect
24 * @cfg {boolean} [disambiguation] Page is a disambiguation page
25 * @cfg {string} [query] Matching query string to highlight
26 * @cfg {string} [compare] String comparison function for query highlighting
28 mw
.widgets
.TitleOptionWidget
= function MwWidgetsTitleOptionWidget( config
) {
31 if ( !config
.showImages
) {
33 } else if ( config
.missing
) {
34 icon
= 'page-not-found';
35 } else if ( config
.redirect
) {
36 icon
= 'page-redirect';
37 } else if ( config
.disambiguation
) {
38 icon
= 'page-disambiguation';
40 icon
= 'page-existing';
43 // Config initialization
52 mw
.widgets
.TitleOptionWidget
.parent
.call( this, config
);
55 this.checkIcon
.$element
.remove();
58 this.$label
.attr( 'href', config
.url
);
59 this.$element
.addClass( 'mw-widget-titleOptionWidget' );
61 // OOUI OptionWidgets make an effort to not be tab accessible, but
62 // adding a link inside them would undo that. So, explicitly make it
64 this.$label
.attr( 'tabindex', '-1' );
66 // Allow opening the link in new tab, but not regular navigation.
67 this.$label
.on( 'click', function ( e
) {
68 // Don't interfere with special clicks (e.g. to open in new tab)
69 if ( !( e
.which
!== 1 || e
.altKey
|| e
.ctrlKey
|| e
.shiftKey
|| e
.metaKey
) ) {
74 // Highlight matching parts of link suggestion
76 this.setHighlightedQuery( config
.data
, config
.query
, config
.compare
);
78 this.$label
.attr( 'title', config
.data
);
80 if ( config
.missing
) {
81 this.$label
.addClass( 'new' );
82 } else if ( config
.redirect
) {
83 this.$label
.addClass( 'mw-redirect' );
84 } else if ( config
.disambiguation
) {
85 this.$label
.addClass( 'mw-disambig' );
88 if ( config
.showImages
&& config
.imageUrl
) {
90 .addClass( 'mw-widget-titleOptionWidget-hasImage' )
91 .css( 'background-image', 'url(' + config
.imageUrl
+ ')' );
94 if ( config
.description
) {
97 .addClass( 'mw-widget-titleOptionWidget-description' )
98 .text( config
.description
)
99 .attr( 'title', config
.description
)
106 OO
.inheritClass( mw
.widgets
.TitleOptionWidget
, OO
.ui
.MenuOptionWidget
);