Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc0c40f6

Browse files
committed
Add feature detection & check for errors
1 parentf067c15 commitc0c40f6

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

‎python_docs_theme/static/copybutton.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,23 @@ const loadCopyButton = () => {
3333
constmakeOnButtonClick=()=>{
3434
lettimeout=null
3535
// define the behavior of the button when it's clicked
36-
returnevent=>{
36+
returnasyncevent=>{
37+
// check if the clipboard is available
38+
if(!navigator.clipboard||!navigator.clipboard.writeText){
39+
return;
40+
}
41+
3742
clearTimeout(timeout)
3843
constbuttonEl=event.currentTarget
3944
constcodeEl=buttonEl.nextElementSibling
40-
navigator.clipboard.writeText(getCopyableText(codeEl))
45+
46+
try{
47+
awaitnavigator.clipboard.writeText(getCopyableText(codeEl))
48+
}catch(e){
49+
console.error(e.message)
50+
return
51+
}
52+
4153
buttonEl.innerText=_("Copied!")
4254
timeout=setTimeout(()=>{
4355
buttonEl.innerText=_("Copy")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp