blob: f50fe79fac1f16583e725d97ad5715aba63042b9 [file] [log] [blame]
Michael Davis19475752017-02-23 18:30:23 -06001(function () {
Michael Daviscb8bb192017-02-09 15:45:13 -06002
3 // Init functions
4 header();
5 nav();
6
7 // Load logo
Michael Davis19475752017-02-23 18:30:23 -06008 function loadLogo() {
9 $('.logo__wrapper').load('logo.html', function () {
Michael Daviscb8bb192017-02-09 15:45:13 -060010
11 // Grab logo if has ID or not
12 var logoID = document.getElementById("header__logo");
13 var logo = document.querySelectorAll("img, svg");
14
15 // Has ID - call header height
Michael Davis19475752017-02-23 18:30:23 -060016 if (logoID && logoID !== null) {
Michael Daviscb8bb192017-02-09 15:45:13 -060017 getHeaderHeight();
18
Michael Davis19475752017-02-23 18:30:23 -060019 // If logo exists but no ID - call header height
20 } else if (logo !== null && logo.length == 1) {
21 $('img, svg').on('load', function () {
22 getHeaderHeight();
23 });
Michael Daviscb8bb192017-02-09 15:45:13 -060024
Michael Davis19475752017-02-23 18:30:23 -060025 // If no logo at all - call header height
26 } else {
27 getHeaderHeight();
28 }
Michael Daviscb8bb192017-02-09 15:45:13 -060029 });
30 }
31
32 // Get header height
33 function getHeaderHeight() {
34 // Get header height after logo is loaded
35 var header = document.getElementById("header__wrapper");
36 var headerHeight = header.offsetHeight;
37
38 // Add body padding to compensate for fixed header
39 document.body.style.paddingTop = headerHeight + 'px';
40
41 nav(headerHeight);
42 }
Michael Davis19475752017-02-23 18:30:23 -060043
Michael Daviscb8bb192017-02-09 15:45:13 -060044 // Include header
45 function header() {
46 $('#header__wrapper').load('header.html', function () {
47
48 // include logo into header
49 loadLogo();
50 })
51 }
52
53 // load navigation - pass in header height
54 function nav(height) {
55 $('#navigation').load('navigation.html', function (headerHeight) {
56
57 var nav = document.getElementById("nav__top-level");
Michael Daviscb8bb192017-02-09 15:45:13 -060058 var subnav = document.getElementsByClassName("nav__second-level");
59 var navBtn = document.querySelectorAll('#nav__top-level button');
60
Michael Daviscb8bb192017-02-09 15:45:13 -060061
62 // Bump down nav to compensate for fixed header
63 nav.style.top = height + 'px';
64
65 // Bump second level nav down for fixed header
66 for (var i = 0; i < subnav.length; i++) {
67 subnav[i].style.top = height + 'px';
68 }
69
Michael Davis19475752017-02-23 18:30:23 -060070 //Loop over nav buttons
Michael Daviscb8bb192017-02-09 15:45:13 -060071 for (var i = 0, len = navBtn.length; i < len; i++) {
72
73 // Click event for each nav button
Michael Davis19475752017-02-23 18:30:23 -060074 navBtn[i].addEventListener('click', function () {
Michael Daviscb8bb192017-02-09 15:45:13 -060075 var parent = $(this).parents("#navigation");
76 var btnId = $(this).attr("class").match(/btn[\w-]*\b/);
77 var subnavClass = $('.nav__second-level.' + btnId);
78
Michael Davis19475752017-02-23 18:30:23 -060079 //Remove opened class from buttons
Michael Daviscb8bb192017-02-09 15:45:13 -060080 parent.find('.opened').removeClass('opened');
81
82 // Add opened class to clicked button
83 this.classList.add("opened");
84
Michael Davis19475752017-02-23 18:30:23 -060085 //Close all sub panels and remove opened class
86 parent.find('.nav__second-level').css("display", "none").removeClass('opened');
Michael Daviscb8bb192017-02-09 15:45:13 -060087
Michael Davis19475752017-02-23 18:30:23 -060088 //Open sub panels that matches clicked button and add opened class
89 parent.find(subnavClass).css("display", "block").addClass('opened');
90
91 // var pgurl = window.location.href.substr(window.location.href.lastIndexOf("/")+1);
92 //
93 // $('.nav__second-level a').each(function(){
94 // console.log(pgurl);
95 // if($(this).attr("href") == pgurl || $(this).attr("href") == '' )
96 // $('.nav__second-level li').addClass("active");
97 // })
98 });
Michael Daviscb8bb192017-02-09 15:45:13 -060099
100 }
Michael Daviscb8bb192017-02-09 15:45:13 -0600101 });
102 }
103
104}());