Debian Codegraph @

extensions/WikiEditor/modules/insertlink/LinkTextField.js

raw symbols SCIP
1 /**
2 * @class
3 * @extends OO.ui.FieldLayout
4 * @constructor
5 */
6 function LinkTextField() {
7 var input = new OO.ui.TextInputWidget( {
8 placeholder: mw.msg( 'wikieditor-toolbar-tool-link-int-text-tooltip' )
9 } );
10
11 input.connect( this, {
12 change: 'onInputChange'
13 } );
14
15 var config = {
16 align: 'top',
17 label: mw.msg( 'wikieditor-toolbar-tool-link-int-text' ),
18 classes: [ 'mw-wikiEditor-InsertLink-LinkTextField' ]
19 };
20 LinkTextField.super.call( this, input, config );
21
22 // Whether the user has changed the value
23 // (as opposed to the value being changed automatically
24 // because the link target field changed).
25 this.touched = false;
26 }
27
28 OO.inheritClass( LinkTextField, OO.ui.FieldLayout );
29
30 /**
31 * Set the input's value.
32 *
33 * @param {string} val The new value.
34 */
35 LinkTextField.prototype.setValueIfUntouched = function ( val ) {
36 if ( !this.touched ) {
37 this.getField().setValue( val );
38 }
39 };
40
41 /**
42 * @param {boolean} touched
43 */
44 LinkTextField.prototype.setTouched = function ( touched ) {
45 this.touched = touched;
46 };
47
48 /**
49 * If this input is active when it's being changed,
50 * set it as 'touched' so it won't change again if the title-lookup is changed.
51 */
52 LinkTextField.prototype.onInputChange = function () {
53 if ( $.contains( this.$element[ 0 ], document.activeElement ) ) {
54 this.touched = true;
55 }
56 };
57
58 module.exports = LinkTextField;