-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
157 lines (129 loc) · 4.99 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
"use strict";
var AYR = AYR || {};
(function(){
// Cache DOM elements for future use
var mainContent = document.querySelector('main');
var loader = document.querySelector('.loader-wrapper');
var menuBtn = document.querySelector('.menu-btn');
var siteNav = document.querySelector('.site-nav');
var siteHeader = document.querySelector('.site-header');
var last_known_scroll_position = 0;
var ticking = false;
// If ontouchstart exists then set click handler to touchstart otherwise set clickhandler to click
var clickHandler = ('ontouchstart' in document.documentElement ? "touchstart" : "click");
/**************************************/
/* Application Object
/***************************************************/
AYR = {
currPageName:"",
contentElement: {},
init: function () {
console.log('init');
/**************************************/
/* Mobile Navigation Trigger
/***************************************************/
menuBtn.addEventListener(clickHandler, function(e) {
this.classList.toggle('active');
siteNav.classList.toggle('active');
siteHeader.classList.toggle('mobile-active');
});
/**************************************/
/* Window Scroll
/***************************************************/
// Reference: https://developer.mozilla.org/en-US/docs/Web/Events/scroll
// Reference: http://www.html5rocks.com/en/tutorials/speed/animations/
// function doSomething(scroll_pos) {
// if(ayrApi.isMobile() === false) {
// if(last_known_scroll_position >= 100 ){
// siteHeader.classList.add('small');
// }else{
// siteHeader.classList.remove('small');
// }
// }
// }
// window.addEventListener('scroll', function(e) {
// var scrollTop = window.pageYOffset || document.documentElement.scrollTop;
// last_known_scroll_position = scrollTop;
// if (!ticking) {
// window.requestAnimationFrame(function() {
// doSomething(last_known_scroll_position);
// ticking = false;
// });
// }
// ticking = true;
// });
/**************************************/
/* Window Load
/***************************************************/
window.onload = function (e,afterPages) {
ayrApi.toTop();
}
/**************************************/
/* Window Resize
/***************************************************/
// Reference: https://developer.mozilla.org/en-US/docs/Web/Events/resize
var optimizedResize = (function() {
var callbacks = [],
running = false;
// fired on resize event
function resize() {
if (!running) {
running = true;
if (window.requestAnimationFrame) {
window.requestAnimationFrame(runCallbacks);
} else {
setTimeout(runCallbacks, 66);
}
}
}
// run the actual callbacks
function runCallbacks() {
callbacks.forEach(function(callback) {
callback();
});
running = false;
}
// adds callback to loop
function addCallback(callback) {
if (callback) {
callbacks.push(callback);
}
}
return {
// public method to add additional callback
add: function(callback) {
if (!callbacks.length) {
window.addEventListener('resize', resize);
}
addCallback(callback);
}
}
}());
// start process
// optimizedResize.add(function() {
// if(ayrApi.isMobile()){
// siteHeader.classList.remove('small');
// } else {
// if(last_known_scroll_position >= 100 ){
// siteHeader.classList.add('small');
// }else{
// siteHeader.classList.remove('small');
// }
// }
// // Resize Content Display Wrapper based on new height of content on resize
// contentDisplayWrapper.style.height = document.querySelector('.content-pages > .' + AYR.currPageName + '-page').offsetHeight + 'px';
// });
}, // End Init
collapseMobileNav: function() {
// Collapse Mobile Nav When navigation link is clicked in mobile view
if(ayrApi.hasClass(siteNav, 'active')){
siteNav.classList.remove('active');
menuBtn.classList.remove('active');
}
if(ayrApi.hasClass(siteHeader, 'mobile-active')){
siteHeader.classList.remove('mobile-active');
}
}
};
})(); // End Self Evoking Function
AYR.init();