2015-05-03 21:21:00 +00:00
|
|
|
/*!
|
|
|
|
* 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 );
|
|
|
|
|
2015-05-29 12:08:05 +00:00
|
|
|
/* Static Methods */
|
2015-05-03 21:21:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2015-05-29 12:08:05 +00:00
|
|
|
ve.ui.MWInternalLinkAnnotationWidget.static.getAnnotationFromText = function ( value ) {
|
2015-05-03 21:21:00 +00:00
|
|
|
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
|
|
|
|
*/
|
2015-05-29 12:08:05 +00:00
|
|
|
ve.ui.MWInternalLinkAnnotationWidget.static.getTextFromAnnotation = function ( annotation ) {
|
2015-05-03 21:21:00 +00:00
|
|
|
return annotation ? annotation.getAttribute( 'title' ) : '';
|
|
|
|
};
|
2015-05-29 12:08:05 +00:00
|
|
|
|
|
|
|
/* 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 ve.ui.MWLinkTargetInputWidget( {
|
|
|
|
icon: 'search',
|
|
|
|
$overlay: config.$overlay
|
|
|
|
} );
|
|
|
|
};
|