Merge "SpecialMovepage: Convert form to use OOUI controls"
[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] Label to display
18 * @cfg {mw.Title} [title] Page title object
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
25 */
26 mw.widgets.TitleOptionWidget = function MwWidgetsTitleOptionWidget( config ) {
27 var icon;
28
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';
35 } else {
36 icon = 'page-existing';
37 }
38
39 // Config initialization
40 config = $.extend( {
41 icon: icon,
42 label: config.data,
43 href: config.title.getUrl(),
44 autoFitLabel: false
45 }, config );
46
47 // Parent constructor
48 mw.widgets.TitleOptionWidget.parent.call( this, config );
49
50 // Initialization
51 this.$label.wrap( '<a>' );
52 this.$link = this.$label.parent();
53 this.$link.attr( 'href', config.href );
54 this.$element.addClass( 'mw-widget-titleOptionWidget' );
55
56 // Highlight matching parts of link suggestion
57 this.$label.autoEllipsis( { hasSpan: false, tooltip: true, matchText: config.query } );
58
59 if ( config.missing ) {
60 this.$link.addClass( 'new' );
61 }
62
63 if ( config.imageUrl ) {
64 this.$icon
65 .addClass( 'mw-widget-titleOptionWidget-hasImage' )
66 .css( 'background-image', 'url(' + config.imageUrl + ')' );
67 }
68
69 if ( config.description ) {
70 this.$element.append(
71 $( '<span>' )
72 .addClass( 'mw-widget-titleOptionWidget-description' )
73 .text( config.description )
74 );
75 }
76 };
77
78 /* Setup */
79
80 OO.inheritClass( mw.widgets.TitleOptionWidget, OO.ui.MenuOptionWidget );
81
82 }( jQuery, mediaWiki ) );