setup() {
this.container = this.$refs.container;
this.tabs = this.$manyRefs.tab;
+ this.sidebarScrollContainers = this.$manyRefs.sidebarScrollContainer;
this.lastLayoutType = 'none';
this.onDestroy = null;
// Watch layout changes
this.updateLayout();
- window.addEventListener('resize', event => {
+ window.addEventListener('resize', () => {
this.updateLayout();
}, {passive: true});
+
+ this.setupSidebarScrollHandlers();
}
updateLayout() {
let newLayout = 'tablet';
if (window.innerWidth <= 1000) newLayout = 'mobile';
- if (window.innerWidth >= 1400) newLayout = 'desktop';
+ if (window.innerWidth > 1400) newLayout = 'desktop';
if (newLayout === this.lastLayoutType) return;
if (this.onDestroy) {
this.lastTabShown = tabName;
}
+ setupSidebarScrollHandlers() {
+ for (const sidebar of this.sidebarScrollContainers) {
+ sidebar.addEventListener('scroll', () => this.handleSidebarScroll(sidebar), {
+ passive: true,
+ });
+ this.handleSidebarScroll(sidebar);
+ }
+
+ window.addEventListener('resize', () => {
+ for (const sidebar of this.sidebarScrollContainers) {
+ this.handleSidebarScroll(sidebar);
+ }
+ });
+ }
+
+ handleSidebarScroll(sidebar) {
+ const scrollable = sidebar.clientHeight !== sidebar.scrollHeight;
+ const atTop = sidebar.scrollTop === 0;
+ const atBottom = (sidebar.scrollTop + sidebar.clientHeight) === sidebar.scrollHeight;
+
+ sidebar.parentElement.classList.toggle('scroll-away-from-top', !atTop && scrollable);
+ sidebar.parentElement.classList.toggle('scroll-away-from-bottom', !atBottom && scrollable);
+ }
+
}