Merge "Add part to update ctd_user_defined in populateChangeTagDef"
[lhc/web/wiklou.git] / resources / src / mediawiki.htmlform / autoinfuse.js
1 /*
2 * HTMLForm enhancements:
3 * Infuse some OOUI HTMLForm fields (those which benefit from always being infused).
4 */
5 ( function ( mw, $ ) {
6
7 mw.hook( 'htmlform.enhance' ).add( function ( $root ) {
8 var $oouiNodes, modules, extraModules;
9
10 $oouiNodes = $root.find( '.mw-htmlform-field-autoinfuse' );
11
12 $oouiNodes = $oouiNodes.filter( function () {
13 return !$( this ).closest( '.mw-htmlform-autoinfuse-lazy' ).length;
14 } );
15
16 if ( $oouiNodes.length ) {
17 // The modules are preloaded (added server-side in HTMLFormField, and the individual fields
18 // which need extra ones), but this module doesn't depend on them. Wait until they're loaded.
19 modules = [ 'mediawiki.htmlform.ooui' ];
20 $oouiNodes.each( function () {
21 var data = $( this ).data( 'mw-modules' );
22 if ( data ) {
23 // We can trust this value, 'data-mw-*' attributes are banned from user content in Sanitizer
24 extraModules = data.split( ',' );
25 modules.push.apply( modules, extraModules );
26 }
27 } );
28 mw.loader.using( modules ).done( function () {
29 $oouiNodes.each( function () {
30 OO.ui.infuse( this );
31 } );
32 } );
33 }
34
35 } );
36
37 }( mediaWiki, jQuery ) );