mediawiki-extensions-Visual.../modules/ve-mw/ui/widgets/ve.ui.MWInternalLinkAnnotationWidget.js
Ed Sanders e9384ad9ac Update VE core submodule to master (83d45d1)
New changes:
9d162ce Restore the selection to a sensible place when closing FindAndReplace
57229ac Only apply annotations if 'done' is clicked
bfb17ee Always show cancel button on annotation inspectors
91672cf Disable 'done'/'insert' button when input invalid
aef9cbd Only create annotations from text input if it is valid
a384b96 [BREAKING CHANGE] Make getTextFromAnnotation/getAnnotationFromText static
fa09ab7 Scroll table selection into view when it changes

Local changes:
Make getTextFromAnnotation/getAnnotationFromText static

Change-Id: Id3c2a1efb1f327fa6d5b93d57d90bb5bb8ee88f8
2015-06-02 00:47:13 +00:00

83 lines
2.1 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 ve.ui.MWLinkTargetInputWidget( {
icon: 'search',
$overlay: config.$overlay
} );
};