-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
259 lines (233 loc) · 8.4 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>WatzThis?</title>
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="img/h/apple-touch-icon.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="img/m/apple-touch-icon.png">
<link rel="apple-touch-icon-precomposed" href="img/l/apple-touch-icon-precomposed.png">
<link rel="apple-touch-startup-image" href="img/l/splash.png">
<link rel="stylesheet" type="text/css" href="watzthis.css">
<!-- the following script tag brings in the Google Maps API functions -->
<script src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script>
//initialize variables for color buttons and auto mode
var light = new Array();
var t;
var color=0;
var flipping=0;
var speed=2000;
light[0] = 'black';
light[1] = 'white';
light[2] = "red";
light[3] = "blue";
light[4] = "green";
light[5] = "orange";
function flip(whichway){
//changes the screen color when called
document.bgColor = light[whichway];
stopFlip();
}
function autoFlip(speed) {
//changes the screen color automatically at an interval set by speed
document.bgColor = light[color];
if (color < light.length-1) {
color++;
} else {
color=0;
}
t = setTimeout("autoFlip(speed)",speed);
}
function doAutoFlip(speed){
//start the auto-flipping if it's not already going.
if (!flipping){
flipping=1;
autoFlip(speed);
}
}
function stopFlip() {
//stop the auto-flipping
clearTimeout(t);
flipping=0;
}
function $(id){
//gets an element by the id passed to it. this is used to display the map.
return document.getElementById(id);
}
//initialize map variables;
var you = {};
var map = {};
function getLoc() {
if (navigator.geolocation){
//if the browser supports geolocation, get current location and display on a map.
var gps = navigator.geolocation;
gps.getCurrentPosition(function(position){
var latLng = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
var opts = {zoom:6, center:latLng, mapTypeId: google.maps.MapTypeId.ROADMAP};
map = new google.maps.Map($("map_canvas"), opts);
you = new google.maps.Marker({
position: latLng,
map: map,
title: "There you are!"
});
var infowindow = new google.maps.InfoWindow({
map: map,
position: latLng,
content: 'Location found using HTML5.'
});
});
} else {
//if the browser doesn't support geolocation, display an alert saying so.
alert("Your browser doesn't support geolocation.");
}
}
</script>
<script type="text/javascript">
// TOUCH-EVENTS SINGLE-FINGER SWIPE-SENSING JAVASCRIPT
// Courtesy of PADILICIOUS.COM and MACOSXAUTOMATION.COM
// this script can be used with one or more page elements to perform actions based on them being swiped with a single finger
var triggerElementID = null; // this variable is used to identity the triggering element
var fingerCount = 0;
var startX = 0;
var startY = 0;
var curX = 0;
var curY = 0;
var deltaX = 0;
var deltaY = 0;
var horzDiff = 0;
var vertDiff = 0;
var minLength = 72; // the shortest distance the user may swipe
var swipeLength = 0;
var swipeAngle = null;
var swipeDirection = null;
// The 4 Touch Event Handlers
// NOTE: the touchStart handler should also receive the ID of the triggering element
// make sure its ID is passed in the event call placed in the element declaration, like:
// <div id="picture-frame" ontouchstart="touchStart(event,'picture-frame');" ontouchend="touchEnd(event);" ontouchmove="touchMove(event);" ontouchcancel="touchCancel(event);">
function touchStart(event,passedName) {
// disable the standard ability to select the touched object
event.preventDefault();
// get the total number of fingers touching the screen
fingerCount = event.touches.length;
// since we're looking for a swipe (single finger) and not a gesture (multiple fingers),
// check that only one finger was used
if ( fingerCount == 1 ) {
// get the coordinates of the touch
startX = event.touches[0].pageX;
startY = event.touches[0].pageY;
// store the triggering element ID
triggerElementID = passedName;
} else {
// more than one finger touched so cancel
touchCancel(event);
}
}
function touchMove(event) {
event.preventDefault();
if ( event.touches.length == 1 ) {
curX = event.touches[0].pageX;
curY = event.touches[0].pageY;
} else {
touchCancel(event);
}
}
function touchEnd(event) {
event.preventDefault();
// check to see if more than one finger was used and that there is an ending coordinate
if ( fingerCount == 1 && curX != 0 ) {
// use the Distance Formula to determine the length of the swipe
swipeLength = Math.round(Math.sqrt(Math.pow(curX - startX,2) + Math.pow(curY - startY,2)));
// if the user swiped more than the minimum length, perform the appropriate action
if ( swipeLength >= minLength ) {
caluculateAngle();
determineSwipeDirection();
processingRoutine();
touchCancel(event); // reset the variables
} else {
touchCancel(event);
}
} else {
touchCancel(event);
}
}
function touchCancel(event) {
// reset the variables back to default values
fingerCount = 0;
startX = 0;
startY = 0;
curX = 0;
curY = 0;
deltaX = 0;
deltaY = 0;
horzDiff = 0;
vertDiff = 0;
swipeLength = 0;
swipeAngle = null;
swipeDirection = null;
triggerElementID = null;
}
function caluculateAngle() {
var X = startX-curX;
var Y = curY-startY;
var Z = Math.round(Math.sqrt(Math.pow(X,2)+Math.pow(Y,2))); //the distance - rounded - in pixels
var r = Math.atan2(Y,X); //angle in radians (Cartesian system)
swipeAngle = Math.round(r*180/Math.PI); //angle in degrees
if ( swipeAngle < 0 ) { swipeAngle = 360 - Math.abs(swipeAngle); }
}
function determineSwipeDirection() {
if ( (swipeAngle <= 45) && (swipeAngle >= 0) ) {
swipeDirection = 'left';
} else if ( (swipeAngle <= 360) && (swipeAngle >= 315) ) {
swipeDirection = 'left';
} else if ( (swipeAngle >= 135) && (swipeAngle <= 225) ) {
swipeDirection = 'right';
} else if ( (swipeAngle > 45) && (swipeAngle < 135) ) {
swipeDirection = 'down';
} else {
swipeDirection = 'up';
}
}
function processingRoutine() {
if ( swipeDirection == 'left' ) {
window.frames.ghost.location.href = 'animated_ghost_reverse.svg';
} else if ( swipeDirection == 'right' ) {
window.frames.ghost.location.href = 'animated_ghost.svg';
} else if ( swipeDirection == 'up' ) {
alert('up');
} else if ( swipeDirection == 'down' ) {
alert('down');
}
}
</script>
</head>
<body style="margin: 0px; padding: 0px;">
<div id="container">
<h1>WatzThis?</h1>
<div id="page" ontouchstart="touchStart(event,'ghost');" ontouchend="touchEnd(event);" ontouchmove="touchMove(event);" ontouchcancel="touchCancel(event);">
<iframe name="ghost" width="100%" height="100px" src="animated_ghost.svg"></iframe>
<div id="directions">
<ol>
<li>Use the top row of buttons to turn the flashlight on or off, or to make the light red.</li>
<li>Use the 2nd row of buttons to turn on and off your automatic flashing color light dance party.</li>
</ol>
</div>
<div id="flashlight">
<input type="button" id="OFF" class="bigButton" value="OFF" onclick="flip(0);">
<input type="button" id="ON" class="bigButton" value="ON" onclick="flip(1);">
<input type="button" id="RED" class="bigButton" value="RED" onclick="flip(2);">
</div>
<div id="danceparty">
<input type="button" id="AUTO" class="bigButton" value="AUTO" onclick="doAutoFlip(500);">
<input type="button" id="STOP" class="bigButton" value="STOP" onclick="stopFlip();">
</div>
<div id="geolocation">
<input type="button" id="latlong" class="bigButton" value="GET LOC" onclick="getLoc();">
</div>
</div>
<div id="map_canvas"
style="width: 100%; height: 100%; float: left; border: 1px solid black;">
</div>
</body>
</html>