5 this.container = this.$refs.container;
6 this.tabs = this.$manyRefs.tab;
8 this.lastLayoutType = 'none';
14 this.lastTabShown = 'content';
17 this.mobileTabClick = this.mobileTabClick.bind(this);
19 // Watch layout changes
21 window.addEventListener('resize', event => {
27 let newLayout = 'tablet';
28 if (window.innerWidth <= 1000) newLayout = 'mobile';
29 if (window.innerWidth >= 1400) newLayout = 'desktop';
30 if (newLayout === this.lastLayoutType) return;
34 this.onDestroy = null;
37 if (newLayout === 'desktop') {
39 } else if (newLayout === 'mobile') {
43 this.lastLayoutType = newLayout;
47 for (const tab of this.tabs) {
48 tab.addEventListener('click', this.mobileTabClick);
51 this.onDestroy = () => {
52 for (const tab of this.tabs) {
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.dataset.tab;
73 * Show the content tab.
74 * Used by the page-display component.
77 this.showTab('content', false);
82 * @param {String} tabName
83 * @param {Boolean }scroll
85 showTab(tabName, scroll = true) {
86 this.scrollCache[this.lastTabShown] = document.documentElement.scrollTop;
89 for (const tab of this.tabs) {
90 const isActive = (tab.dataset.tab === tabName);
91 tab.setAttribute('aria-selected', isActive ? 'true' : 'false');
95 const showInfo = (tabName === 'info');
96 this.container.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;