summaryrefslogtreecommitdiff
path: root/www/wiki/resources/src/mediawiki/htmlform/autoinfuse.js
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/resources/src/mediawiki/htmlform/autoinfuse.js')
-rw-r--r--www/wiki/resources/src/mediawiki/htmlform/autoinfuse.js32
1 files changed, 32 insertions, 0 deletions
diff --git a/www/wiki/resources/src/mediawiki/htmlform/autoinfuse.js b/www/wiki/resources/src/mediawiki/htmlform/autoinfuse.js
new file mode 100644
index 00000000..c39e43aa
--- /dev/null
+++ b/www/wiki/resources/src/mediawiki/htmlform/autoinfuse.js
@@ -0,0 +1,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 ) );