Fixed auto-opening collapsed bbcodes on initial scroll
authorAlexander Ebert <ebert@woltlab.com>
Sun, 18 Sep 2016 11:12:34 +0000 (13:12 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 18 Sep 2016 11:12:43 +0000 (13:12 +0200)
wcfsetup/install/files/js/WoltLabSuite/Core/Bbcode/Collapsible.js

index 464372e2222486e46886864a5b8e8a91abdac263..c351868d2ba1c4c7ddf3b012f7db2dc989c14f6d 100644 (file)
@@ -27,16 +27,18 @@ define([], function() {
                                }
                                
                                (function(container, toggleButton) {
-                                       var toggle = function() {
+                                       var toggle = function(event) {
                                                if (container.classList.toggle('collapsed')) {
                                                        toggleButton.textContent = elData(toggleButton, 'title-expand');
                                                        
-                                                       // 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 (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 {
@@ -46,14 +48,6 @@ define([], function() {
                                        
                                        toggleButton.addEventListener(WCF_CLICK_EVENT, toggle);
                                        
-                                       // searching in a page causes Google Chrome to scroll
-                                       // the box if something inside it matches
-                                       // 
-                                       // expand the box in this case, to:
-                                       // a) Improve UX
-                                       // b) Hide an ugly misplaced "show all" button
-                                       container.addEventListener('scroll', toggle);
-                                       
                                        // expand boxes that are initially scrolled
                                        if (container.scrollTop !== 0) {
                                                toggle();