X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/vendor/oojs/oojs-ui/demos/infusion.js diff --git a/vendor/oojs/oojs-ui/demos/infusion.js b/vendor/oojs/oojs-ui/demos/infusion.js new file mode 100644 index 00000000..dcf8c122 --- /dev/null +++ b/vendor/oojs/oojs-ui/demos/infusion.js @@ -0,0 +1,33 @@ +// Demonstrate JavaScript 'infusion' of PHP-generated widgets. +// Used by widgets.php. + +var infuseButton; + +// Helper function to get high resolution profiling data, where available. +function now() { + return ( window.performance && performance.now ) ? performance.now() : + Date.now ? Date.now() : new Date().getTime(); +} + +// Add a button to infuse everything! +// (You wouldn't typically do this: you'd only infuse those objects which you needed to attach +// client-side behaviors to, or where the JS implementation provides additional features over PHP, +// like DropdownInputWidget. We do it here because it's a good overall test.) +function infuseAll() { + var start, end; + start = now(); + $( '*[data-ooui]' ).map( function ( _, e ) { + return OO.ui.infuse( e.id ); + } ); + end = now(); + window.console.log( 'Took ' + ( end - start ) + ' ms to infuse demo page.' ); + infuseButton.setDisabled( true ); +} + +// More typical usage: we take the existing server-side +// button group and do things to it, here adding a new button. +infuseButton = new OO.ui.ButtonWidget( { label: 'Infuse' } ) + .on( 'click', infuseAll ); + +OO.ui.ButtonGroupWidget.static.infuse( 'demo-menu-infuse' ) + .addItems( [ infuseButton ] );