6 this.middle = elem.querySelector('.tri-layout-middle');
7 this.right = elem.querySelector('.tri-layout-right');
8 this.left = elem.querySelector('.tri-layout-left');
10 this.lastLayoutType = 'none';
11 this.onDestroy = null;
15 window.addEventListener('resize', event => {
21 const newLayout = (window.innerWidth <= 1000) ? 'mobile' : 'desktop';
22 if (newLayout === this.lastLayoutType) return;
26 this.onDestroy = null;
29 if (newLayout === 'desktop') {
35 this.lastLayoutType = newLayout;
39 const mobileSidebarClickBound = this.mobileSidebarClick.bind(this);
40 const mobileContentClickBound = this.mobileContentClick.bind(this);
41 this.left.addEventListener('click', mobileSidebarClickBound);
42 this.right.addEventListener('click', mobileSidebarClickBound);
43 this.middle.addEventListener('click', mobileContentClickBound);
45 this.onDestroy = () => {
46 this.left.removeEventListener('click', mobileSidebarClickBound);
47 this.right.removeEventListener('click', mobileSidebarClickBound);
48 this.middle.removeEventListener('click', mobileContentClickBound);
57 * Slide the main content back into view if clicked and
58 * currently slid out of view.
61 mobileContentClick(event) {
62 this.elem.classList.remove('mobile-open');
66 * On sidebar click, Show the content by sliding the main content out.
69 mobileSidebarClick(event) {
70 if (this.elem.classList.contains('mobile-open')) {
71 this.elem.classList.remove('mobile-open');
73 event.preventDefault();
74 event.stopPropagation();
75 this.elem.classList.add('mobile-open');
81 export default TriLayout;