mediawiki-extensions-Visual.../modules/ve-mw/ui/widgets/ve.ui.MWInternalLinkMenuOptionWidget.js
suchetag 6983fbe3d0 Highlight matching parts of link suggestions
Bug: T93697
Change-Id: I1778dc204e45e0b124e3a171b9cce171a3138a58
2015-05-05 10:08:26 +00:00

57 lines
1.7 KiB
JavaScript

/*!
* VisualEditor UserInterface MWInternalLinkMenuOptionWidget class.
*
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* Creates a ve.ui.MWInternalLinkMenuOptionWidget object.
*
* @class
* @extends ve.ui.MWLinkMenuOptionWidget
*
* @constructor
* @param {Object} [config] Configuration options
* @cfg {string} [pagename] Pagename to return the names of internal pages
* @cfg {string} [imageUrl] Thumbnail image URL with URL encoding
* @cfg {string} [description] Page description
*/
ve.ui.MWInternalLinkMenuOptionWidget = function VeUiMWInternalLinkMenuOptionWidget( config ) {
// Config initialization
config = ve.extendObject( { icon: 'page-existing' }, config );
// Properties
this.pagename = config.pagename;
// Parent constructor
ve.ui.MWLinkMenuOptionWidget.call( this, $.extend( { label: this.pagename, href: mw.util.getUrl( this.pagename ), autoFitLabel: false }, config ) );
// Style based on link cache information
ve.init.platform.linkCache.styleElement( this.pagename, this.$link );
// Intialization
this.$element.addClass( 've-ui-mwInternalLinkMenuOptionWidget' );
if ( config.imageUrl ) {
this.$icon
.addClass( 've-ui-mwInternalLinkMenuOptionWidget-hasImage' )
.css( 'background-image', 'url(' + config.imageUrl + ')' );
}
if ( config.description ) {
this.$element.append(
$( '<span>' )
.addClass( 've-ui-mwInternalLinkMenuOptionWidget-description' )
.text( config.description )
);
}
// Highlight matching parts of link suggestion
this.$label.autoEllipsis( { hasSpan: false, tooltip: true, matchText: config.query } );
};
/* Inheritance */
OO.inheritClass( ve.ui.MWInternalLinkMenuOptionWidget, ve.ui.MWLinkMenuOptionWidget );