mediawiki-extensions-WikiEd.../modules/insertlink/TitleOptionWidget.js
Ed Sanders 7fea791042 build: Update eslint-config-wikimedia to 0.21.0
Change-Id: I87bca80d107c965296af74e16961cd855d72b806
2022-02-07 17:27:27 +00:00

54 lines
1.6 KiB
JavaScript

/**
* A custom TitleOptionWidget that knows about external links.
*
* @class
* @extends mw.widgets.TitleOptionWidget
* @constructor
* @param {Object} config Configuration options.
* @cfg {boolean} [external] Page title is an external link.
*/
function InsertLinkTitleOptionWidget( config ) {
this.external = config.external || false;
if ( this.external ) {
config.icon = 'linkExternal';
config.description = mw.msg( 'wikieditor-toolbar-tool-link-int-target-status-external' );
// Lowercase the first character; it was uppercased by the API.
config.url = config.data.slice( 0, 1 ).toLowerCase() + config.data.slice( 1 );
config.data = config.url;
// Prepend http:// if there is no protocol (i.e. if it starts with "www.").
// @TODO This is repeated when the link is inserted (in jquery.wikiEditor.dialogs.config.js).
if ( !config.url.match( /^[a-z]+:\/\/./ ) ) {
config.url = 'http://' + config.url;
}
config.missing = false;
}
this.disambiguation = config.disambiguation || false;
this.missing = config.missing || false;
InsertLinkTitleOptionWidget.super.call( this, config );
}
OO.inheritClass( InsertLinkTitleOptionWidget, mw.widgets.TitleOptionWidget );
/**
* @return {boolean}
*/
InsertLinkTitleOptionWidget.prototype.isExternal = function () {
return this.external;
};
/**
* @return {boolean}
*/
InsertLinkTitleOptionWidget.prototype.isMissing = function () {
return this.missing;
};
/**
* @return {boolean}
*/
InsertLinkTitleOptionWidget.prototype.isDisambiguation = function () {
return this.disambiguation;
};
module.exports = InsertLinkTitleOptionWidget;