website/layouts/partials/hooks/body-end.html

65 lines
2.3 KiB
HTML

{{ with .Site.Params.algolia_docsearch }}
<!-- scripts for algolia docsearch -->
{{ end }}
{{/* copy-and-paste helper for codenew shortcode */}}
{{- if or (.HasShortcode "code_sample") (.HasShortcode "code") (.HasShortcode "codenew") -}}
{{- $toastrJs := resources.Get "js/toastr-2.1.4.min.js" | minify | fingerprint -}}
{{- if hugo.IsProduction -}}
<script async src="{{ $toastrJs.RelPermalink }}"></script>
{{- else -}}
<script async src="{{ $toastrJs.RelPermalink }}"></script>
{{- end -}}
<script type="text/javascript">
function copyCode(elem) {
if (document.getElementById(elem)) {
if (navigator.clipboard) {
navigator.clipboard.writeText(document.getElementById(elem).textContent).then(
function () {
toastr.options = {
closeButton: true,
progressBar: true,
positionClass: "toast-bottom-center",
timeOut: 2000,
preventDuplicates: true,
newestOnTop: true
};
toastr.success("{{i18n "toast_success_copycode"}}" + elem, "{{i18n "success_copy_to_clipboard"}}");
},
function () {
toastr.options = {
closeButton: true,
progressBar: true,
positionClass: "toast-bottom-center",
timeOut: 2000,
preventDuplicates: true,
newestOnTop: true
};
toastr.error("{{i18n "toast_failure_copycode"}}" + elem, "{{i18n "error_copy_to_clipboard"}}");
}
);
} else {
toastr.options = {
closeButton: true,
progressBar: true,
positionClass: "toast-bottom-center",
timeOut: 2000,
preventDuplicates: true,
newestOnTop: true
};
toastr.warning("{{i18n "browser_clipboard_support_warning"}}", "{{i18n "warning_copy_to_clipboard"}}");
}
}
}
</script>
{{- end -}}
{{/* JavaScript detector */}}
{{- if hugo.IsProduction -}}
{{- $jsDetect := resources.Get "js/detect-js.js" | minify | fingerprint -}}
<script defer src="{{ $jsDetect.RelPermalink }}" integrity="{{ $jsDetect.Data.Integrity }}" crossorigin="anonymous"></script>
{{- else -}}
{{- $jsDetect := resources.Get "js/detect-js.js" -}}
<script defer src="{{ $jsDetect.RelPermalink }}"></script>
{{- end -}}