Add oneClickSelect

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

File diff suppressed because one or more lines are too long

View File

@ -893,6 +893,10 @@ body .container main article tabset [role=tabpanel] pre, body .container main ar
background-color: var(--colour-black-5); background-color: var(--colour-black-5);
font-size: 0.8rem; font-size: 0.8rem;
} }
body .container main article tabset [role=tabpanel] pre code:not(.inline), body .container main article .tab-group [role=tabpanel] pre code:not(.inline) {
display: block;
width: 100%;
}
body .container main article p.switch { body .container main article p.switch {
-webkit-box-align: center; -webkit-box-align: center;
-ms-flex-align: center; -ms-flex-align: center;

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 = () => { const getURLVars = () => {
var oResult = {}; var oResult = {};
@ -182,15 +196,21 @@ module.exports = {
break; break;
} }
a.querySelectorAll("code").forEach((c)=> { a.querySelectorAll("code").forEach((c)=> {
c.innerHTML = c.innerHTML.replace(/</g, "&lt;");
c.classList.add("line-numbers"); c.classList.add("line-numbers");
c.innerHTML = c.innerHTML.replace(/</g, "&lt;");
c.classList.add("copy-to-clipboard-button"); c.classList.add("copy-to-clipboard-button");
// add oneclickselect
}) })
if (typeof args.success == "function") args.success(a); if (typeof args.success == "function") args.success(a);
Prism.highlightAll(); Prism.highlightAll();
a.querySelectorAll("code").forEach((c)=> {
c.onclick = (e) => {
oneClickSelect(e);
}
})
module.exports.colour.positionTooltip(); module.exports.colour.positionTooltip();
window.onresize = () => { window.onresize = () => {
module.exports.colour.positionTooltip(); module.exports.colour.positionTooltip();

View File

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