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 {string} [imageUrl] Thumbnail image URL with URL encoding
20 * @cfg {string} [description] Page description
21 * @cfg {boolean} [missing] Page doesn't exist
22 * @cfg {boolean} [redirect] Page is a redirect
23 * @cfg {boolean} [disambiguation] Page is a disambiguation page
24 * @cfg {string} [query] Matching query string
26 mw
.widgets
.TitleOptionWidget
= function MwWidgetsTitleOptionWidget( config
) {
29 if ( config
.missing
) {
30 icon
= 'page-not-found';
31 } else if ( config
.redirect
) {
32 icon
= 'page-redirect';
33 } else if ( config
.disambiguation
) {
34 icon
= 'page-disambiguation';
36 icon
= 'page-existing';
39 // Config initialization
48 mw
.widgets
.TitleOptionWidget
.parent
.call( this, config
);
51 this.$label
.attr( 'href', config
.url
);
52 this.$element
.addClass( 'mw-widget-titleOptionWidget' );
54 // Allow opening the link in new tab, but not regular navigation.
55 this.$label
.on( 'click', function ( e
) {
56 // Don't interfere with special clicks (e.g. to open in new tab)
57 if ( !( e
.which
!== 1 || e
.altKey
|| e
.ctrlKey
|| e
.shiftKey
|| e
.metaKey
) ) {
62 // Highlight matching parts of link suggestion
63 this.$label
.autoEllipsis( { hasSpan
: false, tooltip
: true, matchText
: config
.query
} );
65 if ( config
.missing
) {
66 this.$label
.addClass( 'new' );
69 if ( config
.imageUrl
) {
71 .addClass( 'mw-widget-titleOptionWidget-hasImage' )
72 .css( 'background-image', 'url(' + config
.imageUrl
+ ')' );
75 if ( config
.description
) {
78 .addClass( 'mw-widget-titleOptionWidget-description' )
79 .text( config
.description
)
80 .attr( 'title', config
.description
)
87 OO
.inheritClass( mw
.widgets
.TitleOptionWidget
, OO
.ui
.MenuOptionWidget
);
89 }( jQuery
, mediaWiki
) );