Add quadruple click to select all
This commit is contained in:
parent
fc7b14192c
commit
921994d2ad
2 changed files with 31 additions and 0 deletions
28
articles/static/copy-code.js
Normal file
28
articles/static/copy-code.js
Normal 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);
|
|
@ -63,6 +63,9 @@
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<script src="{% static 'edit-keymap.js' %}" async defer></script>
|
<script src="{% static 'edit-keymap.js' %}" async defer></script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if article and article.has_code %}
|
||||||
|
<script src="{% static 'copy-code.js' %}" async defer></script>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Reference in a new issue