2 * JavaScript for Special:Preferences: signature field enhancements.
5 mw
.hook( 'htmlform.enhance' ).add( ( $root
) => {
6 const $signatureInput
= $root
.find( '#mw-input-wpnickname' );
8 // This preference could theoretically be disabled ($wgHiddenPrefs)
9 !$signatureInput
.length
||
10 $signatureInput
.closest( '.mw-htmlform-autoinfuse-lazy' ).length
15 const signatureInput
= OO
.ui
.infuse( $signatureInput
);
17 // Add a visible length limit
18 mw
.widgets
.visibleCodePointLimit( signatureInput
);
20 // Use appropriate font
21 function updateFont( useEditFont
) {
22 // The following classes are used here:
23 // * mw-editfont-monospace
24 // * mw-editfont-sans-serif
25 // * mw-editfont-serif
26 signatureInput
.$element
.toggleClass(
27 'mw-editfont-' + mw
.user
.options
.get( 'editfont' ),
31 const $fancyToggleInput
= $root
.find( '#mw-input-wpfancysig' );
32 if ( $fancyToggleInput
.length
) {
33 const fancyToggleInput
= OO
.ui
.infuse( $fancyToggleInput
);
34 fancyToggleInput
.on( 'change', () => {
35 updateFont( fancyToggleInput
.isSelected() );
37 // !!+ casts '0' to false
38 updateFont( !!+mw
.user
.options
.get( 'fancysig' ) );
41 // Highlight lint errors
42 $root
.find( '[data-mw-lint-error-location]' ).each( function () {
45 location
= $item
.data( 'mw-lint-error-location' ),
46 button
= new OO
.ui
.ButtonWidget( {
47 label
: mw
.msg( 'prefs-signature-highlight-error' )
50 button
.on( 'click', () => {
51 signatureInput
.selectRange( location
[ 0 ], location
[ 1 ] );
54 $item
.append( button
.$element
);