mediawiki-extensions-Visual.../modules/ve-mw/ui/widgets/ve.ui.MWInternalLinkAnnotationWidget.js
Ed Sanders 52cb066dc7 Use new MediaWiki core TitleInputWidget
All link input/title input functionality has been moved to core, so
we can replace the link widget, redirect widget and template search
widget with it.

Depends on Ib463e60cad96 in MediaWiki core.

Change-Id: I452f3b86ead403307072cf904f0553c9771f4300
2015-06-24 17:06:00 -07:00

86 lines
2.2 KiB
JavaScript

/*!
* VisualEditor UserInterface MWInternalLinkAnnotationWidget class.
*
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* Creates an ve.ui.MWInternalLinkAnnotationWidget object.
*
* @class
* @extends ve.ui.LinkAnnotationWidget
*
* @constructor
* @param {Object} [config] Configuration options
*/
ve.ui.MWInternalLinkAnnotationWidget = function VeUiMWInternalLinkAnnotationWidget() {
// Parent constructor
ve.ui.MWInternalLinkAnnotationWidget.super.apply( this, arguments );
};
/* Inheritance */
OO.inheritClass( ve.ui.MWInternalLinkAnnotationWidget, ve.ui.LinkAnnotationWidget );
/* Static Methods */
/**
* @inheritdoc
*/
ve.ui.MWInternalLinkAnnotationWidget.static.getAnnotationFromText = function ( value ) {
var title,
target = value.trim();
// Keep annotation in sync with value
if ( target === '' ) {
return null;
} else {
title = mw.Title.newFromText( target );
if (
title &&
( title.getNamespaceId() === 6 || title.getNamespaceId() === 14 ) &&
target[0] !== ':'
) {
// Prepend links to File and Category namespace with a colon
target = ':' + target;
}
return new ve.dm.MWInternalLinkAnnotation( {
type: 'link/mwInternal',
attributes: {
title: target,
// bug 62816: we really need a builder for this stuff
normalizedTitle: ve.dm.MWInternalLinkAnnotation.static.normalizeTitle( target ),
lookupTitle: ve.dm.MWInternalLinkAnnotation.static.getLookupTitle( target )
}
} );
}
};
/**
* @inheritdoc
*/
ve.ui.MWInternalLinkAnnotationWidget.static.getTextFromAnnotation = function ( annotation ) {
return annotation ? annotation.getAttribute( 'title' ) : '';
};
/* Methods */
/**
* Create a text input widget to be used by the annotation widget
*
* @param {Object} [config] Configuration options
* @return {OO.ui.TextInputWidget} Text input widget
*/
ve.ui.MWInternalLinkAnnotationWidget.prototype.createInputWidget = function ( config ) {
return new mw.widgets.TitleInputWidget( {
$overlay: config.$overlay,
icon: 'search',
showImages: mw.config.get( 'wgVisualEditor' ).usePageImages,
showDescriptions: mw.config.get( 'wgVisualEditor' ).usePageDescriptions,
cache: ve.init.platform.linkCache
} );
};