From cee1f78fa951aa1214c375cf40d272473f4908c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Tue, 22 Oct 2024 11:35:54 +0200 Subject: [PATCH] feat: auto-collapse teasers on travel info pages --- .../js/controllers/autocollapse_controller.js | 44 +++++++++++++++++++ .../Private/Templates/Travelinfo/Index.html | 41 +++++++++++++---- 2 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/controllers/autocollapse_controller.js diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/controllers/autocollapse_controller.js b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/controllers/autocollapse_controller.js new file mode 100644 index 00000000..f7a0bbbb --- /dev/null +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Assets/js/controllers/autocollapse_controller.js @@ -0,0 +1,44 @@ +import { Controller } from '@hotwired/stimulus' + +export default class extends Controller { + + static targets = [ 'sizer', 'container', 'button' ] + + static values = { + offset: { + type: Number, + default: 0, + }, + expanded: { + type: Boolean, + default: true, + } + } + + connect() { + // Determine height of element controlling max height + this.maxHeight = this.sizerTarget.offsetHeight + // Determine rendered height of element holding content + + this.contentHeight = this.containerTarget.offsetHeight + + // Determine height of collapsed content element considering + // potential offset for button + this.collapsedHeight = this.maxHeight - this.offsetValue + + // Set initial expanded/collapsed status and button visibility + this.expandedValue = this.contentHeight < this.maxHeight + this.buttonTarget.classList.toggle('hidden', this.expandedValue) + } + + toggle() { + this.expandedValue = !this.expandedValue + } + + expandedValueChanged(expanded) { + this.containerTarget.style.height = expanded ? 'auto' : `${this.collapsedHeight}px` + this.containerTarget.style.overflowY = expanded ? 'none' : 'hidden' + this.buttonTarget.classList.toggle('toggle-more', false === expanded) + this.buttonTarget.classList.toggle('toggle-less', expanded) + } +} diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Travelinfo/Index.html b/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Travelinfo/Index.html index 994afc45..83d29d01 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Travelinfo/Index.html +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Templates/Travelinfo/Index.html @@ -97,8 +97,10 @@
-
-
+
+
@@ -106,12 +108,24 @@
-
-

- {teaser.title} -

- {teaser.bodytext -> f:format.html()} -
+
+
+

+ {teaser.title} +

+ {teaser.bodytext -> f:format.html()} +
+
+ +
+
@@ -253,6 +267,17 @@ + + + + + + + + + + +