-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1590 from NatLibFi/issue1484-concept-page-copy-to…
…-clipboard Copy to clipboard functionality for concept page
- Loading branch information
Showing
9 changed files
with
95 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters