-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
755 lines (606 loc) · 26.3 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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Emojional</title>
<script type="text/javascript" src="cordova.js"></script>
<script src="js/jquery-2.1.3.js"></script>
<script src="js/jquery.mobile-1.4.5.js"></script>
<script src="js/index.js"></script>
<meta charset="utf-8" />
<link rel="stylesheet" href="css/jquery.mobile-1.4.5.css" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<script src="http://cdn.jsdelivr.net/parse/1.2.9/parse.min.js"></script>
<style>
h1{
color:white;
text-transform: none;
font-size: 30px;
}
#main-page, #user-page {
background-color: #4a88cd;
color:black;
text-transform: none;
}
body{
font-family:'HelveticaNeue-Light', 'HelveticaNeue', Helvetica, Arial, sans-serif;
font-size:25px;
}
/* STYLE OF MY EMOJI //// TOP HALF OF SCREEN */
#emoji-mine{
font-family:'HelveticaNeue-Light', 'HelveticaNeue', Helvetica, Arial, sans-serif;
font-size:25px;
width: auto;
padding-top:20%;
padding-bottom: 24%;
display: block;
margin: 0 auto;
background-color: #2761a3;
text-align: center;
}
/* STYLE OF ROOM AVERAGE ////BOTTOM HALF OF SCREEN*/
#emoji-average {
font-family:'HelveticaNeue-Light', 'HelveticaNeue', Helvetica, Arial, sans-serif;
font-size:20px;
width: auto;
padding: 25%;
display: block; margin: 0 auto;
background-color:#2761a3;
background-image: url("img/roundBack.png");
background-size: 100% 100%;
background-repeat: no-repeat;
background-position: bottom;
text-align: center;
}
/*STYLE OF LIST OF EMOJIS TO CHOOSE EMOJI FROM //// MIDDLE ROW*/
#emoji-list{
font-size:4em;
width:auto;
padding-top: 5%;
padding-bottom:5%;
overflow-x:auto;
white-space: nowrap;
display: none;
margin: 0 auto;
text-align: center;
position: relative;
background: #ffffff;
}
#userManagement{
padding:4%;
}
#status{
width: 100%;
height: 15%;
}
#pref, #back{
position: absolute;
margin:0;
margin-top: -72px;
right:0;
}
.signup-form{
}
#swipe-nav, #swipe-nav2{
width: 100%;
height:50px;
position: absolute;
bottom: 0;
background-color: #4a88cd;
}
@keyframes arrows {
0% {padding-left:0;}
40% {padding-left:30px;}
100% {padding-left:0;}
}
@-moz-keyframes arrows {
0% {padding-left:0;}
40% {padding-left:30px;}
100% {padding-left:0;}
}
@-webkit-keyframes arrows {
0% {padding-left:0;}
40% {padding-left:30px;}
100% {padding-left:0;}
}
.arrow, .arrowl{
width: 30px;
height: 30px;
display: block;
margin-left: auto;
margin-right: auto;
animation: arrows 3s linear 1s infinite alternate;
-webkit-animation: arrows 3s linear 1s infinite alternate;
-moz-animation: arrows 3s linear 1s infinite alternate;
}
</style>
</head>
<body>
<body id="body-id">
<!-- MAIN PAGE -->
<div data-role="page" class="page" id="main-page">
<!-- HEADER -->
<div data-role="header" data-id="head1" data-position="fixed" data-theme="a" data-tap-toggle="false" style="text-shadow:none;padding-top:3%; padding-bottom:3%; background-color: #142e4c; border-style:none;font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">
<h1>Emojional</h1>
<!-- <img src="img/o.png" id="back"></img>
-->
</div>
<!-- <div data-role="navbar">
<ul>
<li><a href="#" class="ui-btn-active ">Home</a></li>
<li><a href="#user-page">User</a></li>
</ul>
</div> -->
<!-- CONTENT -->
<div role="main" class="ui-content" style="padding:0;margin:0;background-color: #759FF0;text-shadow:none; font-family: sans-serif-thin; font-style: normal">
<!-- CONTAINER FOR WORD 'ME' -->
<div id="emoji-mine">Me<br>
<!-- CONTAINER FOR MY MOOD ACTUAL EMOJI -->
<div id="mine-inner" style="padding:0;margin:0;font-size:42px">😊</div>
</div>
<!-- LIST OF EMOJIS TO PICK FROM -->
<div id="emoji-list">
</div>
<!-- CONTAINER FOR HOW MANY PEOPLE 'IN ROOM' -->
<div id="emoji-average"><br>
<div id="result-counter"></div>
<!-- CONTAINER FOR ROOM AVERAGE ACTUAL EMOJI -->
<div id="average-inner" style="padding:0;margin:0;font-size:42px"></div>
</div>
</div>
<div id="swipe-nav"><img class="arrow" src="img/arrow.png"></div>
</div>
<!-- USER PAGE -->
<div data-role="page" class="page" id="user-page">
<!-- HEADER -->
<div data-role="header" data-id="head1" data-position="fixed" data-theme="a" data-tap-toggle="false" style="text-shadow:none;padding-top:3%; padding-bottom:3%; background-color: #142e4c; border-style:none;font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;">
<h1>Emojional</h1>
<!-- <img src="img/x.png" id="pref"></img>
-->
</div>
<!-- <div data-role="navbar">
<ul>
<li><a href="#main-page">Home</a></li>
<li><a href="#" class="ui-btn-active">User</a></li>
</ul>
</div> -->
<!-- CONTENT -->
<div id="userManagement">
<div id="status"></div>
<br>
<h1>Username</h1><input type="text" id="username" name="username" size="15" /><br />
<form class="login-form">
<div align="center">
<p><input type="submit" value="Login" /></p>
</div>
</form>
<form class="signup-form">
<div align="center">
<p><input type="submit" value="Signup" /></p>
</div>
</form>
<button id="logout">Log Out</button>
</div>
<div id="swipe-nav2"><img class="arrowl" src="img/arrowl.png"></div>
</div>
<script type="text/javascript">
// ---------------- Initialisation ----------------------
Parse.initialize("Key", "Key");
//Parse initialize the object to use
var LocationUpdate = Parse.Object.extend("LocationUpdate");
var LocationUpdate = new LocationUpdate();
//declare variables
var loc, lat, lon, className, sameUser, newMood, averageMood, rawMood;
//call the get location
getLocation();
//Prase user management
var currentUser = Parse.User.current();
var password = "password";
var currentRoomMood = [];
//------------------- User Management ------------------------
if (currentUser) {
// if the user has not logged out go to home page
var sameUser = currentUser.attributes.username;
console.log('still the same user called ' + sameUser);
$.mobile.navigate( "#main-page" );
} else {
$.mobile.navigate( "#user-page" );
$(".signup-form").submit (function(event) {
event.preventDefault();
var user = new Parse.User();
//use the same password for everybody - one variable for both signup and login
//get the form values from the html
var s_username = $('#username').val();
// var s_password = "davidmarc";
// SIGNUP: new user to Parse
user.set("username", s_username);
user.set("password", password);
// how does this work (???)
user.signUp(null, {
success: function(user) {
console.log("new signup, username: " + username + " password: " + password);
$("#status").css("background-color", "#7BFD79");
$("#status").html("Success! Welcome");
$.mobile.navigate( "#main-page" );
},
error: function(user, error) {
// Show the error message somewhere and let the user try again. (!!!)
alert("Error: " + error.code + " " + error.message);
$("#status").css("background-color", "#FD234E");
$("#status").html(error);
}
});
});
$(".login-form").submit (function(event) {
event.preventDefault();
//get the form values from the html
var username = $('#username').val();
// var password = "davidmarc";
// LOGIN: using the form input
Parse.User.logIn(username, password, {
success: function(user) {
// Go to home page (!!!)
console.log("new login, username: " + username + " password: " + password);
$("#status").css("background-color", "#7BFD79");
$("#status").html("Welcome Back");
$.mobile.navigate( "#main-page" );
},
error: function(user, error) {
// The login failed. Check error to see why.
//post the error to the login page (!!!)
console.log(error);
$("#status").css("background-color", "#FD234E");
$("#status").html(error);
}
});
});
}
//logout function
$("#logout").click(function(){
Parse.User.logOut();
console.log('a user was logged out');
$("#status").html("Successfully logged out");
});
// -------------- Get Location -------------------------
//phonegap: post my location and emoji mood upon submit
//still need to code a way to launch get Location on the click of an emoji
function getLocation(){
console.log('at get location');
navigator.geolocation.getCurrentPosition(showPosition, locationError);
}
function showPosition(position) {
console.log('at show position');
lat = position.coords.latitude.toFixed(3);;
lon = position.coords.longitude.toFixed(3);;
loc = {lat: lat, lon: lon};
console.log("lat: " + lat + " lon: " + lon);
}
function locationError(error){
console.log(error);
}
// -------------------------------- Emoji Parsing ------------------------------
//marcs javascript
var myMood = [],
emptiedEmojis = false,
emojis = ['😀',
'😁',
'😂',
'😃',
'😄',
'😅',
'😆',
'😇',
'😈',
'😉',
'😊',
'😋',
'😌',
'😍',
'😎',
'😏',
'😐',
'😑',
'😒',
'😓',
'😔',
'😕',
'😖',
'😗',
'😘',
'😙',
'😚',
'😛',
'😜',
'😝',
'😞',
'😟',
'😠',
'😡',
'😢',
'😣',
'😤',
'😥',
'😦',
'😧',
'😨',
'😩',
'😪',
'😫',
'😬',
'😭',
'😮',
'😯',
'😰',
'😱',
'😲',
'😳',
'😴',
'😵',
'😶',
'😷']
var myMood = [];
for (var i = 0; i < emojis.length; i++){
var elt = $('<span>' + emojis[i] + '</span>');
elt.attr('id', 'e' + i + '');
elt.attr('class', 'emoji');
elt.html(emojis[i]);
$('#emoji-list').append(elt);
}
//FILL EMOJI LIST WITH INTERACTIVE EMOJIS
for (var i = 0; i < emojis.length; i++) {
var elt = $('<span>' + emojis[i] + '</span>');
elt.attr('id', 'e' + i + '');
elt.attr('class', 'emoji');
elt.html(emojis[i]);
$('#emoji-list').append(elt);
};
//------------------------ UI/UX -------------------------------
//ADD EVENT LISTENER TO PUSH A LIMIT OF 5 EMOJIS INTO myMood ARRAY AND INTO HTML
$('.emoji').click(function() {
console.log($(this).text());
if (!emptiedEmojis) {
$('#mine-inner').html('');
myMood = [];
emptiedEmojis = true;
};
if (myMood.length < 5) {
myMood.push($(this).text());
$('#mine-inner').append($(this).text());
};
});
//ADD EVENTLISTENER TO ANIMATE ON TAP GESTURE TO REVEAL EMOJI LIST
$('#emoji-mine, #emoji-average').click(function() {
if ($('#emoji-list').is(':hidden')) {
$(' #emoji-list').animate({
scrollLeft: '+=360'
}, {
duration: 500,
queue: false
});
$('#emoji-list').slideDown('slow');
emptiedEmojis = false;
} else {
$('#emoji-list').slideUp('slow');
sendLocation(myMood);
roomMood();
console.log(myMood + " was captured");
};
});
//MAKE IT SO YOU CANT DRAG THE PAGE WITH SLIDE GESTURE
$('#emoji-mine, #emoji-average').on('touchmove', function(evt) {
evt.preventDefault();
});
//ADD SLIDE UP AND SLIDE DOWN GESTURE EVENTLISTENERS TO JQUERY LIBRARY //////IGNORE TIL THE NEXT COMMENT
var supportTouch = $.support.touch,
scrollEvent = "touchmove scroll",
touchStartEvent = supportTouch ? "touchstart" : "mousedown",
touchStopEvent = supportTouch ? "touchend" : "mouseup",
touchMoveEvent = supportTouch ? "touchmove" : "mousemove";
$.event.special.swipeupdown = {
setup: function() {
var thisObject = this;
var $this = $(thisObject);
$this.bind(touchStartEvent, function(event) {
var data = event.originalEvent.touches ?
event.originalEvent.touches[0] :
event,
start = {
time: (new Date).getTime(),
coords: [data.pageX, data.pageY],
origin: $(event.target)
},
stop;
function moveHandler(event) {
if (!start) {
return;
}
var data = event.originalEvent.touches ?
event.originalEvent.touches[0] :
event;
stop = {
time: (new Date).getTime(),
coords: [data.pageX, data.pageY]
};
if (Math.abs(start.coords[1] - stop.coords[1]) > 10) {
event.preventDefault();
}
}
$this
.bind(touchMoveEvent, moveHandler)
.one(touchStopEvent, function(event) {
$this.unbind(touchMoveEvent, moveHandler);
if (start && stop) {
if (stop.time - start.time < 1000 &&
Math.abs(start.coords[1] - stop.coords[1]) > 30 &&
Math.abs(start.coords[0] - stop.coords[0]) < 75) {
start.origin
.trigger("swipeupdown")
.trigger(start.coords[1] > stop.coords[1] ? "swipeup" : "swipedown");
}
}
start = stop = undefined;
});
});
}
};
$.each({
swipedown: "swipeupdown",
swipeup: "swipeupdown"
}, function(event, sourceEvent) {
$.event.special[event] = {
setup: function() {
$(this).bind(sourceEvent, $.noop);
}
};
});
//ADD SWIPEDOWN EVENTLISTENER FOR ANIMATION TO REVEAL EMOJIS LIST //////ALTERNATIVE TO TAP GESTURE
$('#emoji-average').on('swipedown', function() {
if ($('#emoji-list').is(':hidden')) {
$(' #emoji-list').animate({
scrollLeft: '+=160'
}, {
duration: 1000,
queue: false
});
$('#emoji-list').slideDown('slow');
emptiedEmojis = false;
};
});
//ADD SWIPEUP EVENTLISTENER FOR ANIMATION TO REVEAL EMOJIS LIST //////ALTERNATIVE TO TAP GESTURE
$('#emoji-average').on('swipeup', function() {
if ($('#emoji-list').is(':visible')) {
$('#emoji-list').slideUp('slow');
};
});
$("#swipe-nav").on('swiperight', function(event) {
$.mobile.navigate( "#user-page" );
console.log('swipe right');
});
$("#swipe-nav2").on('swipeleft', function(event) {
$.mobile.navigate( "#main-page" );
console.log('swipe left');
});
// $("#pref").click(function(){
// $.mobile.navigate( "#user-page" );
// });
// $("#back").click(function(){
// $.mobile.navigate( "#main-page" );
// });
// ----------------- Send it to server with location ------------------
//sending location and emoji to the server when I update my location
function sendLocation(myMood){
console.log('at send location');
//create a relationship between the current user and the location in the database
LocationUpdate.set("parent", currentUser);
LocationUpdate.set({
geolocation: loc,
myMood: myMood
}, {
success: function(LocationUpdate) {
// The object was saved successfully.
console.log('your location was logged as ' + loc + "with a mood of " + myMood);
//call the room mood query at the same time
},
error: function(LocationUpdate, error) {
// The save failed.
// error is a Parse.Error with an error code and message.
console.log('there was an error ' + error);
}
});
//the parse funciton to save
LocationUpdate.save();
}
var x1f600 = 0;
var x1f601 = 0;
var x1f602 = 0;
var x1f603 = 0;
var x1f604 = 0;
var x1f605 = 0;
var x1f637 = 0;
var moods = {
mood0: "😀",
mood1: "😁",
mood2: "😂",
mood3: "😃",
mood4: "😄"
};
// ------------------- Query to Server -------------------------
//define the query to the server
var locations = Parse.Object.extend("LocationUpdate");
var query = new Parse.Query(locations);
var postDate, d, cutDate;
// add a timeframe to what data I am asking for!!! - your emotion expires every day
function roomMood(){
query.equalTo("geolocation", loc);
query.find({
success: function(results) {
d = new Date();
console.log("Successfully retrieved " + results.length + " updates at lat: " + lat + " lon: " + lon);
$("#result-counter").html(results.length + " moods found");
// Do something with the returned Parse.Object values
for (var i = 0; i < results.length; i++) {
// console.log(results[i]);
// console.log( 'lat: ' + results[i].attributes.geolocation.lat + ' user: ' +
// results[i].attributes.parent.id + " with a mood of " + results[i].attributes.myMood + " at time: " + results[i].createdAt);
//see if the timestampt matches the current day
postDate = results[i].createdAt;
if (postDate = d){
console.log('same date!');
}
currentRoomMood.push(results[i].attributes.myMood.join(" "));
if(results[i].attributes.myMood.toString() == moods.mood0){
x1f600++;
console.log("x1f600: " + x1f600);
}
else if(results[i].attributes.myMood == moods.mood1){
x1f601++;
console.log("x1f601: " + x1f601);
}
else if(results[i].attributes.myMood == moods.mood2){
x1f602++;
console.log("x1f602: " + x1f602);
}
else if(results[i].attributes.myMood == moods.mood3){
x1f603++;
console.log(x1f603);
}
else if(results[i].attributes.myMood == moods.mood4){
x1f604++;
console.log(x1f604);
}
}
console.log("mood from server is in the new array is: " + currentRoomMood);
//post the new mood into the Room div
// $("#emoji-mine").html(orderByOccurrence(currentRoomMood.join("")));
$("#average-inner").html(currentRoomMood.join(" ").slice(0,36));
},
error: function(error) {
}
});
};
userHistory();
// ------------------- Query for user data -------------------------
//define the query to the server
var userDate = Parse.Object.extend("LocationUpdate");
var queryUser = new Parse.Query(locations);
var userMoods = [];
// add a timeframe to what data I am asking for!!! - your emotion expires every day
function userHistory(){
var userNow = Parse.User.current().id;
query.equalTo("parent", userNow);
query.find({
success: function(results) {
for (var i = 0; i < results.length; i++) {
userMoods.push(results[i].attributes.myMood.join(" "));
$("#status").html(userMoods);
}
},
error: function(error) {
console.log(error);
}
});
}
</script>
</body>
</html>