From 7dcc72d5a0409c8b4febef65afe1e54b8d8042eb Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 18 Oct 2024 18:25:40 -0400 Subject: [PATCH] Fixes #24 - Expose oneClickSelect --- public/assets/scaffolding-min.js | 52 +++++++++++++++++++++----------- src/js/core/_core.js | 49 +++++++++++++++++++----------- 2 files changed, 67 insertions(+), 34 deletions(-) diff --git a/public/assets/scaffolding-min.js b/public/assets/scaffolding-min.js index d0f3343..2220f34 100644 --- a/public/assets/scaffolding-min.js +++ b/public/assets/scaffolding-min.js @@ -75,22 +75,23 @@ var showMessage = function showMessage(m, s) { status.remove(); }, 1000); }; -var oneClickSelect = function oneClickSelect(e) { - var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 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 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(); +// } +// } + var getURLVars = function getURLVars() { var oResult = {}; if (location.search.length > 0) { @@ -148,6 +149,23 @@ module.exports = { module.exports.cookie.set(cname, "", -1); } }, + oneClickSelect: function oneClickSelect(e) { + var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : e.currentTarget; + // In here, "this" is the element + alert("here"); + 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(); + } + }, colour: { copy: function copy(w, t) { var c = t.parentNode.getAttribute("data-" + (w == "var" ? "token" : w)); @@ -243,7 +261,7 @@ module.exports = { Prism.highlightAll(); a.querySelectorAll("code").forEach(function (c) { c.onclick = function (e) { - oneClickSelect(e); + module.exports.oneClickSelect(e); }; }); module.exports.colour.positionTooltip(); diff --git a/src/js/core/_core.js b/src/js/core/_core.js index bc3438f..49d34e0 100644 --- a/src/js/core/_core.js +++ b/src/js/core/_core.js @@ -71,21 +71,21 @@ const showMessage = (m, s) => { }, 1000); } -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 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 = {}; @@ -149,8 +149,23 @@ module.exports = { module.exports.cookie.set(cname, "", -1); }, }, + oneClickSelect: (e, t = e.currentTarget) => { + // In here, "this" is the element + alert("here"); + 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(); + } + }, colour: { - copy: (w, t) => { let c = t.parentNode.getAttribute("data-" + (w=="var" ? "token" : w)); c = w == "var" ? `var(${c})` : c; @@ -255,7 +270,7 @@ module.exports = { a.querySelectorAll("code").forEach((c)=> { c.onclick = (e) => { - oneClickSelect(e); + module.exports.oneClickSelect(e); } })