js: Define function for copy to clipboard and provide it in onClick

Instead of looping through all the code blocks at onload, just put an
onClick tag in the HTML template, which calls a global function.

This also improves the semantics since we aren't abusing href to be
javascript.

Also improves the writeText function call, since that method actually
returns a Promise which we should be waiting on. It technically worked
before because Promise starts executing instantly in JS, without being
awaited.
This commit is contained in:
bbaovanc committed 2026-09-18 14:21:47 -05:00
1 parent a2a8e2c205
commit b67e3f4671
2 files changed
+20 -22

No files matched your search

+2 -1
View File
@@ -5,7 +5,8 @@
<div class="code-block">
<div class="code-block-header">
<pre class="code-block-type">{{ $type }}</pre>
<a href="javascript:void(0)" class="code-block-copy-button">
{{/* https://blog.udemy.com/javascript-href/ */}}
<a href="javascript:null" onClick="javascript:copy_to_clipboard(this)" class="code-block-copy-button">
{{ i18n "copy_to_clipboard" }}
</a>
</div>