Skip to content

Commit 6146108

Browse files
committed
fully switched codeblocks JS asset from jQuery
1 parent 4b5ddc0 commit 6146108

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

app/assets/javascripts/codeblocks.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ document.addEventListener('DOMContentLoaded', () => {
3434
};
3535

3636
/**
37-
* @param {HTMLElement} element
37+
* @param {Element} element
3838
* @returns {HTMLDivElement}
3939
*/
4040
const wrapRelative = (element) => {
@@ -49,14 +49,18 @@ document.addEventListener('DOMContentLoaded', () => {
4949
return;
5050
}
5151

52-
$('.post--content pre > code')
53-
.parent()
54-
.each(function (_, element) {
55-
const $content = $(this).text();
56-
const numLines = $content.trim().split(/\r?\n/).length;
52+
document.querySelectorAll('.post--content pre > code').forEach((child) => {
53+
const { parentElement: element } = child;
5754

58-
const button = createCopyButton($content, numLines <= 1);
59-
const wrapper = wrapRelative(element);
60-
wrapper.prepend(button);
61-
});
55+
if (!element) {
56+
return;
57+
}
58+
59+
const { textContent } = element;
60+
const numLines = textContent.trim().split(/\r?\n/).length;
61+
62+
const button = createCopyButton(textContent, numLines <= 1);
63+
const wrapper = wrapRelative(element);
64+
wrapper.prepend(button);
65+
});
6266
});

0 commit comments

Comments
 (0)