diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:32:59 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-05-01 15:32:59 -0400 |
commit | 6dc1997577fab2c366781fd7048144935afa0012 (patch) | |
tree | 8918d28c7ab4342f0738985e37af1dfc42d0e93a /resources/src/mediawiki.widgets/mw.widgets.TitleOptionWidget.js | |
parent | 150f94f051128f367bc89f6b7e5f57eb2a69fc62 (diff) | |
parent | fa89acd685cb09cdbe1c64cbb721ec64975bbbc1 (diff) |
Merge commit 'fa89acd'
# Conflicts:
# .gitignore
# extensions/ArchInterWiki.sql
Diffstat (limited to 'resources/src/mediawiki.widgets/mw.widgets.TitleOptionWidget.js')
-rw-r--r-- | resources/src/mediawiki.widgets/mw.widgets.TitleOptionWidget.js | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/resources/src/mediawiki.widgets/mw.widgets.TitleOptionWidget.js b/resources/src/mediawiki.widgets/mw.widgets.TitleOptionWidget.js new file mode 100644 index 00000000..ec0c9357 --- /dev/null +++ b/resources/src/mediawiki.widgets/mw.widgets.TitleOptionWidget.js @@ -0,0 +1,82 @@ +/*! + * MediaWiki Widgets - TitleOptionWidget class. + * + * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt + * @license The MIT License (MIT); see LICENSE.txt + */ +( function ( $, mw ) { + + /** + * Creates a mw.widgets.TitleOptionWidget object. + * + * @class + * @extends OO.ui.MenuOptionWidget + * + * @constructor + * @param {Object} [config] Configuration options + * @cfg {string} [data] Label to display + * @cfg {mw.Title} [title] Page title object + * @cfg {string} [imageUrl] Thumbnail image URL with URL encoding + * @cfg {string} [description] Page description + * @cfg {boolean} [missing] Page doesn't exist + * @cfg {boolean} [redirect] Page is a redirect + * @cfg {boolean} [disambiguation] Page is a disambiguation page + * @cfg {string} [query] Matching query string + */ + mw.widgets.TitleOptionWidget = function MwWidgetsTitleOptionWidget( config ) { + var icon; + + if ( config.missing ) { + icon = 'page-not-found'; + } else if ( config.redirect ) { + icon = 'page-redirect'; + } else if ( config.disambiguation ) { + icon = 'page-disambiguation'; + } else { + icon = 'page-existing'; + } + + // Config initialization + config = $.extend( { + icon: icon, + label: config.data, + href: config.title.getUrl(), + autoFitLabel: false + }, config ); + + // Parent constructor + mw.widgets.TitleOptionWidget.parent.call( this, config ); + + // Initialization + this.$label.wrap( '<a>' ); + this.$link = this.$label.parent(); + this.$link.attr( 'href', config.href ); + 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' ); + } + + if ( config.imageUrl ) { + this.$icon + .addClass( 'mw-widget-titleOptionWidget-hasImage' ) + .css( 'background-image', 'url(' + config.imageUrl + ')' ); + } + + if ( config.description ) { + this.$element.append( + $( '<span>' ) + .addClass( 'mw-widget-titleOptionWidget-description' ) + .text( config.description ) + ); + } + }; + + /* Setup */ + + OO.inheritClass( mw.widgets.TitleOptionWidget, OO.ui.MenuOptionWidget ); + +}( jQuery, mediaWiki ) ); |