From 96ef1fa842739f7f1b0f546c54e0879864d18ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georg=20Mai=C3=9Fer?= Date: Tue, 26 Nov 2024 14:34:55 +0100 Subject: [PATCH] Bugfix: Make selector more restrictive --- amd/build/anchor.min.js | 2 +- amd/build/anchor.min.js.map | 2 +- amd/src/anchor.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/amd/build/anchor.min.js b/amd/build/anchor.min.js index f40455f..0e0772c 100644 --- a/amd/build/anchor.min.js +++ b/amd/build/anchor.min.js @@ -1,3 +1,3 @@ -define("local_wb_news/anchor",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0;_exports.init=()=>{console.log("anchor loaded");const hash=window.location.hash;if(hash){const targetElement=document.querySelector(hash);targetElement&&targetElement.classList.contains("collapse")&&targetElement.classList.add("show")}document.querySelectorAll('a[href^="#"]').forEach((anchor=>{anchor.addEventListener("click",(e=>{const target=document.querySelector(e.currentTarget.getAttribute("href"));target&&target.classList.contains("collapse")&&(target.style.display="block"===target.style.display?"none":"block")}))}))}})); +define("local_wb_news/anchor",["exports"],(function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0;_exports.init=()=>{console.log("anchor loaded");const hash=window.location.hash;if(hash){const targetElement=document.querySelector(hash);targetElement&&targetElement.classList.contains("collapse")&&targetElement.classList.add("show")}document.querySelectorAll('#page-local-wb_news-index a[href^="#"]').forEach((anchor=>{anchor.addEventListener("click",(e=>{const target=document.querySelector(e.currentTarget.getAttribute("href"));target&&target.classList.contains("collapse")&&(target.style.display="block"===target.style.display?"none":"block")}))}))}})); //# sourceMappingURL=anchor.min.js.map \ No newline at end of file diff --git a/amd/build/anchor.min.js.map b/amd/build/anchor.min.js.map index edb2083..15dabd6 100644 --- a/amd/build/anchor.min.js.map +++ b/amd/build/anchor.min.js.map @@ -1 +1 @@ -{"version":3,"file":"anchor.min.js","sources":["../src/anchor.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/*\n * @package local_wb_news\n * @copyright Wunderbyte GmbH \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nexport const init = () => {\n // eslint-disable-next-line no-console\n console.log('anchor loaded');\n // Get the anchor from the URL (e.g., #instance-1)\n const hash = window.location.hash;\n\n if (hash) {\n // Select the element with the id matching the hash\n const targetElement = document.querySelector(hash);\n if (targetElement && targetElement.classList.contains('collapse')) {\n // Show the element by changing its display style\n targetElement.classList.add('show');\n }\n }\n\n // Optional: Toggle collapse on clicking the anchor link\n document.querySelectorAll('a[href^=\"#\"]').forEach(anchor => {\n anchor.addEventListener(\"click\", (e) => {\n const target = document.querySelector(e.currentTarget.getAttribute(\"href\"));\n if (target && target.classList.contains(\"collapse\")) {\n // Toggle the display property\n target.style.display = target.style.display === \"block\" ? \"none\" : \"block\";\n }\n });\n });\n};\n"],"names":["console","log","hash","window","location","targetElement","document","querySelector","classList","contains","add","querySelectorAll","forEach","anchor","addEventListener","e","target","currentTarget","getAttribute","style","display"],"mappings":"yJAoBoB,KAEhBA,QAAQC,IAAI,uBAENC,KAAOC,OAAOC,SAASF,QAEzBA,KAAM,OAEAG,cAAgBC,SAASC,cAAcL,MACzCG,eAAiBA,cAAcG,UAAUC,SAAS,aAElDJ,cAAcG,UAAUE,IAAI,QAKpCJ,SAASK,iBAAiB,gBAAgBC,SAAQC,SAC9CA,OAAOC,iBAAiB,SAAUC,UACxBC,OAASV,SAASC,cAAcQ,EAAEE,cAAcC,aAAa,SAC/DF,QAAUA,OAAOR,UAAUC,SAAS,cAEpCO,OAAOG,MAAMC,QAAmC,UAAzBJ,OAAOG,MAAMC,QAAsB,OAAS"} \ No newline at end of file +{"version":3,"file":"anchor.min.js","sources":["../src/anchor.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/*\n * @package local_wb_news\n * @copyright Wunderbyte GmbH \n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nexport const init = () => {\n // eslint-disable-next-line no-console\n console.log('anchor loaded');\n // Get the anchor from the URL (e.g., #instance-1)\n const hash = window.location.hash;\n\n if (hash) {\n // Select the element with the id matching the hash\n const targetElement = document.querySelector(hash);\n if (targetElement && targetElement.classList.contains('collapse')) {\n // Show the element by changing its display style\n targetElement.classList.add('show');\n }\n }\n\n // Optional: Toggle collapse on clicking the anchor link\n document.querySelectorAll('#page-local-wb_news-index a[href^=\"#\"]').forEach(anchor => {\n anchor.addEventListener(\"click\", (e) => {\n const target = document.querySelector(e.currentTarget.getAttribute(\"href\"));\n if (target && target.classList.contains(\"collapse\")) {\n // Toggle the display property\n target.style.display = target.style.display === \"block\" ? \"none\" : \"block\";\n }\n });\n });\n};\n"],"names":["console","log","hash","window","location","targetElement","document","querySelector","classList","contains","add","querySelectorAll","forEach","anchor","addEventListener","e","target","currentTarget","getAttribute","style","display"],"mappings":"yJAoBoB,KAEhBA,QAAQC,IAAI,uBAENC,KAAOC,OAAOC,SAASF,QAEzBA,KAAM,OAEAG,cAAgBC,SAASC,cAAcL,MACzCG,eAAiBA,cAAcG,UAAUC,SAAS,aAElDJ,cAAcG,UAAUE,IAAI,QAKpCJ,SAASK,iBAAiB,0CAA0CC,SAAQC,SACxEA,OAAOC,iBAAiB,SAAUC,UACxBC,OAASV,SAASC,cAAcQ,EAAEE,cAAcC,aAAa,SAC/DF,QAAUA,OAAOR,UAAUC,SAAS,cAEpCO,OAAOG,MAAMC,QAAmC,UAAzBJ,OAAOG,MAAMC,QAAsB,OAAS"} \ No newline at end of file diff --git a/amd/src/anchor.js b/amd/src/anchor.js index 52e5c1a..6ea63b6 100644 --- a/amd/src/anchor.js +++ b/amd/src/anchor.js @@ -34,7 +34,7 @@ export const init = () => { } // Optional: Toggle collapse on clicking the anchor link - document.querySelectorAll('a[href^="#"]').forEach(anchor => { + document.querySelectorAll('#page-local-wb_news-index a[href^="#"]').forEach(anchor => { anchor.addEventListener("click", (e) => { const target = document.querySelector(e.currentTarget.getAttribute("href")); if (target && target.classList.contains("collapse")) {