diff --git a/resource/css/skosmos.css b/resource/css/skosmos.css index 11bdfc72f..fda786a1f 100644 --- a/resource/css/skosmos.css +++ b/resource/css/skosmos.css @@ -85,13 +85,6 @@ body { margin: 0 5px; } - #main-container.termpage .fa-copy { - color: var(--vocab-text); - font-size: 30px; - position: relative; - bottom: -3px; - } - #main-container.searchpage .fa-arrow-right, #main-container.searchpage-multi-vocab .fa-arrow-right { color: var(--vocab-text); font-size: 12px; @@ -105,11 +98,6 @@ body { text-align: center; } - #main-container.searchpage .fa-copy, #main-container.searchpage-multi-vocab .fa-copy { - position: relative; - bottom: 5px; - } - .fa-magnifying-glass { color: var(--search-button-text); font-size: 22px; @@ -703,16 +691,26 @@ body { } #concept-label h1 { - float: left; + display: inline; } - .copy-clipboard { - border: none; - font-size: 20px; + #copy-preflabel { + color: var(--vocab-text); + font-size: 30px; + position: relative; + bottom: 10px; + left: 5px; } - .copy-clipboard:active, .copy-clipboard:focus, .copy-clipboard:active:focus { - border: none; + #copy-uri { + color: var(--vocab-text); + position: relative; + bottom: 4px; + } + + .copy-clipboard:focus { + border: 1px solid var(--vocab-text); + border-radius: 3px; } .property ul, .property li { diff --git a/resource/js/copy-to-clipboard.js b/resource/js/copy-to-clipboard.js new file mode 100644 index 000000000..e666ec9f7 --- /dev/null +++ b/resource/js/copy-to-clipboard.js @@ -0,0 +1,30 @@ +// function for copying the content from a specific element (by id) to the clipboard +function copyToClipboard (id) { + const copyElem = document.getElementById(id) + const sel = window.getSelection() + const range = document.createRange() + range.selectNodeContents(copyElem) + sel.removeAllRanges() + sel.addRange(range) + + navigator.clipboard.writeText(copyElem.innerText).catch((err) => + console.error('Failed to copy text to clipboard: ', err)) +} + +function registerCopyToClipboardEvents () { + const copyPrefElem = document.getElementById('copy-preflabel') + if (copyPrefElem) { + copyPrefElem.addEventListener('click', () => copyToClipboard('concept-preflabel')) + } + + const copyUriElem = document.getElementById('copy-uri') + if (copyUriElem) { + copyUriElem.addEventListener('click', () => copyToClipboard('concept-uri')) + } +} + +// register the copyToClipboard function as event an handler for the copy buttons +registerCopyToClipboardEvents() + +// re-register the event handlers after partial page loads +document.addEventListener('loadConceptPage', registerCopyToClipboardEvents) diff --git a/resource/translations/skosmos_en.po b/resource/translations/skosmos_en.po index 27ec9f661..b546794a7 100644 --- a/resource/translations/skosmos_en.po +++ b/resource/translations/skosmos_en.po @@ -879,3 +879,6 @@ msgstr "Information" msgid "Breadcrumbs" msgstr "Breadcrumbs" + +msgid "Copy to clipboard" +msgstr "Copy to clipboard" diff --git a/resource/translations/skosmos_fi.po b/resource/translations/skosmos_fi.po index f35146357..b8840bebd 100644 --- a/resource/translations/skosmos_fi.po +++ b/resource/translations/skosmos_fi.po @@ -888,3 +888,6 @@ msgstr "Tietoja" msgid "Breadcrumbs" msgstr "Murupolut" + +msgid "Copy to clipboard" +msgstr "Kopioi leikepöydälle" diff --git a/resource/translations/skosmos_sv.po b/resource/translations/skosmos_sv.po index 86c6f55d5..77befd524 100644 --- a/resource/translations/skosmos_sv.po +++ b/resource/translations/skosmos_sv.po @@ -887,3 +887,6 @@ msgstr "Information" msgid "Breadcrumbs" msgstr "Brödsmulor" + +msgid "Copy to clipboard" +msgstr "Kopiera till urklipp" diff --git a/src/view/concept-card.inc b/src/view/concept-card.inc index e5c63d355..79029c766 100644 --- a/src/view/concept-card.inc +++ b/src/view/concept-card.inc @@ -30,10 +30,11 @@