mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/WikiEditor
synced 2024-12-02 20:06:49 +00:00
e3e9ebb6cb
Following-up on I9fb7e66bf925eb9a8260d6245d2a7db54a7a2fec this converts the link-text field to OOUI. Bug: T289214 Change-Id: I17f34a8cbf72b80f3916581867e5828d9b129789
59 lines
1.3 KiB
JavaScript
59 lines
1.3 KiB
JavaScript
/**
|
|
* @class
|
|
* @extends OO.ui.FieldLayout
|
|
* @constructor
|
|
*/
|
|
function LinkTextField() {
|
|
var input = new OO.ui.TextInputWidget( {
|
|
placeholder: mw.msg( 'wikieditor-toolbar-tool-link-int-text-tooltip' )
|
|
} );
|
|
|
|
input.connect( this, {
|
|
change: 'onInputChange'
|
|
} );
|
|
|
|
var config = {
|
|
align: 'top',
|
|
label: mw.msg( 'wikieditor-toolbar-tool-link-int-text' ),
|
|
classes: [ 'ext-WikiEditor-InsertLink-LinkTextField' ]
|
|
};
|
|
LinkTextField.super.call( this, input, config );
|
|
|
|
// Whether the user has changed the value
|
|
// (as opposed to the value being changed automatically
|
|
// because the link target field changed).
|
|
this.touched = false;
|
|
}
|
|
|
|
OO.inheritClass( LinkTextField, OO.ui.FieldLayout );
|
|
|
|
/**
|
|
* Set the input's value.
|
|
*
|
|
* @param {string} val The new value.
|
|
*/
|
|
LinkTextField.prototype.setValueIfUntouched = function ( val ) {
|
|
if ( !this.touched ) {
|
|
this.getField().setValue( val );
|
|
}
|
|
};
|
|
|
|
/**
|
|
* @param {boolean} touched
|
|
*/
|
|
LinkTextField.prototype.setTouched = function ( touched ) {
|
|
this.touched = touched;
|
|
};
|
|
|
|
/**
|
|
* If this input is active when it's being changed,
|
|
* set it as 'touched' so it won't change again if the title-lookup is changed.
|
|
*/
|
|
LinkTextField.prototype.onInputChange = function () {
|
|
if ( $.contains( this.$element[ 0 ], document.activeElement ) ) {
|
|
this.touched = true;
|
|
}
|
|
};
|
|
|
|
module.exports = LinkTextField;
|