theme: avoid JS errors if an output format loaded not all files #308

This commit is contained in:
Sören Weber 2022-07-09 19:46:39 +02:00
parent 775e5c0e9e
commit 8d19b3b484
No known key found for this signature in database
GPG key ID: 07D17FF580AE7589
4 changed files with 6 additions and 6 deletions

View file

@ -33,5 +33,5 @@ This only works in modern browsers.
{{% button style="warning" icon="trash" %}}Reset variant{{% /button %}}
<script>
variants.generator( '#vargenerator', '.secondary a', '.warning a' );
window.variants && variants.generator( '#vargenerator', '.secondary a', '.warning a' );
</script>

View file

@ -69,7 +69,7 @@
function useMermaid( config ){
if (typeof mermaid != 'undefined' && typeof mermaid.mermaidAPI != 'undefined') {
mermaid.initialize( Object.assign( { "securityLevel": "antiscript", "startOnLoad": false }, config ) );
if( config.theme ){
if( config.theme && variants ){
var write_style = variants.findLoadedStylesheet( 'variant-style' );
write_style.setProperty( '--CONFIG-MERMAID-theme', config.theme );
}
@ -96,7 +96,7 @@
{{- end }}
<script>
function useSwagger( config ){
if( config.theme ){
if( config.theme && variants ){
var write_style = variants.findLoadedStylesheet( 'variant-style' );
write_style.setProperty( '--CONFIG-SWAGGER-theme', config.theme );
}

View file

@ -84,7 +84,7 @@
<i class="fas fa-paint-brush fa-fw"></i>
<span>&nbsp;</span>
<div class="select-style">
<select id="select-variant" onchange="variants.changeVariant( this.value );">
<select id="select-variant" onchange="window.variants && variants.changeVariant( this.value );">
{{- $firstvariant := true }}
{{- range $themevariants }}
{{- $themevariant := . }}
@ -100,7 +100,7 @@
</div>
<div class="select-clear"></div>
</a>
<script>variants.markSelectedVariant();</script>
<script>window.variants && variants.markSelectedVariant();</script>
</li>
<li class="footerVisitedLinks{{if $showvisitedlinks}} showVisitedLinks{{end}}"><a class="padding" onclick="clearHistory();"><i class="fas fa-history fa-fw"></i> {{ T "Clear-History" }}</a></li>
</ul>

View file

@ -40,6 +40,6 @@
{{- range $themevariants }}
{{- $quotedthemevariants = $quotedthemevariants | append (printf "'%s'" .) }}
{{- end }}
variants.init( [ {{ delimit $quotedthemevariants ", " | safeJS }} ] );
window.variants && variants.init( [ {{ delimit $quotedthemevariants ", " | safeJS }} ] );
</script>
<script src="{{"js/jquery.min.js"| relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" defer></script>