summaryrefslogtreecommitdiff
path: root/www/wiki/resources/src/mediawiki/htmlform/autoinfuse.js
blob: c39e43aaa8a499cba9a7a8591a2438c57a18f476 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
 * HTMLForm enhancements:
 * Infuse some OOUI HTMLForm fields (those which benefit from always being infused).
 */
( function ( mw, $ ) {

	mw.hook( 'htmlform.enhance' ).add( function ( $root ) {
		var $oouiNodes, modules, extraModules;

		$oouiNodes = $root.find( '.mw-htmlform-field-autoinfuse' );
		if ( $oouiNodes.length ) {
			// The modules are preloaded (added server-side in HTMLFormField, and the individual fields
			// which need extra ones), but this module doesn't depend on them. Wait until they're loaded.
			modules = [ 'mediawiki.htmlform.ooui' ];
			$oouiNodes.each( function () {
				var data = $( this ).data( 'mw-modules' );
				if ( data ) {
					// We can trust this value, 'data-mw-*' attributes are banned from user content in Sanitizer
					extraModules = data.split( ',' );
					modules.push.apply( modules, extraModules );
				}
			} );
			mw.loader.using( modules ).done( function () {
				$oouiNodes.each( function () {
					OO.ui.infuse( this );
				} );
			} );
		}

	} );

}( mediaWiki, jQuery ) );