Compare commits

..

11 Commits

Author SHA1 Message Date
Mark Dumay
c8e2d3410c Merge pull request #269 from gethinode/develop
Fixes
2023-05-27 10:38:56 +02:00
Mark Dumay
8d53c762d7 Merge branch 'main' into develop 2023-05-27 10:27:16 +02:00
mark
22d2e41601 Bump package release 2023-05-27 10:26:44 +02:00
mark
b462c31916 Remove redundant empty lines on copy 2023-05-27 09:45:28 +02:00
mark
dbb5b4be69 Add a toast message on copy 2023-05-27 09:21:35 +02:00
mark
4f288ec5dd Add subject to copy message 2023-05-27 09:21:11 +02:00
mark
8fb47e27af Remove debug statement 2023-05-27 09:07:37 +02:00
mark
a0d2063738 Set message placement to default value 2023-05-27 09:06:07 +02:00
mark
c17986bb49 Enable toast placement configuration 2023-05-27 09:03:44 +02:00
mark
bafd522530 Embed container in base to aid CSS purge 2023-05-27 09:03:14 +02:00
mark
930e151365 Embed container in base to aid CSS purge 2023-05-27 09:02:47 +02:00
11 changed files with 77 additions and 42 deletions

View File

@@ -14,10 +14,12 @@ const addCopyButtons = (clipboard) => {
// 2. Create a button that will trigger a copy operation // 2. Create a button that will trigger a copy operation
const button = document.createElement('button') const button = document.createElement('button')
button.className = 'clipboard-button' button.className = 'clipboard-button'
button.setAttribute('data-toast-target', 'toast-copied-code-message')
button.type = 'button' button.type = 'button'
button.innerHTML = svgCopy button.innerHTML = svgCopy
button.addEventListener('click', () => { button.addEventListener('click', () => {
clipboard.writeText(codeBlock.innerText).then( const text = codeBlock.innerText.split('\n').filter(Boolean).join('\n')
clipboard.writeText(text).then(
() => { () => {
button.blur() button.blur()
button.innerHTML = svgCheck button.innerHTML = svgCheck

View File

@@ -1,37 +1,24 @@
// Script to move all embedded toast messages into a container. The container ensures multiple toast messages are // Script to move all embedded toast messages into a container with id 'toast-container'. The container ensures multiple
// stacked properly. The script targets all elements specified by a 'data-toast-target' and ensures the click event // toast messages are stacked properly. The script targets all elements specified by a 'data-toast-target' and ensures
// of the origin is linked as well. // the click event of the origin is linked as well.
// create a HTML fragment const container = document.getElementById('toast-container')
function createFragment (htmlStr) { if (container !== null) {
const fragment = document.createDocumentFragment() // process all data-toast-target elements
const temp = document.createElement('div') document.querySelectorAll('[data-toast-target]').forEach(trigger => {
temp.innerHTML = htmlStr const target = document.getElementById(trigger.getAttribute('data-toast-target'))
while (temp.firstChild) { if (target !== null) {
fragment.appendChild(temp.firstChild) // move the element to the toast containr
} container.appendChild(target)
return fragment
}
// insert a toast container in the DOM // eslint-disable-next-line no-undef
const container = '<div id="toast-container" class="toast-container position-fixed bottom-0 end-0 p-3"></div>' const toast = bootstrap.Toast.getOrCreateInstance(target)
document.body.appendChild(createFragment(container)) if (toast !== null) {
const parent = document.getElementById('toast-container') // associate the click event of the origin with the toast element
trigger.addEventListener('click', () => {
// process all data-toast-target elements toast.show()
document.querySelectorAll('[data-toast-target]').forEach(trigger => { })
const target = document.getElementById(trigger.getAttribute('data-toast-target')) }
if (target !== null) {
// move the element to the toast containr
parent.appendChild(target)
// eslint-disable-next-line no-undef
const toast = bootstrap.Toast.getOrCreateInstance(target)
if (toast !== null) {
// associate the click event of the origin with the toast element
trigger.addEventListener('click', () => {
toast.show()
})
} }
} })
}) }

View File

@@ -36,6 +36,11 @@
sidebar = true sidebar = true
# toml-docs-end navigation # toml-docs-end navigation
# toml-docs-start messages
[messages]
placement = "bottom-right"
# toml-docs-end messages
# toml-docs-start sharing # toml-docs-start sharing
[sharing] [sharing]
enabled = true enabled = true

View File

@@ -82,7 +82,11 @@
- id: shareLink - id: shareLink
translation: "Share via" translation: "Share via"
- id: copiedToClipboard - id: copiedToClipboard
translation: "Copied to clipboard" translation: "copied to clipboard"
- id: link
translation: "Link"
- id: code
translation: "Code"
# 404 page # 404 page
- id: pageNotFound - id: pageNotFound

View File

@@ -72,7 +72,11 @@
- id: shareLink - id: shareLink
translation: "Delen via" translation: "Delen via"
- id: copiedToClipboard - id: copiedToClipboard
translation: "Gekopieerd naar clipboard" translation: "gekopieerd naar clipboard"
- id: link
translation: "Link"
- id: code
translation: "Code"
# 404 page # 404 page
- id: pageNotFound - id: pageNotFound

View File

@@ -68,6 +68,7 @@
</div> </div>
{{ end }} {{ end }}
{{- partial "footer/toast-container.html" . -}}
{{- partialCached "footer/scripts.html" (dict "header" false "page" .) }} {{- partialCached "footer/scripts.html" (dict "header" false "page" .) }}
</body> </body>
</html> </html>

View File

@@ -19,7 +19,7 @@
{{- $target = (printf "toast-message-%s-%d" (anchorize $item.name) $index ) -}} {{- $target = (printf "toast-message-%s-%d" (anchorize $item.name) $index ) -}}
{{- $clipboard = $url -}} {{- $clipboard = $url -}}
{{- $url = "#!" -}} {{- $url = "#!" -}}
{{- partial "assets/toast.html" (dict "id" $target "message" (T "copiedToClipboard")) -}} {{- partial "assets/toast.html" (dict "id" $target "message" (printf "%s %s" (T "link") (T "copiedToClipboard"))) -}}
{{- end -}} {{- end -}}
{{ partial "assets/button.html" (dict "toast" $target "clipboard" $clipboard "href" $url "icon" $item.icon "class" "btn-social px-1" )}} {{ partial "assets/button.html" (dict "toast" $target "clipboard" $clipboard "href" $url "icon" $item.icon "class" "btn-social px-1" )}}
{{- end -}} {{- end -}}

View File

@@ -0,0 +1,31 @@
<!--
Defines a container to stack toast messages. By default, toast messages are displayed in the bottom right of the
viewport. Multiple toast messages are stacked vertically. Adjust the configuration by adjusting 'messages' in the
site parameters. The following arguments are supported:
"placement" Optional position of the toast messages relative to the viewport: "top-left", "top-center",
"top-right", "middle-left", "middle-center", "middle-right", "bottom-left", "bottom-center", or
"bottom-right" (default).
-->
{{- $placement := "bottom-right" -}}
{{- $position := "bottom-0 end-0" -}}
{{- with site.Params.messages.placement }}{{ $placement = . }}{{ end -}}
{{- $supportedPlacements := slice "top-left" "top-center" "top-right" "middle-left" "middle-center" "middle-right" "bottom-left" "bottom-center" "bottom-right" -}}
{{- if not (in $supportedPlacements $placement) -}}
{{- errorf "partial [footer/toast-container.html] - Invalid value for param 'placement': %s" $placement -}}
{{- end -}}
{{- if eq $placement "top-left" }}{{ $position = "top-0 start-0" -}}
{{- else if eq $placement "top-center" }}{{ $position = "top-0 start-50 translate-middle-x" -}}
{{- else if eq $placement "top-right" }}{{ $position = "top-0 end-0" -}}
{{- else if eq $placement "middle-left" }}{{ $position = "top-50 start-0 translate-middle-y" -}}
{{- else if eq $placement "middle-center" }}{{ $position = "top-50 start-50 translate-middle" -}}
{{- else if eq $placement "middle-right" }}{{ $position = "top-50 end-0 translate-middle-y" -}}
{{- else if eq $placement "bottom-left" }}{{ $position = "bottom-0 start-0" -}}
{{- else if eq $placement "bottom-center" }}{{ $position = "bottom-0 start-50 translate-middle-x" -}}
{{- else if eq $placement "bottom-right" }}{{ $position = "bottom-0 end-0" -}}
{{- end -}}
<div id="toast-container" class="toast-container position-fixed {{ $position }} p-3">
{{- partial "assets/toast.html" (dict "id" "toast-copied-code-message" "message" (printf "%s %s" (T "code") (T "copiedToClipboard"))) -}}
</div>

View File

@@ -4,6 +4,7 @@
"header": Optional header of the toast message. Uses the site title by default. "header": Optional header of the toast message. Uses the site title by default.
--> -->
{{- $error := false -}}
{{- $id := printf "toast-message-%d" .Ordinal -}} {{- $id := printf "toast-message-%d" .Ordinal -}}
{{- with .Get "id" }}{{ $id = . }}{{ end -}} {{- with .Get "id" }}{{ $id = . }}{{ end -}}
{{ $header := .Get "header" -}} {{ $header := .Get "header" -}}
@@ -11,6 +12,6 @@
{{ if not $message -}} {{ if not $message -}}
{{ errorf "Missing inner element text: %s" .Position -}} {{ errorf "Missing inner element text: %s" .Position -}}
{{ else }} {{ else if not $error -}}
{{ partial "assets/toast.html" (dict "id" $id "header" $header "message" $message) }} {{ partial "assets/toast.html" (dict "id" $id "header" $header "message" $message) }}
{{ end -}} {{ end -}}

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{ {
"name": "@gethinode/hinode", "name": "@gethinode/hinode",
"version": "0.14.3", "version": "0.14.4",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@gethinode/hinode", "name": "@gethinode/hinode",
"version": "0.14.3", "version": "0.14.4",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@fortawesome/fontawesome-free": "^6.4.0", "@fortawesome/fontawesome-free": "^6.4.0",

View File

@@ -1,6 +1,6 @@
{ {
"name": "@gethinode/hinode", "name": "@gethinode/hinode",
"version": "0.14.3", "version": "0.14.4",
"description": "Hinode is a clean documentation and blog theme for Hugo, an open-source static site generator", "description": "Hinode is a clean documentation and blog theme for Hugo, an open-source static site generator",
"keywords": [ "keywords": [
"hugo", "hugo",