-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
723 lines (626 loc) · 28.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Generate and play through freediving static tables." />
<link rel="shortcut icon" type="image/png" href="favicon.png"/>
<meta property="og:image" content="http://robinmoisson.github.io/freediving/img/christine_freediving.jpg">
<meta property="og:description" content="Generate and play through freediving static tables." />
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://robinmoisson.github.io/freediving/img/christine_freediving.jpg">
<meta name="twitter:description" content="Generate and play through freediving static tables." />
<title>Freediving Tables</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/lavish-bootstrap.css">
<link rel="stylesheet" href="css/style.css">
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m)
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-73629908-1', 'auto');
ga('send', 'pageview');
</script>
</head>
<body>
<div class="main-div-wrapper">
<div class="container main-div">
<!-- NAVBAR -->
<div class="row">
<nav class="navbar navbar-static-top navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand hidden-xs" href="/freediving">Freediving</a>
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
data-target="#navbar-collapse" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<p class="navbar-text navbar-left-margin visible-xs" id="login_xs"></p>
</div>
<div class="collapse navbar-collapse pull-left" id="navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="/freediving" id="home-url">Tables</a></li>
<li><a href="/freediving/static.html">Experiencing static</a></li>
</ul>
</div>
<div class="navbar-header pull-right hidden-xs">
<div class="login navbar-right"></div>
<p class="syncing navbar-text navbar-right"></p>
</div>
</div>
</nav>
</div>
<div class="row">
<div class="col-xs-12 col-sm-offset-1 col-sm-10">
<h1>Freediving Tables</h1>
<!-- HISTORY -->
<div class="row history">
<div class="col-xs-12">
<h2>
History
<small>
<a href="#" class="toggle-history">►Show history</a>
</small>
</h2>
</div>
<div class="x-scroll history-table hidden">
<table class="table history">
<thead>
<tr>
<th>Date</th>
<th>Type</th>
<th>Repetitions</th>
<th>Total time</th>
<th>Holding time</th>
<th>Shortest breath</th>
<th>Completed?</th>
</tr>
</thead>
<tbody class="history">
<tr>
<td colspan="100">No history yet</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- ACTIVE TABLE -->
<div class="row">
<div class="col-xs-12">
<h2 id="generated_table_title">Current table</h2>
</div>
<div class="col-xs-12 col-sm-6" id="generated_table_wrapper">
<p id="total_time" class="total-time"></p>
<div id="generated_table"><p>The table is empty - load yours below.</p></div>
</div>
<div class="col-xs-12 col-sm-6">
<div id="timer" class="timer text-center hidden">
<p id="timer_title"></p>
<p id="timer_remaining" class="timer-remaining"></p>
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-4 btn-control">
<button class="btn" id="submit_co2">Load CO2</button>
<button class="btn" id="submit_o2">Load O2</button>
</div>
<div class="col-xs-12 col-sm-4 btn-control">
<button id="pause_table" class="btn btn-warning" disabled="disabled">Pause</button>
<button id="start_table" class="btn btn-success" disabled="disabled">Start apnea</button>
</div>
</div>
<!-- GENERATE TABLE -->
<div class="row">
<div class="col-xs-12">
<div class="inline-title">
<h2>Generate Table</h2>
<button class="btn btn-link" id="reset_all" type="button">Reset<span class="hidden-xs"> all values</span>
</button>
</div>
<div class="form-horizontal">
<div class="row">
<div class="col-xs-6">
<div class="form-group">
<label for="preparation_time" class="control-label col-xs-12 col-sm-6">
Initial rest time:
</label>
<div class="col-xs-12 col-sm-6">
<div class="input-group">
<input type="number" id="preparation_time" class="second-input form-control"/>
<div class="input-group-addon">s</div>
</div>
</div>
</div>
</div>
<div class="col-xs-6">
<div class="form-group">
<label for="round_number" class="control-label col-xs-12 col-sm-6">
Number of rounds:
</label>
<div class="col-xs-12 col-sm-6">
<input type="number" id="round_number" class="col-xs-2 form-control"/>
</div>
</div>
</div>
<div class="checkbox col-xs-12 col-sm-6 col-md-4">
<label>
<input type="checkbox" id="is_playing_help_countdown" checked/>
Motivation countdown
<abbr title="Will give you your remaining time during breath hold at 60, 30 and 15s mark">
?
</abbr>
</label>
</div>
</div>
</div>
</div>
<!-- CO2 TABLE -->
<div class="col-xs-12 col-sm-6">
<h3>CO2 Table</h3>
<form id="co2_table" class="form-horizontal">
<div class="row">
<div class="col-xs-6 col-sm-12">
<div class="form-group row">
<label for="co2_first_rest" class="control-label col-xs-12 col-sm-6">
Starting rest time:
</label>
<div class="col-xs-12 col-sm-6">
<div class="input-group">
<input id="co2_first_rest" name="co2_first_rest" type="number"
class="form-control second-input"/>
<div class="input-group-addon">s</div>
</div>
</div>
</div>
</div>
<div class="col-xs-6 col-sm-12">
<div class="form-group row">
<label for="co2_decrease_by" class="control-label col-sm-6">Decrease rest time
by:</label>
<div class="col-xs-12 col-sm-6">
<div class="input-group">
<input id="co2_decrease_by" name="co2_decrease_by" type="number"
class="form-control second-input"/>
<div class="input-group-addon">s</div>
</div>
</div>
</div>
</div>
<div class="col-xs-6 col-sm-12">
<div class="form-group row">
<label for="co2_hold_time" class="control-label col-xs-12 col-sm-6">Hold time:</label>
<div class="col-xs-12 col-sm-6">
<div class="input-group">
<input id="co2_hold_time" name="co2_hold_time" type="number"
class="form-control second-input"/>
<div class="input-group-addon">s</div>
</div>
</div>
</div>
</div>
<div class="col-xs-12 visible-xs">
<div class="text-right">
<button class="btn" type="submit">Load CO2 table</button>
</div>
</div>
</div>
</form>
</div>
<!-- O2 TABLE -->
<div class="col-xs-12 col-sm-6">
<h3>O2 Table</h3>
<form id="o2_table" class="form-horizontal">
<div class="row">
<div class="col-xs-6 col-sm-12">
<div class="form-group row">
<label for="o2_rest" class="control-label col-sm-6">Rest time:</label>
<div class="col-xs-12 col-sm-6">
<div class="input-group">
<input id="o2_rest" name="o2_rest" type="number"
class="form-control second-input">
<div class="input-group-addon">s</div>
</div>
</div>
</div>
</div>
<div class="col-xs-6 col-sm-12">
<div class="form-group row">
<label for="o2_max_hold" class="control-label col-xs-12 col-sm-6">Max hold time:</label>
<div class="col-xs-12 col-sm-6">
<div class="input-group">
<input id="o2_max_hold" name="o2_max_hold" type="number"
class="form-control second-input"/>
<div class="input-group-addon">s</div>
</div>
</div>
</div>
</div>
<div class="col-xs-6 col-sm-12">
<div class="form-group row">
<label for="o2_increase_by" class="control-label col-xs-12 col-sm-6">Increase hold time
by:</label>
<div class="col-xs-12 col-sm-6">
<div class="input-group">
<input id="o2_increase_by" name="o2_increase_by" type="number"
class="form-control second-input"/>
<div class="input-group-addon">s</div>
</div>
</div>
</div>
</div>
<div class="col-xs-12 visible-xs">
<div class="text-right">
<button class="btn" type="submit">Load O2 table</button>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="row">
<footer class="navbar-inverse container-fluid">
<p class="footer-text">Feedback? <a href="mailto:freediving@robinmoisson.com">Email me!</a></p>
<p class="footer-text">Made with <3 — photo courtesy of Christine Armie Marquez</p>
</footer>
</div>
</div>
</div>
<!-- LOGIN MODAL -->
<div class="modal fade" id="login_modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span>
</button>
<h4 class="modal-title" id="myModalLabel">Login</h4>
</div>
<form class="login">
<div class="modal-body">
<div class="form-group">
<input type="email" placeholder="email" class="form-control email"/>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Log In</button>
</div>
</form>
</div>
</div>
</div>
</body>
<script src="js/lib/jquery-1.12.0.min.js"></script>
<script src="js/lib/bootstrap.min.js"></script>
<script src="js/lib/jquery.cookie.js"></script>
<script src="js/lib/NoSleep.js"></script>
<script src="js/Helper.js"></script>
<script src="js/Error.js"></script>
<script src="js/Sync.js"></script>
<script src="js/Settings.js"></script>
<script src="js/Sound.js"></script>
<script src="js/Interval.js"></script>
<script src="js/Table.js"></script>
<script>
var noSleep = new NoSleep();
var HTMLIds = (function () {
var _htmlIds = {
generated_table_title: 'generated_table_title',
generated_table: 'generated_table',
generated_table_wrapper: 'generated_table_wrapper',
total_time: 'total_time',
current_timer: 'current_timer',
table_interval_prefix: 'table_interval_',
round_number_prefix: 'round_number_',
start_table: 'start_table',
pause_table: 'pause_table',
submit_co2: 'submit_co2',
submit_o2: 'submit_o2',
co2_table: 'co2_table',
o2_table: 'o2_table',
reset_all: 'reset_all'
};
return {
getIdName: function (id) {
return _HTMLIds[id];
},
getJqueryObject: function (id) {
return $('#' + _HTMLIds[id]);
}
};
})();
var defaultSettings = {
O2: {
preparationTime: {
value: 45,
selectorId: 'preparation_time'
},
numberOfRounds: {
value: 9,
selectorId: 'round_number'
},
restTime: {
value: 60,
selectorId: 'o2_rest'
},
increaseBy: {
value: 10,
selectorId: 'o2_increase_by'
},
maxHoldTime: {
value: 180,
selectorId: 'o2_max_hold'
},
isPlayingHelpCountdown: {
value: true,
selectorId: 'is_playing_help_countdown',
type: 'checkbox'
}
},
CO2: {
preparationTime: {
value: 45,
selectorId: 'preparation_time'
},
numberOfRounds: {
value: 8,
selectorId: 'round_number'
},
firstRestTime: {
value: 135,
selectorId: 'co2_first_rest'
},
decreaseBy: {
value: 15,
selectorId: 'co2_decrease_by'
},
holdTime: {
value: 135,
selectorId: 'co2_hold_time'
},
isPlayingHelpCountdown: {
value: true,
selectorId: 'is_playing_help_countdown',
type: 'checkbox'
}
}
};
var sound = new GoogleSound();
var sync = new Sync();
var tables = {
O2: new O2Table(new Settings(defaultSettings.O2), sync, sound),
CO2: new CO2Table(new Settings(defaultSettings.CO2), sync, sound)
};
var currentTable = null;
$(document).ready(function () {
var email = $.cookie('email');
if (email) {
sync.logIn(email);
loginUpdateDisplay(email);
}
else {
logoutUpdateDisplay();
}
$.each(tables, function (key, table) {
table.settings.updateDisplay();
});
updateAllSecondInput();
$('#reset_all').click(function () {
$.each(tables, function (key, table) {
table.settings.reset();
table.settings.saveToCookie();
});
updateAllSecondInput();
});
$('#start_table').click(function () {
sound.preloadSounds();
currentTable.start();
updateButtonsForTableRunning();
});
$('#pause_table').click(function () {
currentTable.pause();
updateButtonsForTablePaused();
});
$('#submit_co2').click(function () {
$('#co2_table').submit();
});
$('#submit_o2').click(function () {
$('#o2_table').submit();
});
$('#o2_table').submit(function (e) {
e.preventDefault();
var settings = new Settings(defaultSettings.O2);
settings.updateFromUI();
tables.O2 = new O2Table(settings, sync, sound);
tables.O2.settings.saveToCookie();
setAndDisplayNewTable(tables.O2);
});
$('#co2_table').submit(function (e) {
e.preventDefault();
var settings = new Settings(defaultSettings.CO2);
settings.updateFromUI();
console.log(settings.get('isPlayingHelpCountdown'));
tables.CO2 = new CO2Table(settings, sync, sound);
tables.CO2.settings.saveToCookie();
setAndDisplayNewTable(tables.CO2);
});
$(document).on('beat', function (event) {
var timer = $('#timer');
timer.removeClass('hidden');
timer.css('color', event.color);
$('#timer_title').text(event.intervalType);
$('#timer_remaining').text(event.remaining);
});
$(document).on('tableCompleted', function (event) {
$('#current_timer').html('Table completed.');
});
var currentIntervalIndex = '0';
$(document).on('currentIntervalIndex', function (event) {
var currentRoundNumber = Math.floor(currentIntervalIndex / 2 + 1);
$('#table_interval_' + currentIntervalIndex).removeClass('active-interval');
$('#round_number_' + currentRoundNumber).removeClass('active-interval');
currentIntervalIndex = event.msg;
currentRoundNumber = Math.floor(currentIntervalIndex / 2 + 1);
$('#table_interval_' + currentIntervalIndex).addClass('active-interval');
$('#round_number_' + currentRoundNumber).addClass('active-interval');
});
$(document).on('tableStopped', function () {
var currentRoundNumber = Math.floor(currentIntervalIndex / 2 + 1);
$('#table_interval_' + currentIntervalIndex).removeClass('active-interval');
$('#round_number_' + currentRoundNumber).removeClass('active-interval');
var timer = $('#timer');
timer.addClass('hidden');
timer.css('color', 'white');
$('#timer_title').text('');
$('#timer_remaining').text('');
updateButtonsForTablePaused();
});
/**
* handle login submission
*/
$(document).on('submit', 'form.login', function (e) {
e.preventDefault();
var email = $(this).find('.email').val().trim();
sync.logIn(email);
loginUpdateDisplay(email);
});
/**
* Handle logout
*/
$(document).on('click', 'a.logout', function (e) {
e.preventDefault();
sync.logOut();
logoutUpdateDisplay();
});
/**
* Toggle/reload history block
*/
$(document).on('click', '.toggle-history', function () {
var historyTable = $('div.history-table');
var isVisible = !historyTable.hasClass('hidden');
if (!isVisible) {
sync.refreshHistory();
historyTable.removeClass('hidden');
$(this).text('▼Hide history');
}
else {
historyTable.addClass('hidden');
$(this).text('►Show history');
}
});
$(document).on('input', '.second-input', function() {
updateSecondInput(this);
})
});
function logoutUpdateDisplay() {
var loginHtml = '<form class="login navbar-form">' +
'<div class="form-group">' +
'<input type="email" placeholder="email" class="form-control email"/>' +
'</div>' +
'<button class="btn btn-primary">Log In</button>' +
'</form>';
$('div.login').html(loginHtml);
$('p#login_xs').html('<a href="#" class="login" data-toggle="modal" data-target="#login_modal">\n' +
' Login\n' +
'</a>');
// hide history section
var historyBlock = $('div.history');
if (!historyBlock.hasClass('hidden')) {
historyBlock.addClass('hidden');
}
$('input.email').val(null);
}
function loginUpdateDisplay(email) {
var logoutHtml = ' <span class="navbar-label label label-primary">' + email + '</span>' +
' <a href="#" class="logout navbar-text">Logout</a>';
$('div.login').html(logoutHtml);
$('p#login_xs').html('<a href="#" class="login logout">Logout</a>');
// show history section
var historyBlock = $('div.history');
if (historyBlock.hasClass('hidden')) {
historyBlock.removeClass('hidden');
}
var historyTable = $('div.history-table');
if (!historyTable.hasClass('hidden')) {
historyTable.addClass('hidden');
}
// dismiss login modal
$('#login_modal').modal('hide');
}
function setAndDisplayNewTable(newTable) {
if (currentTable !== null) {
currentTable.stop();
}
currentTable = newTable;
displayTable();
}
function displayTable() {
var generatedTable = $('#generated_table');
$('#generated_table_title').html('Current table: ' + currentTable.getType());
generatedTable.html('');
$('#total_time').html('Total time: ' + currentTable.getTotalDurationString());
var htmlTable = createHTMLTable();
generatedTable.append(htmlTable);
if (currentTable.errorMsg) {
generatedTable.append('<p class="interval-too-short">' + currentTable.errorMsg + '</p>');
}
updateButtonsForTablePaused();
$('html, body').animate({
scrollTop: $("#generated_table_wrapper").offset().top
}, 0);
}
function createHTMLTable() {
var html = '';
for (var i = 0; i < currentTable.intervalList.length; i = i + 2) {
var roundNumber = i / 2 + 1;
html += '<p>'
+ '<span class="round-number" id="round_number_' + roundNumber + '">' + roundNumber + '.</span>'
+ createIntervalHTMLElement(currentTable.intervalList, i)
+ createIntervalHTMLElement(currentTable.intervalList, i + 1)
+ '</p>';
}
return html;
}
function createIntervalHTMLElement(intervalList, intervalIndex) {
if (typeof(intervalList[intervalIndex]) === 'undefined') {
return '';
}
var html = '<span class="interval" id="table_interval_' + intervalIndex + '">';
html += intervalList[intervalIndex].display() + '</span>';
return html;
}
function updateButtonsForTableRunning() {
$('#start_table').prop('disabled', true);
$('#pause_table').prop('disabled', false);
noSleep.enable();
}
function updateButtonsForTablePaused() {
$('#start_table').prop('disabled', false);
$('#pause_table').prop('disabled', true);
noSleep.disable();
}
function updateAllSecondInput() {
$.each($('.second-input'), function (key, secondInput) {
updateSecondInput(secondInput);
});
}
function updateSecondInput(secondInput) {
var seconds = parseInt($(secondInput).val());
$(secondInput).parent('.input-group').find('.input-group-addon').text(
helper.getDisplayDurationString(seconds)
);
}
</script>
</html>