class Navigation { static initialize() { Navigation.allSubviews = [ ]; Navigation.element = document.body.querySelector("tab-bar"); //Process the tab bar like a view controller. UIKit.processViewControllerElement(Navigation.element, Navigation); Navigation.barItems = document.body.querySelectorAll("tab-bar bar-button-item:not(.user-menu-button)"); for (var i = 0; i < Navigation.barItems.length; i++) { Navigation.barItems[i].addEventListener("click", Navigation.onBarItemSelected); } Navigation.onHashChanged(); } /** * Hides all elements from the navigation that should not be visible on the login screen. */ static displayForLogin() { Navigation.element.classList.add("login-view"); } /** * Shows all elements again that were not visible on the login screen. */ static endDisplayForLogin() { Navigation.element.classList.remove("login-view"); } static onHashChanged(event) { var hash = window.location.hash; for (var i = 0; i < Navigation.barItems.length; i++) { var item = Navigation.barItems[i]; if (item.getAttribute("target") == hash) { if (item.className.indexOf("active") == -1) { item.classList.add("active"); } } else { item.classList.remove("active"); } } } static onBarItemSelected(event) { var target = event.currentTarget.getAttribute("target"); if (!target) { return; } if (target.startsWith("#")) { window.location.hash = target; return; } } static onUserIconClicked(event) { var userMenu = UIKit.getPopoverById("user-menu"); //Inform the context menu about the summoning view controller and view. userMenu.setViewController(Navigation); //userMenu.setView(Navigation); userMenu.showForElement(event.currentTarget, "right"); event.stopPropagation(); } static onLogOutMenuItemPressed(event) { Authentication.logOut(); } } window.addEventListener("hashchange", Navigation.onHashChanged);