Fixed nested collapsible bbcode
authorAlexander Ebert <ebert@woltlab.com>
Fri, 25 Nov 2016 17:00:52 +0000 (18:00 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 25 Nov 2016 17:00:52 +0000 (18:00 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Bbcode/Collapsible.js

index c351868d2ba1c4c7ddf3b012f7db2dc989c14f6d..3a86bf88da2fad47572c1a372e7dded3aa30c2df 100644 (file)
@@ -19,40 +19,43 @@ define([], function() {
                        var container, toggleButton;
                        while (_containers.length) {
                                container = _containers[0];
-                               container.classList.remove('jsCollapsibleBbcode');
                                
-                               toggleButton = elBySel('.toggleButton', container);
-                               if (toggleButton === null) {
+                               toggleButton = elBySelAll('.toggleButton', container)[0];
+                               if (toggleButton === undefined) {
                                        continue;
                                }
                                
-                               (function(container, toggleButton) {
-                                       var toggle = function(event) {
-                                               if (container.classList.toggle('collapsed')) {
-                                                       toggleButton.textContent = elData(toggleButton, 'title-expand');
-                                                       
-                                                       if (event instanceof Event) {
-                                                               // negative top value means the upper boundary is not within the viewport
-                                                               var top = container.getBoundingClientRect().top;
-                                                               if (top < 0) {
-                                                                       var y = window.pageYOffset + (top - 100);
-                                                                       if (y < 0) y = 0;
-                                                                       window.scrollTo(window.pageXOffset, y);
+                               if (toggleButton.closest('.jsCollapsibleBbcode') === container) {
+                                       (function (container, toggleButton) {
+                                               var toggle = function (event) {
+                                                       if (container.classList.toggle('collapsed')) {
+                                                               toggleButton.textContent = elData(toggleButton, 'title-expand');
+                                                               
+                                                               if (event instanceof Event) {
+                                                                       // negative top value means the upper boundary is not within the viewport
+                                                                       var top = container.getBoundingClientRect().top;
+                                                                       if (top < 0) {
+                                                                               var y = window.pageYOffset + (top - 100);
+                                                                               if (y < 0) y = 0;
+                                                                               window.scrollTo(window.pageXOffset, y);
+                                                                       }
                                                                }
                                                        }
+                                                       else {
+                                                               toggleButton.textContent = elData(toggleButton, 'title-collapse');
+                                                       }
+                                               };
+                                               
+                                               toggleButton.addEventListener(WCF_CLICK_EVENT, toggle);
+                                               
+                                               // expand boxes that are initially scrolled
+                                               if (container.scrollTop !== 0) {
+                                                       toggle();
                                                }
-                                               else {
-                                                       toggleButton.textContent = elData(toggleButton, 'title-collapse');
-                                               }
-                                       };
-                                       
-                                       toggleButton.addEventListener(WCF_CLICK_EVENT, toggle);
-                                       
-                                       // expand boxes that are initially scrolled
-                                       if (container.scrollTop !== 0) {
-                                               toggle();
-                                       }
-                               })(container, toggleButton);
+                                       })(container, toggleButton);
+                               }
+                               
+                               container.classList.remove('jsCollapsibleBbcode');
                        }
                }
        };