Scroll to tab menu if it was scrolled out of view
authorAlexander Ebert <ebert@woltlab.com>
Sun, 15 Jan 2017 18:48:57 +0000 (19:48 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 15 Jan 2017 18:48:57 +0000 (19:48 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/TabMenu.js

index 7c24ec81ba750787f0a2ce1e59c123664d06eed3..16e6a2076b767646f22ce54b79d9b2c7d025d933 100644 (file)
@@ -12,7 +12,6 @@ define(['Dictionary', 'EventHandler', 'Dom/ChangeListener', 'Dom/Util', 'Ui/Clos
        var _activeList = null;
        var _enableTabScroll = false;
        var _tabMenus = new Dictionary();
-       var _scrollListenerUuid = null;
        
        /**
         * @exports     WoltLabSuite/Core/Ui/TabMenu
@@ -52,6 +51,35 @@ define(['Dictionary', 'EventHandler', 'Dom/ChangeListener', 'Dom/Util', 'Ui/Clos
                                        });
                                }
                        });
+                       
+                       if (window.location.hash.match(/^#(.*)$/)) {
+                               var hash = RegExp.$1;
+                               window.setTimeout(function () {
+                                       // check if page was initially scrolled using a tab id
+                                       var tabMenuContent = elById(hash);
+                                       if (tabMenuContent && tabMenuContent.classList.contains('tabMenuContent')) {
+                                               var scrollY = (window.scrollY || window.pageYOffset);
+                                               if (scrollY > 0) {
+                                                       var parent = tabMenuContent.parentNode;
+                                                       var offsetTop = parent.offsetTop - 50;
+                                                       if (offsetTop < 0) offsetTop = 0;
+                                                       
+                                                       if (scrollY > offsetTop) {
+                                                               var y = DomUtil.offset(parent).top;
+                                                               
+                                                               if (y <= 50) {
+                                                                       y = 0;
+                                                               }
+                                                               else {
+                                                                       y -= 50;
+                                                               }
+                                                               
+                                                               window.scrollTo(0, y);
+                                                       }
+                                               }
+                                       }
+                               }, 100);
+                       }
                },
                
                /**