Merge "jquery.tablesorter: Silence an expected "sort-rowspan-error" warning"
[mediawiki.git] / resources / src / mediawiki.special.preferences.ooui / signature.js
blob777e17a4b42e9c4922c893d77a8d6c74767f12c5
1 /*!
2 * JavaScript for Special:Preferences: signature field enhancements.
3 */
4 ( function () {
5 mw.hook( 'htmlform.enhance' ).add( ( $root ) => {
6 const $signatureInput = $root.find( '#mw-input-wpnickname' );
7 if (
8 // This preference could theoretically be disabled ($wgHiddenPrefs)
9 !$signatureInput.length ||
10 $signatureInput.closest( '.mw-htmlform-autoinfuse-lazy' ).length
11 ) {
12 return;
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' ),
28 useEditFont
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() );
36 } );
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 () {
43 const
44 $item = $( this ),
45 location = $item.data( 'mw-lint-error-location' ),
46 button = new OO.ui.ButtonWidget( {
47 label: mw.msg( 'prefs-signature-highlight-error' )
48 } );
50 button.on( 'click', () => {
51 signatureInput.selectRange( location[ 0 ], location[ 1 ] );
52 } );
54 $item.append( button.$element );
55 } );
57 } );
58 }() );