7 this.lastLayoutType = 'none';
13 this.lastTabShown = 'content';
16 this.mobileTabClick = this.mobileTabClick.bind(this);
18 // Watch layout changes
20 window.addEventListener('resize', event => {
26 let newLayout = 'tablet';
27 if (window.innerWidth <= 1000) newLayout = 'mobile';
28 if (window.innerWidth >= 1400) newLayout = 'desktop';
29 if (newLayout === this.lastLayoutType) return;
33 this.onDestroy = null;
36 if (newLayout === 'desktop') {
38 } else if (newLayout === 'mobile') {
42 this.lastLayoutType = newLayout;
46 const layoutTabs = document.querySelectorAll('[tri-layout-mobile-tab]');
47 for (let tab of layoutTabs) {
48 tab.addEventListener('click', this.mobileTabClick);
51 this.onDestroy = () => {
52 for (let tab of layoutTabs) {
53 tab.removeEventListener('click', this.mobileTabClick);
64 * Action to run when the mobile info toggle bar is clicked/tapped
67 mobileTabClick(event) {
68 const tab = event.target.getAttribute('tri-layout-mobile-tab');
73 * Show the content tab.
74 * Used by the page-display component.
77 this.showTab('content', false);
84 showTab(tabName, scroll = true) {
85 this.scrollCache[this.lastTabShown] = document.documentElement.scrollTop;
88 const tabs = document.querySelectorAll('.tri-layout-mobile-tab');
89 for (let tab of tabs) {
90 const isActive = (tab.getAttribute('tri-layout-mobile-tab') === tabName);
91 tab.classList.toggle('active', isActive);
95 const showInfo = (tabName === 'info');
96 this.elem.classList.toggle('show-info', showInfo);
98 // Set the scroll position from cache
100 const pageHeader = document.querySelector('header');
101 const defaultScrollTop = pageHeader.getBoundingClientRect().bottom;
102 document.documentElement.scrollTop = this.scrollCache[tabName] || defaultScrollTop;
104 document.documentElement.scrollTop = this.scrollCache[tabName] || defaultScrollTop;
108 this.lastTabShown = tabName;
113 export default TriLayout;