soundcite player gets loaded only if there's .soundcite element in a page..

This commit is contained in:
Marcell Mars 2020-09-10 03:23:08 +02:00
parent 2cf0849d9d
commit 8c493c5928
3 changed files with 18 additions and 6 deletions

View File

@ -1,10 +1,14 @@
window.addEventListener('scroll', function(e) {
if (document.querySelector('body').clientWidth > 1024) {
let rightcolumn = document.querySelector('.rightcolumn');
let mantletitle = document.querySelector('.mantletitle') || document.querySelector('.crusttitle');
let mantletitle = document.querySelector('.mantletitle') || document.querySelector('.crusttitle') || false;
if (!mantletitle) {
return
}
let mantlebar = document.querySelector('.mantlebar')
let grid = document.querySelector('.grid')
let gridrect = mantletitle.getBoundingClientRect();
if (gridrect.top < 20 && !grid.classList.contains('moved')) {
grid.classList.add('moved');
mantlebar.style.display = "inline";
@ -28,4 +32,11 @@ window.addEventListener('DOMContentLoaded', (e) => {
s.appendChild(par.cloneNode(true))
par.remove()
document.querySelector("#TableOfContents > ol:first-child").insertBefore(s, document.querySelector("#TableOfContents > ol:first-child").firstChild)
if (document.querySelector(".soundcite")) {
var soundcite = document.createElement('script');
soundcite.src = `/js/soundcite.min.js`;
document.body.appendChild(soundcite);
}
})

View File

@ -32,11 +32,9 @@
{{- else if strings.HasPrefix .Destination "audio:" -}}
{{- $a_destination := (substr .Destination 6) -}}
{{- if findRE "^.*static" $a_destination -}}
<div>{{ .Text }}</div>
<audio src="{{- (replaceRE "^.*static" "" $a_destination ) | safeURL -}}" preload="metadata" controls="true"></audio>
<span class="soundcite" data-url="{{- (replaceRE "^.*static" "" $a_destination ) | safeURL -}}">{{ .Text }}</span>
{{- else -}}
<div>{{ .Text }}</div>
<audio src="{{- $a_destination | safeURL -}}" preload="metadata" controls="true"></audio>
<span class="soundcite" data-url="{{- $a_destination | safeURL -}}">{{ .Text }}</span>
{{- end -}}
{{- else if findRE "^.*static" .Destination -}}
<img src="{{- (replaceRE "^.*static" "" .Destination ) | safeURL -}}" alt="{{- .Text -}}" {{- with .Title}} title="{{- . -}}"{{- end -}} />

View File

@ -1,8 +1,11 @@
{{ if (or (eq hugo.Environment "gitea") (eq hugo.Environment "preview") ) }}
<link rel="stylesheet" href="/css/site.css">
<link rel="stylesheet" href="/css/site.min.css">
<link rel="stylesheet" href="/css/player.min.css">
{{ else if .Site.IsServer }}
{{ $style := resources.Get "css/site.css" | postCSS (dict "config" "./assets/css/postcss.config.js") | minify }}
<link rel="stylesheet" href="{{ $style.Permalink }}">
{{ $style := resources.Get "css/player.css" | postCSS (dict "config" "./assets/css/postcss.config.js") | minify }}
<link rel="stylesheet" href="{{ $style.Permalink }}">
{{ else }}
{{ $flist := newScratch }}
{{ $flist.Set "initial" "nop" }}