Skip to content

Commit 3344afc

Browse files
committed
CodeCopy: Pass codeBlockId via function call
Pass codeBlockId via function call instead of pulling from a data attribute. Reduces code complexity a tiny bit.
1 parent 8075202 commit 3344afc

File tree

5 files changed

+3
-4
lines changed

5 files changed

+3
-4
lines changed

assets/js/code-copy-v2.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Tightly coupled to `render-codeblock.html` for element targeting
2-
const copyToClipBoard = ((clipboard) => async (button) => {
3-
const codeBlockId = button.getAttribute('data-id-codeblock');
2+
const copyToClipBoard = ((clipboard) => async (button, codeBlockId) => {
43
const codeBlock = document
54
.getElementById(codeBlockId)
65
.getElementsByClassName('highlight')[0];

layouts/_default/_markup/render-codeblock.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{{- if $isSingleLine -}}
77
<div class="code-block" data-mf="true" style="display: none;">
88
<div class="code-container">
9-
<button onclick="copyToClipBoard(this)" data-id-codeblock="{{ $codeBlockId }}" class="code-copy-button" type="button">Copy</button>
9+
<button onclick="copyToClipBoard(this, {{ $codeBlockId }})" class="code-copy-button" type="button">Copy</button>
1010
<div class="highlight-v2 single-line" id="{{ $codeBlockId }}">
1111
{{ $result.Wrapped }}
1212
</div>
@@ -18,7 +18,7 @@
1818
<span class="code-type">{{ .Type }}</span>
1919
{{- end -}}
2020
<div class="code-container">
21-
<button onclick="copyToClipBoard(this)" data-id-codeblock="{{ $codeBlockId }}" class="code-copy-button multi-line" type="button">Copy</button>
21+
<button onclick="copyToClipBoard(this, {{ $codeBlockId }})" class="code-copy-button multi-line" type="button">Copy</button>
2222
<div class="highlight-v2" id="{{ $codeBlockId }}">
2323
{{ $result.Wrapped }}
2424
</div>
Loading
Loading
Loading

0 commit comments

Comments
 (0)