Load lazyload modules with skin modules if needed

This commit is contained in:
alistair3149 2020-06-15 22:41:46 -04:00
parent 105bcd52ed
commit 3736489118
3 changed files with 5 additions and 24 deletions

View file

@ -35,27 +35,6 @@ use ThumbnailImage;
* on<HookName>()
*/
class CitizenHooks {
/**
* @param OutputPage $out
* @param Skin $skin
* @return bool
*/
public static function onBeforePageDisplay( $out, $skin ) {
try {
$config = MediaWikiServices::getInstance()->getConfigFactory()->makeConfig( 'Citizen' );
$lazyloadEnabled = $config->get( 'CitizenEnableLazyload' );
} catch ( Exception $e ) {
return false;
}
if ( $lazyloadEnabled === true ) {
$out->addModules( 'skins.citizen.styles.lazyload' );
$out->addModules( 'skins.citizen.scripts.lazyload' );
}
return true;
}
/**
* ResourceLoaderGetConfigVars hook handler for setting a config variable
* @see https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderGetConfigVars

View file

@ -250,6 +250,11 @@ class SkinCitizen extends SkinTemplate {
'skins.citizen.icons.badges',
] );
// Add lazyload-related modules
if ( $this->getConfigValue( 'CitizenEnableLazyload' ) === true ) {
$this->out->addModuleStyles( [ 'skins.citizen.styles.lazyload' ] );
$this->out->addModules( [ 'skins.citizen.scripts.lazyload' ] );
}
$this->out->addModules( [
'skins.citizen.scripts',
] );

View file

@ -529,9 +529,6 @@
}
},
"Hooks": {
"BeforePageDisplay": [
"Citizen\\CitizenHooks::onBeforePageDisplay"
],
"ResourceLoaderGetConfigVars": [
"Citizen\\CitizenHooks::onResourceLoaderGetConfigVars"
],