| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
const colonSeparator = require( './contentMessages.json' ).colonSeparator; |
| 8 |
|
| 9 |
mw.hook( 'htmlform.enhance' ).add( ( $root ) => { |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
$root |
| 14 |
.find( '.mw-htmlform-select-and-other-field' ) |
| 15 |
.each( function () { |
| 16 |
const $this = $( this ), |
| 17 |
$widget = $this.closest( '.oo-ui-widget[data-ooui]' ); |
| 18 |
|
| 19 |
const $reasonList = $root.find( '#' + $this.data( 'id-select' ) ); |
| 20 |
|
| 21 |
if ( $widget.length ) { |
| 22 |
mw.loader.using( 'mediawiki.widgets.SelectWithInputWidget', () => { |
| 23 |
const widget = OO.ui.Widget.static.infuse( $widget ); |
| 24 |
const maxlengthUnit = widget.getData().maxlengthUnit; |
| 25 |
const lengthLimiter = maxlengthUnit === 'codepoints' ? |
| 26 |
'visibleCodePointLimitWithDropdown' : 'visibleByteLimitWithDropdown'; |
| 27 |
mw.widgets[ lengthLimiter ]( widget.textinput, widget.dropdowninput ); |
| 28 |
} ); |
| 29 |
} else { |
| 30 |
|
| 31 |
let currentValReasonList = $reasonList.val(); |
| 32 |
|
| 33 |
$reasonList.on( 'change', () => { |
| 34 |
currentValReasonList = $reasonList.val(); |
| 35 |
} ); |
| 36 |
|
| 37 |
|
| 38 |
const maxlengthUnit = $this.data( 'mw-maxlength-unit' ); |
| 39 |
const lengthLimiter = maxlengthUnit === 'codepoints' ? 'codePointLimit' : 'byteLimit'; |
| 40 |
$this[ lengthLimiter ]( ( input ) => { |
| 41 |
|
| 42 |
let comment = currentValReasonList; |
| 43 |
if ( comment === 'other' ) { |
| 44 |
comment = input; |
| 45 |
} else if ( input !== '' ) { |
| 46 |
|
| 47 |
comment += colonSeparator + input; |
| 48 |
} |
| 49 |
return comment; |
| 50 |
} ); |
| 51 |
} |
| 52 |
} ); |
| 53 |
} ); |