-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
168 lines (149 loc) · 5.26 KB
/
index.html
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
158
159
160
161
162
163
164
165
166
167
168
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="Description" content="Get real time MTA subway times">
<title>MTA - Subway Time</title>
<link rel="icon" type="image/png" href="./images/icons-48.png">
<link rel="apple-touch-icon" sizes="48x48" href="./images/icons-48.png">
<link rel="apple-touch-icon" sizes="96x96" href="./images/icons-96.png">
<link rel="apple-touch-icon" sizes="192x192" href="./images/icons-192.png">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#223266"/>
<link rel="manifest" href="./manifest.json">
<!-- Google Analytics -->
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-129386476-1', 'auto');
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<!-- End Google Analytics -->
<style>
* {
box-sizing: border-box;
}
html, body {
height: 100%;
width: 100%;
}
body {
transition: transform 0.15s ease-in-out;
font-family: sans-serif;
margin: 0;
padding: 8px;
}
.menu {
position: absolute;
left: 0;
transform: translateX(-100%);
height: 100%;
width: 80%;
font-size: 20px;
display: none;
}
.menu-open {
transform: translateX(80%);
}
.menu-show {
display: block;
}
ul {
list-style: none;
padding: 0;
}
li {
padding: 16px;
}
.main {
width: 100%;
max-height: calc(100% - 112px);
height: 100%;
}
.logo-link {
display: inline-block;
margin-left: auto;
margin-right: auto;
}
.header {
display: flex;
align-items: center;
margin-bottom: 24px;
}
.hamburger {
height: 50px;
width: 50px;
}
</style>
</head>
<body>
<nav class="menu js-menu">
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#subway_map">Subway Map (available offline)</a></li>
</ul>
</nav>
<header class="header">
<button class="js-hamburger hamburger">🍔</button>
<a href="#home" class="logo-link"><h1>MTA Subway Time</h1></a>
</header>
<div class="js-main main"></div>
<script>
const hamburgerButton = document.querySelector(".js-hamburger");
const menu = document.querySelector(".menu")
const menuLinks = menu.querySelectorAll("a");
const firstEle = menuLinks[0];
const lastEle = menuLinks[menuLinks.length - 1];
const TAB_KEY = 9;
const ESCAPE_KEY = 27;
hamburgerButton.addEventListener("click", e => {
e.preventDefault();
document.body.classList.toggle("menu-open");
menu.classList.toggle("menu-show");
firstEle.focus()
});
menu.addEventListener("keydown", trapTabKey)
document.body.addEventListener("click", e => {
if (e.target === hamburgerButton) return;
const isMenuOpen = document.body.classList.contains("menu-open");
if (isMenuOpen) {
document.body.classList.toggle("menu-open");
menu.classList.toggle("menu-show");
}
});
function trapTabKey(e){
if(e.keyCode === TAB_KEY) {
if(e.shiftKey) {
if(document.activeElement === firstEle){
e.preventDefault();
lastEle.focus()
}
} else {
if(document.activeElement === lastEle){
e.preventDefault();
firstEle.focus()
}
}
}
if(e.keyCode === ESCAPE_KEY){
document.body.classList.toggle("menu-open");
menu.classList.toggle("menu-show");
hamburgerButton.focus()
}
}
</script>
<script>
if ("serviceWorker" in navigator) {
window.addEventListener("load", () => {
navigator.serviceWorker.register("./sw.js")
.then(registration => {
console.log("ServiceWorker registration successful");
})
.catch(err => {
console.error(err);
})
})
}
</script>
</body>
</html>