MWLinkAnnotationInspector: Use TitleSearchWidget instead of TitleInputWidget

Depends on I335bd912d in MediaWiki core.

Bug: T101169
Change-Id: I2932c9df5444d1363af5af9b438bb905ed298148
This commit is contained in:
Ed Sanders 2015-09-25 21:29:10 +01:00
parent a04d2ff52b
commit f814ea719b
4 changed files with 50 additions and 25 deletions

View file

@ -22,7 +22,7 @@
"license-name": "MIT",
"type": "other",
"requires": {
"MediaWiki": ">= 1.26.0"
"MediaWiki": ">= 1.27.0"
},
"callback": "VisualEditorHooks::onRegistration",
"config": {

View file

@ -46,14 +46,9 @@ ve.ui.MWLinkAnnotationInspector.static.actions = ve.ui.MWLinkAnnotationInspector
* @inheritdoc
*/
ve.ui.MWLinkAnnotationInspector.prototype.initialize = function () {
var overlay = this.manager.getOverlay();
// Properties
this.allowProtocolInInternal = false;
this.internalAnnotationInput = new ve.ui.MWInternalLinkAnnotationWidget( {
// Sub-classes may want to know where to position overlays
$overlay: overlay ? overlay.$element : this.$frame
} );
this.internalAnnotationInput = new ve.ui.MWInternalLinkAnnotationWidget();
this.externalAnnotationInput = new ve.ui.MWExternalLinkAnnotationWidget();
this.linkTypeSelect = new OO.ui.TabSelectWidget( {
@ -77,6 +72,12 @@ ve.ui.MWLinkAnnotationInspector.prototype.initialize = function () {
this.internalAnnotationInput.connect( this, { change: 'onInternalLinkChange' } );
this.externalAnnotationInput.connect( this, { change: 'onExternalLinkChange' } );
this.internalAnnotationInput.input.results.connect( this, {
add: 'onInternalLinkChangeResultsChange'
// Listening to remove causes a flicker, and is not required
// as 'add' is always trigger on a change too
} );
// Parent method
ve.ui.MWLinkAnnotationInspector.super.prototype.initialize.call( this );
@ -128,6 +129,16 @@ ve.ui.MWLinkAnnotationInspector.prototype.onInternalLinkChange = function ( anno
this.updateActions();
};
/**
* Handle list change events ('add') from the interal link's result widget
*
* @param {OO.ui.OptionWidget[]} items Added items
* @param {number} index Index of insertion point
*/
ve.ui.MWLinkAnnotationInspector.prototype.onInternalLinkChangeResultsChange = function () {
this.updateSize();
};
/**
* Handle change events on the external link widget
*
@ -189,16 +200,6 @@ ve.ui.MWLinkAnnotationInspector.prototype.getSetupProcess = function ( data ) {
}, this );
};
/**
* @inheritdoc
*/
ve.ui.MWLinkAnnotationInspector.prototype.getReadyProcess = function ( data ) {
return ve.ui.MWLinkAnnotationInspector.super.prototype.getReadyProcess.call( this, data )
.next( function () {
this.internalAnnotationInput.getTextInputWidget().populateLookupMenu();
}, this );
};
/**
* @inheritdoc
*/
@ -263,6 +264,8 @@ ve.ui.MWLinkAnnotationInspector.prototype.onLinkTypeSelectSelect = function () {
this.annotationInput = this.createAnnotationInput();
this.form.$element.append( this.annotationInput.$element );
this.updateSize();
// If the user manually switches to internal links with an external link in the input, remember this
if ( !isExternal && inputHasProtocol ) {
this.allowProtocolInInternal = true;
@ -272,10 +275,6 @@ ve.ui.MWLinkAnnotationInspector.prototype.onLinkTypeSelectSelect = function () {
// Firefox moves the cursor to the beginning
this.annotationInput.getTextInputWidget().$input[ 0 ].setSelectionRange( end, end );
if ( !isExternal ) {
this.annotationInput.getTextInputWidget().populateLookupMenu();
}
this.updateActions();
};

View file

@ -7,4 +7,24 @@
.ve-ui-mwLinkAnnotationInspector-linkTypeSelect {
margin: -0.75em -0.75em 0.75em -0.75em;
}
}
.ve-ui-linkAnnotationWidget .mw-widget-titleSearchWidget {
position: relative;
}
.ve-ui-linkAnnotationWidget .mw-widget-titleSearchWidget .oo-ui-searchWidget-query {
padding: 0;
height: auto;
border: 0;
}
.ve-ui-linkAnnotationWidget .mw-widget-titleSearchWidget .oo-ui-searchWidget-query .oo-ui-textInputWidget {
margin: 0;
}
.ve-ui-linkAnnotationWidget .mw-widget-titleSearchWidget .oo-ui-searchWidget-results {
position: relative;
top: 0;
padding: 3em 0 0 0;
}

View file

@ -53,13 +53,19 @@ ve.ui.MWInternalLinkAnnotationWidget.static.getTextFromAnnotation = function ( a
* @return {OO.ui.TextInputWidget} Text input widget
*/
ve.ui.MWInternalLinkAnnotationWidget.prototype.createInputWidget = function ( config ) {
return new mw.widgets.TitleInputWidget( {
$overlay: config.$overlay,
return new mw.widgets.TitleSearchWidget( ve.extendObject( {
icon: 'search',
showImages: mw.config.get( 'wgVisualEditor' ).usePageImages,
showDescriptions: mw.config.get( 'wgVisualEditor' ).usePageDescriptions,
cache: ve.init.platform.linkCache
} );
}, config ) );
};
/**
* @inheritdoc
*/
ve.ui.MWInternalLinkAnnotationWidget.prototype.getTextInputWidget = function () {
return this.input.query;
};
/**