From 92b5c0a5cb0f013d8cc15f2aca3f441a918ffaa6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 3 Jun 2020 17:46:46 +0200 Subject: [PATCH] Support multiple toggle buttons in WoltLabSuite/Core/Bbcode/Collapsible --- .../WoltLabSuite/Core/Bbcode/Collapsible.js | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Bbcode/Collapsible.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Bbcode/Collapsible.js index 8002ae63db..64027a42b8 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Bbcode/Collapsible.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Bbcode/Collapsible.js @@ -16,24 +16,26 @@ define([], function() { */ return { observe: function() { - var container, toggleButton; + var container, toggleButtons; while (_containers.length) { container = _containers[0]; // find the matching toggle button - toggleButton = null; + toggleButtons = []; elBySelAll('.toggleButton:not(.jsToggleButtonEnabled)', container, function (button) { //noinspection JSReferencingMutableVariableFromClosure if (button.closest('.jsCollapsibleBbcode') === container) { - toggleButton = button; + toggleButtons.push(button); } }); - if (toggleButton) { - (function (container, toggleButton) { + if (toggleButtons.length > 0) { + (function (container, toggleButtons) { var toggle = function (event) { if (container.classList.toggle('collapsed')) { - toggleButton.textContent = elData(toggleButton, 'title-expand'); + toggleButtons.forEach(function (toggleButton) { + toggleButton.textContent = elData(toggleButton, 'title-expand'); + }); if (event instanceof Event) { // negative top value means the upper boundary is not within the viewport @@ -46,12 +48,16 @@ define([], function() { } } else { - toggleButton.textContent = elData(toggleButton, 'title-collapse'); + toggleButtons.forEach(function (toggleButton) { + toggleButton.textContent = elData(toggleButton, 'title-collapse'); + }); } }; - toggleButton.classList.add('jsToggleButtonEnabled'); - toggleButton.addEventListener(WCF_CLICK_EVENT, toggle); + toggleButtons.forEach(function (toggleButton) { + toggleButton.classList.add('jsToggleButtonEnabled'); + toggleButton.addEventListener(WCF_CLICK_EVENT, toggle); + }); // expand boxes that are initially scrolled if (container.scrollTop !== 0) { @@ -62,7 +68,7 @@ define([], function() { toggle(); } }); - })(container, toggleButton); + })(container, toggleButtons); } container.classList.remove('jsCollapsibleBbcode'); -- 2.20.1