1 import {Component} from "./component";
3 export class TriLayout extends Component {
6 this.container = this.$refs.container;
7 this.tabs = this.$manyRefs.tab;
9 this.lastLayoutType = 'none';
10 this.onDestroy = null;
15 this.lastTabShown = 'content';
18 this.mobileTabClick = this.mobileTabClick.bind(this);
20 // Watch layout changes
22 window.addEventListener('resize', event => {
28 let newLayout = 'tablet';
29 if (window.innerWidth <= 1000) newLayout = 'mobile';
30 if (window.innerWidth >= 1400) newLayout = 'desktop';
31 if (newLayout === this.lastLayoutType) return;
35 this.onDestroy = null;
38 if (newLayout === 'desktop') {
40 } else if (newLayout === 'mobile') {
44 this.lastLayoutType = newLayout;
48 for (const tab of this.tabs) {
49 tab.addEventListener('click', this.mobileTabClick);
52 this.onDestroy = () => {
53 for (const tab of this.tabs) {
54 tab.removeEventListener('click', this.mobileTabClick);
65 * Action to run when the mobile info toggle bar is clicked/tapped
68 mobileTabClick(event) {
69 const tab = event.target.dataset.tab;
74 * Show the content tab.
75 * Used by the page-display component.
78 this.showTab('content', false);
83 * @param {String} tabName
84 * @param {Boolean }scroll
86 showTab(tabName, scroll = true) {
87 this.scrollCache[this.lastTabShown] = document.documentElement.scrollTop;
90 for (const tab of this.tabs) {
91 const isActive = (tab.dataset.tab === tabName);
92 tab.setAttribute('aria-selected', isActive ? 'true' : 'false');
96 const showInfo = (tabName === 'info');
97 this.container.classList.toggle('show-info', showInfo);
99 // Set the scroll position from cache
101 const pageHeader = document.querySelector('header');
102 const defaultScrollTop = pageHeader.getBoundingClientRect().bottom;
103 document.documentElement.scrollTop = this.scrollCache[tabName] || defaultScrollTop;
105 document.documentElement.scrollTop = this.scrollCache[tabName] || defaultScrollTop;
109 this.lastTabShown = tabName;