Thanks to visit codestin.com Credit goes to github.com
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f067c15 commit c0c40f6Copy full SHA for c0c40f6
python_docs_theme/static/copybutton.js
@@ -33,11 +33,23 @@ const loadCopyButton = () => {
33
const makeOnButtonClick = () => {
34
let timeout = null
35
// define the behavior of the button when it's clicked
36
- return event => {
+ return async event => {
37
+ // check if the clipboard is available
38
+ if (!navigator.clipboard || !navigator.clipboard.writeText) {
39
+ return;
40
+ }
41
+
42
clearTimeout(timeout)
43
const buttonEl = event.currentTarget
44
const codeEl = buttonEl.nextElementSibling
- navigator.clipboard.writeText(getCopyableText(codeEl))
45
46
+ try {
47
+ await navigator.clipboard.writeText(getCopyableText(codeEl))
48
+ } catch (e) {
49
+ console.error(e.message)
50
+ return
51
52
53
buttonEl.innerText = _("Copied!")
54
timeout = setTimeout(() => {
55
buttonEl.innerText = _("Copy")
0 commit comments