-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
87 lines (76 loc) · 3.13 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>konami-code.js demo</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style type="text/css">
* {
user-select: none;
}
body.rotate {
transition: transform 1s ease-in-out;
transform: rotateZ(360deg);
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="jumbotron">
<h1>konami-code.js demo</h1>
<p>
<a href="https://en.wikipedia.org/wiki/Konami_Code" target="_blank">What is the Konami Code?</a>
</p>
<h2>Using keyboard</h2>
<pre>Hit: up, up, down, down, left, right, left, right, B, A</pre>
<h2>Using touch screens</h2>
<pre>Swipe: up, up, down, down, left, right, left, right</pre>
<pre>Then tap screen: right half, left half</pre>.
<h3>Input log</h3>
<pre id="inputLog">(you haven't typed so far)</pre>
<p>
<small>If you make a mistake, just start over again.</small>
</p>
<hr>
<p>
<a class="btn btn-primary btn-lg" role="button" href="https://github.com/zbicin/konami-code">See project on GitHub</a>
<a class="btn btn-default btn-lg" role="button" href="https://twitter.com/intent/tweet?text=Because%20nostalgia:%20konami-code.js%20https%3A%2F%2Fzbicin.github.io%2Fkonami-code-js%20%23javascript">Tweet about it</a>
</p>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="konami-code.js"></script>
<script type="text/javascript">
var gestures = [];
var konamiCodeLength = 10;
function onLoad() {
document.body.focus();
}
function onTransitionEnd() {
document.body.classList.remove('rotate');
alert('Konami code!');
}
function onKonamiCode() {
document.body.addEventListener('transitionend', onTransitionEnd);
document.body.classList.add('rotate');
}
function onKonamiCodeGesture(event) {
var name = event.detail.name;
console.log('konamiCodeGesture: ' + name);
gestures.push(name.toLowerCase());
if (gestures.length > konamiCodeLength) {
gestures.shift();
}
document.getElementById('inputLog').innerHTML = gestures.join(', ');
}
document.addEventListener('load', onLoad);
document.addEventListener('konamiCode', onKonamiCode);
document.addEventListener('konamiCodeGesture', onKonamiCodeGesture);
</script>
</body>
</html>