From 4921ec0583e9a60e1baa53e9764473fefdd6f7e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Wed, 13 Sep 2023 23:29:04 +0200 Subject: [PATCH] docs: make scheme switch of github butons reliable #640 --- exampleSite/layouts/partials/menu-footer.html | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/exampleSite/layouts/partials/menu-footer.html b/exampleSite/layouts/partials/menu-footer.html index ed8e183396..46ed8d2ddf 100644 --- a/exampleSite/layouts/partials/menu-footer.html +++ b/exampleSite/layouts/partials/menu-footer.html @@ -12,8 +12,12 @@ } return scheme; } - document.addEventListener( 'themeVariantLoaded', function( e ){ - // we get the scheme for initial loading + function githubButtonsInit(){ + if( !window.githubButtons ){ + // wait for the script to load + setTimeout( githubButtonsInit, 50 ); + return; + } var scheme = githubButtonsScheme(); var githubButtonsHTML = ` Download @@ -21,18 +25,16 @@ Fork `; document.querySelector( '.github-buttons' ).innerHTML = githubButtonsHTML; - if( window.githubButtons ){ - setTimeout( function(){ - // we have to wait until the CSS class .default-animation has settled and recalculate the scheme again - var scheme = githubButtonsScheme(); - document.querySelectorAll( '.github-button' ).forEach( function( anchor ){ - anchor.dataset.colorScheme = scheme; - window.githubButtons.render( anchor, function( el ){ - anchor.parentNode.replaceChild( el, anchor ); - }); - }); - }, 400 ); - } + document.querySelectorAll( '.github-button' ).forEach( function( anchor ){ + anchor.dataset.colorScheme = scheme; + window.githubButtons.render( anchor, function( el ){ + anchor.parentNode.replaceChild( el, anchor ); + }); + }); + } + document.addEventListener( 'themeVariantLoaded', function( e ){ + // we have to wait until the CSS class .default-animation has settled and and the buttons have loaded to recalculate the scheme again + setTimeout( githubButtonsInit, 400 ); }); \ No newline at end of file