Fixed recognition of matching control buttons
authorAlexander Ebert <ebert@woltlab.com>
Fri, 6 Jan 2017 16:31:13 +0000 (17:31 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 6 Jan 2017 16:31:13 +0000 (17:31 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Bbcode/Collapsible.js

index a2e4994cfcf69039bcf04178806ed1ca1b5bffdd..a30b3d25abb6a15be728ac73285441bec492e9c0 100644 (file)
@@ -20,8 +20,16 @@ define([], function() {
                        while (_containers.length) {
                                container = _containers[0];
                                
-                               toggleButton = elBySelAll('.toggleButton', container)[0];
-                               if (toggleButton && toggleButton.closest('.jsCollapsibleBbcode') === container) {
+                               // find the matching toggle button
+                               toggleButton = null;
+                               elBySelAll('.toggleButton:not(.jsToggleButtonEnabled)', container, function (button) {
+                                       //noinspection JSReferencingMutableVariableFromClosure
+                                       if (button.closest('.jsCollapsibleBbcode') === container) {
+                                               toggleButton = button;
+                                       }
+                               });
+                               
+                               if (toggleButton) {
                                        (function (container, toggleButton) {
                                                var toggle = function (event) {
                                                        if (container.classList.toggle('collapsed')) {
@@ -42,6 +50,7 @@ define([], function() {
                                                        }
                                                };
                                                
+                                               toggleButton.classList.add('jsToggleButtonEnabled');
                                                toggleButton.addEventListener(WCF_CLICK_EVENT, toggle);
                                                
                                                // expand boxes that are initially scrolled