Skip to content

Commit f08819b

Browse files
committed
Only initialize modal clipboardJS handler if there is embedded source code modal
1 parent 00c5b5b commit f08819b

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/resources/formats/html/templates/quarto-html.ejs

+10-7
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,16 @@ window.document.addEventListener("DOMContentLoaded", function (event) {
281281
});
282282
clipboard.on('success', onCopySuccess);
283283
284-
// For code content inside modals, clipBoardJS needs to be initialized with a container option
285-
// TODO: Check when it could be a function (https://github.com/zenorocha/clipboard.js/issues/860)
286-
const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', {
287-
text: getTextToCopy,
288-
container: window.document.getElementById('quarto-embedded-source-code-modal')
289-
});
290-
clipboardModal.on('success', onCopySuccess);
284+
285+
if (window.document.getElementById('quarto-embedded-source-code-modal')) {
286+
// For code content inside modals, clipBoardJS needs to be initialized with a container option
287+
// TODO: Check when it could be a function (https://github.com/zenorocha/clipboard.js/issues/860)
288+
const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', {
289+
text: getTextToCopy,
290+
container: window.document.getElementById('quarto-embedded-source-code-modal')
291+
});
292+
clipboardModal.on('success', onCopySuccess);
293+
}
291294
292295
<% } %>
293296

0 commit comments

Comments
 (0)