Skip to content

Commit e529aa0

Browse files
authored
FIX: Make copybutton remain for a second during success (#176)
closes #175
1 parent 403f289 commit e529aa0

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

sphinx_copybutton/_static/copybutton.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ div.highlight {
3535
position: relative;
3636
}
3737

38-
.highlight:hover button.copybtn {
38+
/* Show the copybutton */
39+
.highlight:hover button.copybtn, button.copybtn.success {
3940
opacity: 1;
4041
}
4142

sphinx_copybutton/_static/copybutton.js_t

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,25 @@ const clearSelection = () => {
102102
}
103103
}
104104

105-
// Changes tooltip text for two seconds, then changes it back
105+
// Changes tooltip text for a moment, then changes it back
106+
// We want the timeout of our `success` class to be a bit shorter than the
107+
// tooltip and icon change, so that we can hide the icon before changing back.
108+
var timeoutIcon = 2000;
109+
var timeoutSuccessClass = 1500;
110+
106111
const temporarilyChangeTooltip = (el, oldText, newText) => {
107112
el.setAttribute('data-tooltip', newText)
108113
el.classList.add('success')
109-
setTimeout(() => el.setAttribute('data-tooltip', oldText), 2000)
110-
setTimeout(() => el.classList.remove('success'), 2000)
114+
// Remove success a little bit sooner than we change the tooltip
115+
// So that we can use CSS to hide the copybutton first
116+
setTimeout(() => el.classList.remove('success'), timeoutSuccessClass)
117+
setTimeout(() => el.setAttribute('data-tooltip', oldText), timeoutIcon)
111118
}
112119

113120
// Changes the copy button icon for two seconds, then changes it back
114121
const temporarilyChangeIcon = (el) => {
115122
el.innerHTML = iconCheck;
116-
setTimeout(() => {el.innerHTML = iconCopy}, 2000)
123+
setTimeout(() => {el.innerHTML = iconCopy}, timeoutIcon)
117124
}
118125

119126
const addCopyButtonToCodeCells = () => {

0 commit comments

Comments
 (0)