Add quadruple click to select all

This commit is contained in:
Gabriel Augendre 2021-04-10 16:27:45 +02:00
parent fc7b14192c
commit 921994d2ad
2 changed files with 31 additions and 0 deletions

View file

@ -0,0 +1,28 @@
"use strict";
function addCopyCode() {
const codeBlocks = document.querySelectorAll("pre");
codeBlocks.forEach(pre => {
pre.addEventListener("click", event => {
if (event.detail === 4) {
const selection = window.getSelection();
selection.setBaseAndExtent(
pre.querySelector("code").firstChild,
0,
pre.querySelector("code").lastChild,
1
);
}
});
pre.setAttribute("title", "Quadruple click to select all");
});
}
((readyState) => {
if (readyState === "interactive") {
addCopyCode();
} else if (readyState === "loading") {
window.addEventListener("DOMContentLoaded", addCopyCode, false);
}
})(document.readyState);

View file

@ -63,6 +63,9 @@
{% if user.is_authenticated %}
<script src="{% static 'edit-keymap.js' %}" async defer></script>
{% endif %}
{% if article and article.has_code %}
<script src="{% static 'copy-code.js' %}" async defer></script>
{% endif %}
</body>
</html>