Skip to content

Commit 6244b9c

Browse files
committed
Moving UP,DOWN,LEFT,RIGHT into an enum to clean up a bit - looking to add "tap"
1 parent 6ec0d94 commit 6244b9c

1 file changed

Lines changed: 21 additions & 14 deletions

File tree

‎mirror_api_server/static/glass/glass.js‎

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@
4444
mainDiv = doc.getElementById("glass"),
4545
timer, running = false,
4646
START_CARD = 1, CLOCK_CARD = 2, CONTENT_CARD = 3, ACTION_CARD = 4, SHARE_CARD = 5, REPLY_CARD = 6, HTML_BUNDLE_CARD = 7, CARD_BUNDLE_CARD = 8,
47-
UP = 1, DOWN = 2, LEFT = 3, RIGHT = 4,
4847
recognition;
4948

49+
/*@type{enum}*/
50+
var glassevent = {UP:1, DOWN: 2, LEFT: 3, RIGHT: 4};
51+
5052
demoCards = {
5153
"items": [
5254
{
@@ -210,12 +212,15 @@
210212
return b.date.getTime() - a.date.getTime();
211213
}
212214

215+
/**
216+
* @returns glassevent
217+
*/
213218
function getClickDirection(x, y) {
214-
if (x < 30) { return RIGHT; }
215-
if (x > 610) { return LEFT; }
216-
if (y < 30) { return DOWN; }
217-
if (y > 330) { return UP; }
218-
return UP;
219+
if (x < 30) { return glassevent.RIGHT; }
220+
if (x > 610) { return glassevent.LEFT; }
221+
if (y < 30) { return glassevent.DOWN; }
222+
if (y > 330) { return glassevent.UP; }
223+
return glassevent.UP;
219224
}
220225

221226
function getDirection(x1, y1, x2, y2) {
@@ -228,10 +233,10 @@
228233
}
229234

230235
if (dx === 0) {
231-
return (dy > 0) ? DOWN : UP;
236+
return (dy > 0) ? glassevent.DOWN : glassevent.UP;
232237
}
233238
if (dy === 0) {
234-
return (dx > 0) ? RIGHT : LEFT;
239+
return (dx > 0) ? glassevent.RIGHT : glassevent.LEFT;
235240
}
236241
tmp = Math.abs(dx / dy);
237242
if (tmp >= 0.5 && tmp <= 1.5) {
@@ -241,11 +246,11 @@
241246

242247
if (tmp > 1.5) {
243248
// mainly horizontal movement
244-
return (dx > 0) ? RIGHT : LEFT;
249+
return (dx > 0) ? glassevent.RIGHT : glassevent.LEFT;
245250
}
246251

247252
// mainly vertical movement
248-
return (dy > 0) ? DOWN : UP;
253+
return (dy > 0) ? glassevent.DOWN : glassevent.UP;
249254
}
250255

251256
/**
@@ -579,20 +584,21 @@
579584
}
580585

581586
function makeMove(x1, y1, x2, y2) {
587+
/** @type {glassevent} */
582588
var dir;
583589
dir = getDirection(x1, y1, x2, y2);
584590

585591
switch (dir) {
586-
case RIGHT:
592+
case glassevent.RIGHT:
587593
right();
588594
break;
589-
case LEFT:
595+
case glassevent.LEFT:
590596
left();
591597
break;
592-
case UP:
598+
case glassevent.UP:
593599
up();
594600
break;
595-
case DOWN:
601+
case glassevent.DOWN:
596602
down();
597603
break;
598604
}
@@ -1086,6 +1092,7 @@
10861092
initialize();
10871093
}
10881094

1095+
10891096
global.onSignInCallback = function (authResult) {
10901097
if (authResult.access_token) {
10911098
global.gapi.client.load("mirror", "v1", function () {

0 commit comments

Comments
 (0)