Add oneClickSelect

Add oneClickSelect
This commit is contained in:
2024-07-13 00:03:36 -04:00
parent bdca8b7c3b
commit fe985ec2f6
4 changed files with 32 additions and 4 deletions

View File

@@ -59,7 +59,21 @@ const showMessage = (m, s) => {
})
}
const oneClickSelect = (e, t = e.currentTarget) => {
// In here, "this" is the element
var range, selection;
if (window.getSelection) {
selection = window.getSelection();
range = document.createRange();
range.selectNodeContents(t);
selection.removeAllRanges();
selection.addRange(range);
} else if (document.body.createTextRange) {
range = document.body.createTextRange();
range.moveToElementText(t);
range.select();
}
}
const getURLVars = () => {
var oResult = {};
@@ -182,15 +196,21 @@ module.exports = {
break;
}
a.querySelectorAll("code").forEach((c)=> {
c.innerHTML = c.innerHTML.replace(/</g, "&lt;");
c.classList.add("line-numbers");
c.innerHTML = c.innerHTML.replace(/</g, "&lt;");
c.classList.add("copy-to-clipboard-button");
// add oneclickselect
})
if (typeof args.success == "function") args.success(a);
Prism.highlightAll();
a.querySelectorAll("code").forEach((c)=> {
c.onclick = (e) => {
oneClickSelect(e);
}
})
module.exports.colour.positionTooltip();
window.onresize = () => {
module.exports.colour.positionTooltip();

View File

@@ -129,6 +129,10 @@ body {
pre {
background-color: var(--colour-black-5);
font-size: .8rem;
code:not(.inline) {
display: block;
width: 100%;
}
}
};
p.switch {