generated from dfe-analytical-services/shiny-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Adding line chart copy to clipboard JS
- Loading branch information
Showing
1 changed file
with
22 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,23 @@ | ||
|
||
async function getImageBlobFromUrl(url) { | ||
const fetchedImageData = await fetch(url); | ||
const blob = await fetchedImageData.blob(); | ||
return blob; | ||
} | ||
$(document).ready(function () { | ||
$("#stat_n_focus_line-copybtn").on("click", async () => { | ||
const src = $("#stat_n_focus_line-copy_plot>img").attr("src"); | ||
try { | ||
const blob = await getImageBlobFromUrl(src); | ||
await navigator.clipboard.write([ | ||
new ClipboardItem({ | ||
[blob.type]: blob | ||
}) | ||
]); | ||
alert("Image copied to clipboard!"); | ||
} catch (err) { | ||
console.error(err.name, err.message); | ||
alert("There was an error while copying image to clipboard :/"); | ||
} | ||
}); | ||
}); |