mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/WikiEditor
synced 2024-11-30 19:15:43 +00:00
dbb6583bbb
The main idea is to make the code shorter and easier to read. One notable change is to use .test() for boolean tests instead of the actual .match() function. Change-Id: Ic43442b75f839906b644d4586c907601f4d5d521
54 lines
1.6 KiB
JavaScript
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 ( !/^[a-z]+:\/\/./.test( config.url ) ) {
|
|
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;
|