2016-05-26 12:08:26 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MWWikitextLinkAnnotationInspector class.
|
|
|
|
*
|
2018-01-03 00:54:47 +00:00
|
|
|
* @copyright 2011-2018 VisualEditor Team and others; see AUTHORS.txt
|
2016-05-26 12:08:26 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inspector for applying and editing labeled MediaWiki internal and external links.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.ui.MWLinkAnnotationInspector
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
|
|
|
ve.ui.MWWikitextLinkAnnotationInspector = function VeUiMWWikitextLinkAnnotationInspector( config ) {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWWikitextLinkAnnotationInspector.super.call( this, config );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWWikitextLinkAnnotationInspector, ve.ui.MWLinkAnnotationInspector );
|
|
|
|
|
|
|
|
/* Static properties */
|
|
|
|
|
2016-12-19 12:03:58 +00:00
|
|
|
ve.ui.MWWikitextLinkAnnotationInspector.static.name = 'wikitextLink';
|
2016-05-26 12:08:26 +00:00
|
|
|
|
|
|
|
ve.ui.MWWikitextLinkAnnotationInspector.static.modelClasses = [];
|
|
|
|
|
2016-11-30 22:17:06 +00:00
|
|
|
ve.ui.MWWikitextLinkAnnotationInspector.static.handlesSource = true;
|
2016-05-26 12:08:26 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWWikitextLinkAnnotationInspector.prototype.getSetupProcess = function ( data ) {
|
2017-07-31 17:19:59 +00:00
|
|
|
// Call grand-parent
|
2016-05-26 12:08:26 +00:00
|
|
|
return ve.ui.FragmentInspector.prototype.getSetupProcess.call( this, data )
|
|
|
|
.next( function () {
|
|
|
|
var fragment = this.getFragment();
|
|
|
|
|
|
|
|
// Initialize range
|
|
|
|
if ( this.previousSelection instanceof ve.dm.LinearSelection ) {
|
|
|
|
if (
|
|
|
|
fragment.getSelection().isCollapsed() &&
|
|
|
|
fragment.getDocument().data.isContentOffset( fragment.getSelection().getRange().start )
|
|
|
|
) {
|
|
|
|
// Expand to nearest word
|
|
|
|
if ( !data.noExpand ) {
|
|
|
|
fragment = fragment.expandLinearSelection( 'word' );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Trim whitespace
|
|
|
|
fragment = fragment.trimLinearSelection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update selection
|
|
|
|
fragment.select();
|
|
|
|
this.initialSelection = fragment.getSelection();
|
|
|
|
|
|
|
|
this.fragment = fragment;
|
|
|
|
|
|
|
|
this.actions.setMode( this.getMode() );
|
|
|
|
|
|
|
|
this.initialAnnotation = this.getAnnotationFromFragment( fragment );
|
2017-07-31 17:19:59 +00:00
|
|
|
this.linkTypeIndex.setTabPanel(
|
|
|
|
this.initialAnnotation instanceof ve.dm.MWExternalLinkAnnotation ? 'external' : 'internal'
|
|
|
|
);
|
2016-05-26 12:08:26 +00:00
|
|
|
this.annotationInput.setAnnotation( this.initialAnnotation );
|
|
|
|
this.updateActions();
|
|
|
|
}, this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWWikitextLinkAnnotationInspector.prototype.getTeardownProcess = function ( data ) {
|
|
|
|
data = data || {};
|
2017-07-31 17:19:59 +00:00
|
|
|
// Call grand-parent
|
2016-05-26 12:08:26 +00:00
|
|
|
return ve.ui.FragmentInspector.prototype.getTeardownProcess.call( this, data )
|
|
|
|
.first( function () {
|
2018-01-10 20:34:04 +00:00
|
|
|
var insertion, insert,
|
2016-08-22 17:59:55 +00:00
|
|
|
annotation = this.getAnnotation(),
|
|
|
|
fragment = this.getFragment(),
|
|
|
|
surfaceModel = fragment.getSurface();
|
2016-05-26 12:08:26 +00:00
|
|
|
|
|
|
|
if ( data && data.action === 'done' && annotation ) {
|
2018-01-10 20:34:04 +00:00
|
|
|
insert = this.initialSelection.isCollapsed() && ( insertion = this.getInsertionData() ).length;
|
|
|
|
if ( insert ) {
|
2016-08-22 17:59:55 +00:00
|
|
|
fragment.insertContent( insertion );
|
|
|
|
}
|
|
|
|
fragment.annotateContent( 'set', annotation );
|
2018-01-10 20:34:04 +00:00
|
|
|
// Fix selection after annotating is complete
|
|
|
|
fragment.getPending().then( function () {
|
|
|
|
if ( insert ) {
|
|
|
|
fragment.collapseToEnd().select();
|
|
|
|
} else {
|
|
|
|
fragment.select();
|
|
|
|
}
|
|
|
|
} );
|
2016-05-26 12:08:26 +00:00
|
|
|
} else if ( !data.action ) {
|
|
|
|
// Restore selection to what it was before we expanded it
|
|
|
|
surfaceModel.setSelection( this.previousSelection );
|
|
|
|
}
|
|
|
|
}, this )
|
|
|
|
.next( function () {
|
|
|
|
// Reset state
|
|
|
|
this.initialSelection = null;
|
|
|
|
this.initialAnnotation = null;
|
2017-07-31 17:19:59 +00:00
|
|
|
|
|
|
|
// Parent resets
|
|
|
|
this.allowProtocolInInternal = false;
|
|
|
|
this.internalAnnotationInput.setAnnotation( null );
|
|
|
|
this.externalAnnotationInput.setAnnotation( null );
|
2016-05-26 12:08:26 +00:00
|
|
|
}, this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.ui.windowFactory.register( ve.ui.MWWikitextLinkAnnotationInspector );
|
|
|
|
|
|
|
|
ve.ui.wikitextCommandRegistry.register(
|
|
|
|
new ve.ui.Command(
|
|
|
|
'link', 'window', 'open',
|
2016-12-19 12:03:58 +00:00
|
|
|
{ args: [ 'wikitextLink' ], supportedSelections: [ 'linear' ] }
|
2016-05-26 12:08:26 +00:00
|
|
|
)
|
|
|
|
);
|