diff --git a/peachjam/js/components/clipboard.ts b/peachjam/js/components/clipboard.ts index d2242269e..fa9af618a 100644 --- a/peachjam/js/components/clipboard.ts +++ b/peachjam/js/components/clipboard.ts @@ -10,8 +10,23 @@ export class CopyToClipboard { async copy () { try { + const text = this.root.dataset.value; + const html = this.root.dataset.valueHtml; + if (navigator && navigator.clipboard) { - await navigator.clipboard.writeText(this.root.dataset.value || ''); + const items: Record = {}; + + if (text) { + const type = 'text/plain'; + items[type] = new Blob([text], { type }); + } + + if (html) { + const type = 'text/html'; + items[type] = new Blob([html], { type }); + } + + await navigator.clipboard.write([new ClipboardItem(items)]); this.root.innerText = this.root.dataset.confirmation || 'Copied!'; setTimeout(() => { diff --git a/peachjam/settings.py b/peachjam/settings.py index 25d9cee22..40558eb62 100644 --- a/peachjam/settings.py +++ b/peachjam/settings.py @@ -100,6 +100,7 @@ "allauth.account.middleware.AccountMiddleware", "django.middleware.cache.FetchFromCacheMiddleware", "django_htmx.middleware.HtmxMiddleware", + "django.contrib.sites.middleware.CurrentSiteMiddleware", ] ROOT_URLCONF = "peachjam.urls" diff --git a/peachjam/templates/peachjam/judgment_detail.html b/peachjam/templates/peachjam/judgment_detail.html index bcd99f90a..ac213f516 100644 --- a/peachjam/templates/peachjam/judgment_detail.html +++ b/peachjam/templates/peachjam/judgment_detail.html @@ -36,7 +36,8 @@ class="btn btn-outline-secondary btn-xs ms-2" title="{% trans "Copy to clipboard" %}" data-component="CopyToClipboard" - data-value="{{ document.mnc }}" + data-value='{{ document.mnc }}' + data-value-html='{{ document.mnc }}' data-confirmation="{% trans "Copied!" %}"> {% trans "Copy" %} diff --git a/peachjam/templates/peachjam/layouts/document_detail.html b/peachjam/templates/peachjam/layouts/document_detail.html index 0cff88c06..cba642520 100644 --- a/peachjam/templates/peachjam/layouts/document_detail.html +++ b/peachjam/templates/peachjam/layouts/document_detail.html @@ -183,7 +183,8 @@

{{ document.title }}

class="btn btn-outline-secondary btn-xs ms-2" title="{% trans "Copy to clipboard" %}" data-component="CopyToClipboard" - data-value="{{ document.citation }}" + data-value='{{ document.citation }}' + data-value-html='{{ document.citation }}' data-confirmation="{% trans "Copied!" %}"> {% trans "Copy" %} @@ -210,7 +211,8 @@

{{ document.title }}

class="btn btn-outline-secondary btn-xs ms-2" title="{% trans "Copy to clipboard" %}" data-component="CopyToClipboard" - data-value="{{ alternative_name.title }}" + data-value='{{ alternative_name.title }}' + data-value-html='{{ alternative_name.title }}' data-confirmation="{% trans "Copied!" %}"> {% trans "Copy" %}