From 1e2de91cf7bf643bc78c65979f0c7d0a7217100d Mon Sep 17 00:00:00 2001 From: Robin Wieschendorf Date: Sat, 30 Dec 2023 18:09:52 +0100 Subject: [PATCH 1/2] feat: add new js script Expandable.js --- src/Templates/Scripts/Expandable.js | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/Templates/Scripts/Expandable.js diff --git a/src/Templates/Scripts/Expandable.js b/src/Templates/Scripts/Expandable.js new file mode 100644 index 0000000..2e4dd71 --- /dev/null +++ b/src/Templates/Scripts/Expandable.js @@ -0,0 +1,34 @@ +const expandables = document.querySelectorAll('.expandable'); + +expandables.forEach(function(expandable) { + const lines = 5; + expandable.style.maxHeight = "calc(1.5em * " + lines + ")"; + expandable.style.overflow = "hidden"; + if (hasOverflow(expandable, lines)) { + addExpandButton(expandable); + } +}); + +function hasOverflow(element, lines) { + if (countBRTags(element) > lines) { + return true; + } + return false; +} + +function addExpandButton(expandable) { + var aTag = document.createElement('a'); + aTag.href = "#" + aTag.addEventListener('click', function(event) { + event.preventDefault(); + aTag.style.display = "none"; + expandable.style.maxHeight = "inherit"; + }); + aTag.innerHTML = 'Alle Versionen anzeigen'; + expandable.insertAdjacentElement('afterend', aTag); +} + +function countBRTags(element) { + var brTags = element.innerHTML.match(/
/g); + return brTags ? brTags.length : 0; +} From 1a40cc973b1012d2a922ebb23156e107047053a3 Mon Sep 17 00:00:00 2001 From: Robin Wieschendorf Date: Sat, 30 Dec 2023 18:10:27 +0100 Subject: [PATCH 2/2] feat: use new script Expandable.js --- src/Templates/Footer.tmpl.php | 1 + src/Templates/ModuleInfo.tmpl.php | 28 +++++++++++++++------------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Templates/Footer.tmpl.php b/src/Templates/Footer.tmpl.php index f94d939..835a1c8 100644 --- a/src/Templates/Footer.tmpl.php +++ b/src/Templates/Footer.tmpl.php @@ -9,6 +9,7 @@ +