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 %}} {{% button style="warning" icon="trash" %}}Reset variant{{% /button %}}
<script> <script>
variants.generator( '#vargenerator', '.secondary a', '.warning a' ); window.variants && variants.generator( '#vargenerator', '.secondary a', '.warning a' );
</script> </script>

View file

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

View file

@ -84,7 +84,7 @@
<i class="fas fa-paint-brush fa-fw"></i> <i class="fas fa-paint-brush fa-fw"></i>
<span>&nbsp;</span> <span>&nbsp;</span>
<div class="select-style"> <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 }} {{- $firstvariant := true }}
{{- range $themevariants }} {{- range $themevariants }}
{{- $themevariant := . }} {{- $themevariant := . }}
@ -100,7 +100,7 @@
</div> </div>
<div class="select-clear"></div> <div class="select-clear"></div>
</a> </a>
<script>variants.markSelectedVariant();</script> <script>window.variants && variants.markSelectedVariant();</script>
</li> </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> <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> </ul>

View file

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