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');
69 this.scrollCache[this.lastTabShown] = document.documentElement.scrollTop;
72 const activeTabs = document.querySelectorAll('.tri-layout-mobile-tab.active');
73 for (let tab of activeTabs) {
74 tab.classList.remove('active');
76 event.target.classList.add('active');
79 const showInfo = (tab === 'info');
80 this.elem.classList.toggle('show-info', showInfo);
82 // Set the scroll position from cache
83 const pageHeader = document.querySelector('header');
84 const defaultScrollTop = pageHeader.getBoundingClientRect().bottom;
85 document.documentElement.scrollTop = this.scrollCache[tab] || defaultScrollTop;
87 document.documentElement.scrollTop = this.scrollCache[tab] || defaultScrollTop;
90 this.lastTabShown = tab;
95 export default TriLayout;