ProfessionalWiki / Bootstrap

Provides the Bootstrap 4 web front-end framework to MediaWiki skins and extensions
https://www.mediawiki.org/wiki/Extension:Bootstrap
Other
14 stars 13 forks source link

Initial changes for 5.x #69

Closed malberts closed 4 months ago

malberts commented 1 year ago

Current state:

malberts commented 1 year ago

Requires more work, but JS is now loadable with this snippet in LocalSettings.php:

$wgHooks['SetupAfterCache'][] = function(){
    \Bootstrap\BootstrapManager::getInstance()->addAllBootstrapModules();
    $GLOBALS[ 'wgResourceModules' ]['ext.bootstrap.scripts']['packageFiles'][] = [
        'name' => 'components.js',
        'content' => '
            require("./alert.js");
            require("./button.js");
            require("./carousel.js");
            require("./collapse.js");
            require("./dropdown.js");
            require("./modal.js");
            require("./offcanvas.js");
            require("./popover.js");
            require("./scrollspy.js");
            require("./tab.js");
            require("./toast.js");
            require("./tooltip.js");
        ',
        'main' => true
    ];
    return true;
};

$wgHooks['BeforePageDisplay'][]=function( OutputPage $out, Skin $skin ){
    $out->addModuleStyles( [ 'ext.bootstrap.styles' ] );
    $out->addModules( [ 'ext.bootstrap.scripts' ] );
    return true;
};

The additional require()s are necessary because ResourceLoader non-main packageFiles are available but not loaded, meaning no BS code is run automatically.

This is different when using bootstrap.bundle.js as the main packageFile. All the code is included in one file and this is run once loaded.