Merge "phpunit: Don't override --bootstrap if supplied"
[mediawiki.git] / resources / src / mediawiki.special.preferences.ooui / editfont.js
blobfab93c5235a292f8581e1d4beff32d98c33ed769
1 /*!
2  * JavaScript for Special:Preferences: editfont field enhancements.
3  */
4 ( function () {
5         mw.hook( 'htmlform.enhance' ).add( ( $root ) => {
6                 const $target = $root.find( '#mw-input-wpeditfont' );
8                 if (
9                         // This preference could theoretically be disabled ($wgHiddenPrefs)
10                         !$target.length ||
11                         $target.closest( '.mw-htmlform-autoinfuse-lazy' ).length
12                 ) {
13                         return;
14                 }
16                 const widget = OO.ui.infuse( $target );
18                 // Style options
19                 widget.dropdownWidget.menu.items.forEach( ( item ) => {
20                         // The following classes are used here:
21                         // * mw-editfont-monospace
22                         // * mw-editfont-sans-serif
23                         // * mw-editfont-serif
24                         item.$label.addClass( 'mw-editfont-' + item.getData() );
25                 } );
27                 let lastValue;
29                 function updateLabel( value ) {
30                         // Style selected item label
31                         // The following classes are used here:
32                         // * mw-editfont-monospace
33                         // * mw-editfont-sans-serif
34                         // * mw-editfont-serif
35                         widget.dropdownWidget.$label
36                                 .removeClass( 'mw-editfont-' + lastValue )
37                                 .addClass( 'mw-editfont-' + value );
38                         lastValue = value;
39                 }
41                 widget.on( 'change', updateLabel );
42                 updateLabel( widget.getValue() );
44         } );
45 }() );