mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2025-01-18 19:00:24 +00:00
docs: wait for GitHub button coloring until CSS transitions are finished #615
This commit is contained in:
parent
a52aee2c70
commit
beb284ee87
1 changed files with 18 additions and 7 deletions
|
@ -18,8 +18,7 @@
|
||||||
</span>
|
</span>
|
||||||
<p>Built with <a href="https://github.com/McShelby/hugo-theme-relearn" title="love"><i class="fas fa-heart"></i></a> by <a href="https://gohugo.io/">Hugo</a></p>
|
<p>Built with <a href="https://github.com/McShelby/hugo-theme-relearn" title="love"><i class="fas fa-heart"></i></a> by <a href="https://gohugo.io/">Hugo</a></p>
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener( 'themeVariantLoaded', function( e ){
|
function githubButtonsScheme(){
|
||||||
console.log( e );
|
|
||||||
var scheme = 'light';
|
var scheme = 'light';
|
||||||
var colorPropertyValue = window.getComputedStyle( document.querySelector( '#sidebar' ) ).getPropertyValue( 'background-color' );
|
var colorPropertyValue = window.getComputedStyle( document.querySelector( '#sidebar' ) ).getPropertyValue( 'background-color' );
|
||||||
var colorValues = colorPropertyValue.match( /\d+/g ).map( function( e ){ return parseInt(e,10); });
|
var colorValues = colorPropertyValue.match( /\d+/g ).map( function( e ){ return parseInt(e,10); });
|
||||||
|
@ -27,17 +26,29 @@
|
||||||
// Luma, https://en.wikipedia.org/wiki/Luma_%28video%29, SMPTE C, Rec. 709 weightings
|
// Luma, https://en.wikipedia.org/wiki/Luma_%28video%29, SMPTE C, Rec. 709 weightings
|
||||||
scheme = 'dark';
|
scheme = 'dark';
|
||||||
}
|
}
|
||||||
|
return scheme;
|
||||||
|
}
|
||||||
|
document.addEventListener( 'themeVariantLoaded', function( e ){
|
||||||
|
// we get the scheme for initial loading
|
||||||
|
var scheme = githubButtonsScheme();
|
||||||
var githubButtonsHTML = `
|
var githubButtonsHTML = `
|
||||||
<a class="github-button" href="https://github.com/McShelby/hugo-theme-relearn/archive/main.zip" data-color-scheme="${scheme}" data-icon="octicon-cloud-download" aria-label="Download McShelby/hugo-theme-relearn on GitHub">Download</a>
|
<a class="github-button" href="https://github.com/McShelby/hugo-theme-relearn/archive/main.zip" data-color-scheme="${scheme}" data-icon="octicon-cloud-download" aria-label="Download McShelby/hugo-theme-relearn on GitHub">Download</a>
|
||||||
<a class="github-button" href="https://github.com/McShelby/hugo-theme-relearn" data-color-scheme="${scheme}" data-icon="octicon-star" data-show-count="true" aria-label="Star McShelby/hugo-theme-relearn on GitHub">Star</a>
|
<a class="github-button" href="https://github.com/McShelby/hugo-theme-relearn" data-color-scheme="${scheme}" data-icon="octicon-star" data-show-count="true" aria-label="Star McShelby/hugo-theme-relearn on GitHub">Star</a>
|
||||||
<a class="github-button" href="https://github.com/McShelby/hugo-theme-relearn/fork" data-color-scheme="${scheme}" data-icon="octicon-repo-forked" data-show-count="true" aria-label="Fork McShelby/hugo-theme-relearn on GitHub">Fork</a>
|
<a class="github-button" href="https://github.com/McShelby/hugo-theme-relearn/fork" data-color-scheme="${scheme}" data-icon="octicon-repo-forked" data-show-count="true" aria-label="Fork McShelby/hugo-theme-relearn on GitHub">Fork</a>
|
||||||
`;
|
`;
|
||||||
document.querySelector( '.github-buttons' ).innerHTML = githubButtonsHTML;
|
document.querySelector( '.github-buttons' ).innerHTML = githubButtonsHTML;
|
||||||
document.querySelectorAll( '.github-button' ).forEach( function( anchor ){
|
if( window.githubButtons ){
|
||||||
window.githubButtons.render( anchor, function( el ){
|
setTimeout( function(){
|
||||||
anchor.parentNode.replaceChild( el, anchor );
|
// 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 );
|
||||||
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<script async src="{{"js/github-buttons.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}"></script>
|
<script async src="{{"js/github-buttons.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}"></script>
|
Loading…
Reference in a new issue