diff --git a/includes/CitizenHooks.php b/includes/CitizenHooks.php index ead01540..4e0e8c68 100644 --- a/includes/CitizenHooks.php +++ b/includes/CitizenHooks.php @@ -1,8 +1,10 @@ () */ 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 diff --git a/includes/CitizenTemplate.php b/includes/CitizenTemplate.php index c6373e19..39536d37 100644 --- a/includes/CitizenTemplate.php +++ b/includes/CitizenTemplate.php @@ -1,4 +1,25 @@ getOutput(); // Replace the search module if ( $this->getConfigValue( 'CitizenEnableSearch' ) === true ) { @@ -221,17 +242,25 @@ class SkinCitizen extends SkinTemplate { ]; } + if ( $out->isTOCEnabled() ) { + // Disable style condition loading due to pop in + // $modules['content'][] = 'skins.citizen.styles.toc'; + $modules['content'][] = 'skins.citizen.scripts.toc'; + } + return $modules; } /** * Adds all needed skin modules + * TODO: Replace with getDefaultModules() when we move to min 1.35 */ private function addModules() { $this->out->addModuleStyles( [ 'mediawiki.skinning.content.externallinks', 'skins.citizen.styles', 'skins.citizen.styles.fonts', + 'skins.citizen.styles.toc', 'skins.citizen.icons', 'skins.citizen.icons.ca', 'skins.citizen.icons.es', @@ -242,6 +271,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', ] ); diff --git a/resources/skins.citizen.scripts/toc.js b/resources/skins.citizen.scripts.toc/toc.js similarity index 100% rename from resources/skins.citizen.scripts/toc.js rename to resources/skins.citizen.scripts.toc/toc.js diff --git a/resources/skins.citizen.styles/common/toc.less b/resources/skins.citizen.styles.toc/toc.less similarity index 98% rename from resources/skins.citizen.styles/common/toc.less rename to resources/skins.citizen.styles.toc/toc.less index 163053b4..ff113145 100644 --- a/resources/skins.citizen.styles/common/toc.less +++ b/resources/skins.citizen.styles.toc/toc.less @@ -1,3 +1,6 @@ +@import '../variables.less'; +@import '../mixins.less'; + .toc { position: fixed; z-index: -1; // So that it is below float objects in content diff --git a/resources/skins.citizen.styles/skin.less b/resources/skins.citizen.styles/skin.less index 16631e6d..a6c19222 100644 --- a/resources/skins.citizen.styles/skin.less +++ b/resources/skins.citizen.styles/skin.less @@ -8,7 +8,6 @@ @import 'common/content.less'; @import 'common/typography.less'; @import 'common/hacks.less'; - @import 'common/toc.less'; @import 'common/wikitable.less'; @import 'common/scrollbar.less'; @import 'common/reducemotion.less'; diff --git a/skin.json b/skin.json index 48976cd4..37029e17 100644 --- a/skin.json +++ b/skin.json @@ -188,6 +188,14 @@ ], "styles": [ "resources/skins.citizen.styles.fonts/font-face.less" ] }, + "skins.citizen.styles.toc": { + "class": "ResourceLoaderSkinModule", + "targets": [ + "desktop", + "mobile" + ], + "styles": [ "resources/skins.citizen.styles.toc/toc.less" ] + }, "skins.citizen.styles.search": { "class": "ResourceLoaderSkinModule", "targets": [ @@ -206,10 +214,14 @@ }, "skins.citizen.scripts": { "scripts": [ - "resources/skins.citizen.scripts/toc.js", "resources/skins.citizen.scripts/search.js" ] }, + "skins.citizen.scripts.toc": { + "scripts": [ + "resources/skins.citizen.scripts.toc/toc.js" + ] + }, "skins.citizen.scripts.search": { "scripts": [ "resources/skins.citizen.scripts.search/underscore.partial.js", @@ -517,9 +529,6 @@ } }, "Hooks": { - "BeforePageDisplay": [ - "Citizen\\CitizenHooks::onBeforePageDisplay" - ], "ResourceLoaderGetConfigVars": [ "Citizen\\CitizenHooks::onResourceLoaderGetConfigVars" ],