Merge "mw.loader: Omit private modules from the request queue"
[lhc/web/wiklou.git] / resources / src / mediawiki.widgets / mw.widgets.TitleOptionWidget.js
1 /*!
2 * MediaWiki Widgets - TitleOptionWidget class.
3 *
4 * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7 ( function ( $, mw ) {
8
9 /**
10 * Creates a mw.widgets.TitleOptionWidget object.
11 *
12 * @class
13 * @extends OO.ui.MenuOptionWidget
14 *
15 * @constructor
16 * @param {Object} [config] Configuration options
17 * @cfg {string} [data] Page title
18 * @cfg {string} [imageUrl] Thumbnail image URL with URL encoding
19 * @cfg {string} [description] Page description
20 * @cfg {boolean} [missing] Page doesn't exist
21 * @cfg {boolean} [redirect] Page is a redirect
22 * @cfg {boolean} [disambiguation] Page is a disambiguation page
23 * @cfg {string} [query] Matching query string
24 */
25 mw.widgets.TitleOptionWidget = function MwWidgetsTitleOptionWidget( config ) {
26 var icon, title = config.data;
27
28 if ( config.missing ) {
29 icon = 'page-not-found';
30 } else if ( config.redirect ) {
31 icon = 'page-redirect';
32 } else if ( config.disambiguation ) {
33 icon = 'page-disambiguation';
34 } else {
35 icon = 'page-existing';
36 }
37
38 // Config initialization
39 config = $.extend( {
40 icon: icon,
41 label: title,
42 href: mw.util.getUrl( title ),
43 autoFitLabel: false
44 }, config );
45
46 // Parent constructor
47 OO.ui.MenuOptionWidget.call( this, config );
48
49 // Intialization
50 this.$label.wrap( '<a>' );
51 this.$link = this.$label.parent();
52 this.$link.attr( 'href', config.href );
53 this.$element.addClass( 'mw-widget-titleOptionWidget' );
54
55 // Highlight matching parts of link suggestion
56 this.$label.autoEllipsis( { hasSpan: false, tooltip: true, matchText: config.query } );
57
58 if ( config.missing ) {
59 this.$link.addClass( 'new' );
60 }
61
62 if ( config.imageUrl ) {
63 this.$icon
64 .addClass( 'mw-widget-titleOptionWidget-hasImage' )
65 .css( 'background-image', 'url(' + config.imageUrl + ')' );
66 }
67
68 if ( config.description ) {
69 this.$element.append(
70 $( '<span>' )
71 .addClass( 'mw-widget-titleOptionWidget-description' )
72 .text( config.description )
73 );
74 }
75 };
76
77 /* Inheritance */
78
79 OO.inheritClass( mw.widgets.TitleOptionWidget, OO.ui.MenuOptionWidget );
80
81 }( jQuery, mediaWiki ) );