Skip to content

Commit 5aaa37f

Browse files
committed
fix scroll add copy btn
1 parent 36c1b4c commit 5aaa37f

22 files changed

Lines changed: 56 additions & 1 deletion

File tree

docs/compare/dom-to-image/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,5 +285,6 @@ <h2>Ready to switch?</h2>
285285
}
286286
})();
287287
</script>
288+
<script defer src="/copy-code.js"></script>
288289
</body>
289290
</html>

docs/compare/html-to-image/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,5 +283,6 @@ <h2>Ready to try SnapDOM?</h2>
283283
}
284284
})();
285285
</script>
286+
<script defer src="/copy-code.js"></script>
286287
</body>
287288
</html>

docs/compare/html2canvas/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,5 +489,6 @@ <h2>Ready to switch?</h2>
489489
return String(s).replace(/[&<>"']/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
490490
}
491491
</script>
492+
<script defer src="/copy-code.js"></script>
492493
</body>
493494
</html>

docs/compare/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,5 +212,6 @@ <h2>Try snapDOM in 30 seconds</h2>
212212
}
213213
})();
214214
</script>
215+
<script defer src="/copy-code.js"></script>
215216
</body>
216217
</html>

docs/compare/modern-screenshot/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,5 +247,6 @@ <h2>Try SnapDOM in 30 seconds</h2>
247247
}
248248
})();
249249
</script>
250+
<script defer src="/copy-code.js"></script>
250251
</body>
251252
</html>

docs/copy-code.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
(function () {
2+
function ready(fn) {
3+
if (document.readyState !== 'loading') fn()
4+
else document.addEventListener('DOMContentLoaded', fn)
5+
}
6+
ready(function () {
7+
document.querySelectorAll('.code-block').forEach(function (block) {
8+
if (block.dataset.copyReady) return
9+
block.dataset.copyReady = '1'
10+
var code = block.textContent
11+
var btn = document.createElement('button')
12+
btn.type = 'button'
13+
btn.className = 'code-copy'
14+
btn.setAttribute('aria-label', 'Copy code')
15+
btn.textContent = 'Copy'
16+
btn.addEventListener('click', function () {
17+
navigator.clipboard.writeText(code).then(function () {
18+
btn.textContent = 'Copied'
19+
btn.classList.add('copied')
20+
setTimeout(function () {
21+
btn.textContent = 'Copy'
22+
btn.classList.remove('copied')
23+
}, 1500)
24+
}).catch(function () {
25+
btn.textContent = 'Error'
26+
setTimeout(function () { btn.textContent = 'Copy' }, 1500)
27+
})
28+
})
29+
block.appendChild(btn)
30+
})
31+
})
32+
})()

docs/docs/api/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,5 +229,6 @@ <h2>Ready to capture?</h2>
229229
}
230230
})();
231231
</script>
232+
<script defer src="/copy-code.js"></script>
232233
</body>
233234
</html>

docs/docs/cache/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,5 +169,6 @@ <h2>Ready to capture?</h2>
169169
}
170170
})();
171171
</script>
172+
<script defer src="/copy-code.js"></script>
172173
</body>
173174
</html>

docs/docs/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,5 +222,6 @@ <h2>Ready to capture?</h2>
222222
}
223223
})();
224224
</script>
225+
<script defer src="/copy-code.js"></script>
225226
</body>
226227
</html>

docs/docs/options/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,5 +314,6 @@ <h2>Ready to capture?</h2>
314314
}
315315
})();
316316
</script>
317+
<script defer src="/copy-code.js"></script>
317318
</body>
318319
</html>

0 commit comments

Comments
 (0)