Merge "mediawiki.widgets: Cleanup TitleWidget styles and improve API"
[lhc/web/wiklou.git] / resources / src / mediawiki.widgets / mw.widgets.TitleOptionWidget.js
index 07b81e4..138715a 100644 (file)
@@ -13,8 +13,9 @@
         * @extends OO.ui.MenuOptionWidget
         *
         * @constructor
-        * @param {Object} [config] Configuration options
-        * @cfg {string} [data] Page title
+        * @param {Object} config Configuration options
+        * @cfg {string} data Label to display
+        * @cfg {string} url URL of page
         * @cfg {string} [imageUrl] Thumbnail image URL with URL encoding
         * @cfg {string} [description] Page description
         * @cfg {boolean} [missing] Page doesn't exist
@@ -23,7 +24,7 @@
         * @cfg {string} [query] Matching query string
         */
        mw.widgets.TitleOptionWidget = function MwWidgetsTitleOptionWidget( config ) {
-               var icon, title = config.data;
+               var icon;
 
                if ( config.missing ) {
                        icon = 'page-not-found';
                // Config initialization
                config = $.extend( {
                        icon: icon,
-                       label: title,
-                       href: mw.util.getUrl( title ),
-                       autoFitLabel: false
+                       label: config.data,
+                       autoFitLabel: false,
+                       $label: $( '<a>' )
                }, config );
 
                // Parent constructor
-               OO.ui.MenuOptionWidget.call( this, config );
+               mw.widgets.TitleOptionWidget.parent.call( this, config );
 
-               // Intialization
-               this.$label.wrap( '<a>' );
-               this.$link = this.$label.parent();
-               this.$link.attr( 'href', config.href );
+               // Initialization
+               this.$label.attr( 'href', config.url );
                this.$element.addClass( 'mw-widget-titleOptionWidget' );
 
                // Highlight matching parts of link suggestion
                this.$label.autoEllipsis( { hasSpan: false, tooltip: true, matchText: config.query } );
 
                if ( config.missing ) {
-                       this.$link.addClass( 'new' );
+                       this.$label.addClass( 'new' );
                }
 
                if ( config.imageUrl ) {
@@ -74,7 +73,7 @@
                }
        };
 
-       /* Inheritance */
+       /* Setup */
 
        OO.inheritClass( mw.widgets.TitleOptionWidget, OO.ui.MenuOptionWidget );