From 61706d8651dace14aef8a54d53d17541bb3182db Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Sat, 6 Jan 2018 21:33:54 +0100 Subject: [PATCH] Move script tags to top, run after DOM Ready. --- assets/main.coffee | 46 ++++++++++++++++++++++++---------------------- index_main.php | 4 ++-- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/assets/main.coffee b/assets/main.coffee index ae7a85e..985b0e5 100644 --- a/assets/main.coffee +++ b/assets/main.coffee @@ -1,25 +1,27 @@ -window.mdc.autoInit() -window.tabBar = new mdc.tabs.MDCTabBar document.querySelector '#tab-bar' +document.addEventListener 'DOMContentLoaded', (event) -> -# Hide all panels but the selected one -activatePanel = (panelId) -> - allPanels = document.querySelectorAll '.panel' - for panel, i in allPanels - if panel.id is panelId - tabBar.activeTabIndex = i - panel.style.display = if panel.id is panelId then 'block' else 'none' + window.mdc.autoInit() + window.tabBar = new mdc.tabs.MDCTabBar document.querySelector '#tab-bar' -# React to clicking the tabs -window.tabBar.listen 'MDCTabBar:change', (t) -> - nthChildIndex = t.detail.activeTabIndex - tabId = t.srcElement.id - tab = document.querySelector "##{tabId} .mdc-tab:nth-child(#{nthChildIndex + 1})" - panelId = tab.dataset.panel - activatePanel panelId + # Hide all panels but the selected one + activatePanel = (panelId) -> + allPanels = document.querySelectorAll '.panel' + for panel, i in allPanels + if panel.id is panelId + tabBar.activeTabIndex = i + panel.style.display = if panel.id is panelId then 'block' else 'none' -# If specific tab/panel given in URL, e.g. #motion, switch to that -hash = location.hash -if hash.length > 1 - activatePanel 'family-' + hash.substring 1 -else - activatePanel 'family-keyone' + # React to clicking the tabs + window.tabBar.listen 'MDCTabBar:change', (t) -> + nthChildIndex = t.detail.activeTabIndex + tabId = t.srcElement.id + tab = document.querySelector "##{tabId} .mdc-tab:nth-child(#{nthChildIndex + 1})" + panelId = tab.dataset.panel + activatePanel panelId + + # If specific tab/panel given in URL, e.g. #motion, switch to that + hash = location.hash + if hash.length > 1 + activatePanel 'family-' + hash.substring 1 + else + activatePanel 'family-keyone' diff --git a/index_main.php b/index_main.php index 649f423..4ff1487 100644 --- a/index_main.php +++ b/index_main.php @@ -5,6 +5,8 @@ + + $models) { } ?> - -