-
Notifications
You must be signed in to change notification settings - Fork 0
/
lunchduty-normal.html
1087 lines (933 loc) · 26.2 KB
/
lunchduty-normal.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
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<style>
/* THEMES */
/********** Theme: dark **********/
/* Font styles */
.flipdown.flipdown__theme-dark {
font-family: serif;
font-weight: bold;
}
/* Rotor group headings */
.flipdown.flipdown__theme-dark .rotor-group-heading:before {
color: #000000;
}
/* Delimeters */
.flipdown.flipdown__theme-dark .rotor-group:nth-child(n+1):nth-child(-n+2):before,
.flipdown.flipdown__theme-dark .rotor-group:nth-child(n+1):nth-child(-n+2):after {
background-color: #151515;
}
/* Rotor tops */
.flipdown.flipdown__theme-dark .rotor,
.flipdown.flipdown__theme-dark .rotor-top,
.flipdown.flipdown__theme-dark .rotor-leaf-front {
color: #FFFFFF;
background-color: #151515;
}
/* Rotor bottoms */
.flipdown.flipdown__theme-dark .rotor-bottom,
.flipdown.flipdown__theme-dark .rotor-leaf-rear {
color: #EFEFEF;
background-color: #202020;
}
/* Hinge */
.flipdown.flipdown__theme-dark .rotor:after {
border-top: solid 1px #151515;
}
/********** Theme: light **********/
/* Font styles */
.flipdown.flipdown__theme-light {
font-family: serif;
font-weight: bold;
}
/* Rotor group headings */
.flipdown.flipdown__theme-light .rotor-group-heading:before {
color: #EEEEEE;
}
/* Delimeters */
.flipdown.flipdown__theme-light .rotor-group:nth-child(n+1):nth-child(-n+2):before,
.flipdown.flipdown__theme-light .rotor-group:nth-child(n+1):nth-child(-n+2):after {
background-color: #DDDDDD;
}
/* Rotor tops */
.flipdown.flipdown__theme-light .rotor,
.flipdown.flipdown__theme-light .rotor-top,
.flipdown.flipdown__theme-light .rotor-leaf-front {
color: #222222;
background-color: #DDDDDD;
}
/* Rotor bottoms */
.flipdown.flipdown__theme-light .rotor-bottom,
.flipdown.flipdown__theme-light .rotor-leaf-rear {
color: #333333;
background-color: #EEEEEE;
}
/* Hinge */
.flipdown.flipdown__theme-light .rotor:after {
border-top: solid 1px #222222;
}
/* END OF THEMES */
/* https://stackoverflow.com/questions/1232096/how-to-horizontally-center-a-floating-element-of-a-variable-width */
#centerwrap {
float: left;
position: relative;
left: 50%;
}
#floatedcontent {
float: left;
position: relative;
left: -50%;
}
.flipdown {
text-align: center;
overflow: visible;
width: 100%; /* 510px;*/
height: 20%; /* 110px; */
}
.flipdown .rotor-group {
position: relative;
float: left;
padding-right: 30px;
}
.flipdown .rotor-group:last-child {
padding-right: 0;
}
.flipdown .rotor-group-heading:before {
display: block;
height: 60px;
line-height: 60px;
text-align: center;
}
.flipdown .rotor-group:nth-child(1) .rotor-group-heading:before {
content: attr(data-before);
}
.flipdown .rotor-group:nth-child(2) .rotor-group-heading:before {
content: attr(data-before);
}
.flipdown .rotor-group:nth-child(3) .rotor-group-heading:before {
content: attr(data-before);
}
.flipdown .rotor-group:nth-child(n+1):nth-child(-n+2):before {
content: '';
position: absolute;
bottom: 45px;
left: 215px;
width: 20px;
height: 20px;
border-radius: 50%;
}
.flipdown .rotor-group:nth-child(n+1):nth-child(-n+2):after {
content: '';
position: absolute;
bottom: 90px;
left: 215px;
width: 20px;
height: 20px;
border-radius: 50%;
}
.flipdown .rotor {
position: relative;
float: left;
width: 100px;
height: 160px;
margin: 0px 10px 0px 0px;
border-radius: 8px;
font-size: 8rem;
text-align: center;
perspective: 400px;
}
.flipdown .rotor:last-child {
margin-right: 0;
}
.flipdown .rotor-top,
.flipdown .rotor-bottom {
overflow: hidden;
position: absolute;
width: 100px;
height: 80px;
}
.flipdown .rotor-leaf {
z-index: 1;
position: absolute;
width: 100px;
height: 160px;
transform-style: preserve-3d;
transition: transform 0s;
}
.flipdown .rotor-leaf.flipped {
transform: rotateX(-180deg);
transition: all 0.5s ease-in-out;
}
.flipdown .rotor-leaf-front,
.flipdown .rotor-leaf-rear {
overflow: hidden;
position: absolute;
width: 100px;
height: 80px;
margin: 0;
transform: rotateX(0deg);
backface-visibility: hidden;
-webkit-backface-visibility: hidden;
}
.flipdown .rotor-leaf-front {
line-height: 160px;
border-radius: 8px 8px 0px 0px;
}
.flipdown .rotor-leaf-rear {
line-height: 0px;
border-radius: 0px 0px 8px 8px;
transform: rotateX(-180deg);
}
.flipdown .rotor-top {
line-height: 160px;
border-radius: 8px 8px 0px 0px;
}
.flipdown .rotor-bottom {
bottom: 0;
line-height: 0px;
border-radius: 0px 0px 8px 8px;
}
.flipdown .rotor:after {
content: '';
z-index: 2;
position: absolute;
bottom: 0px;
left: 0px;
width: 100px;
height: 80px;
border-radius: 0px 0px 8px 8px;
}
@media (max-width: 550px) {
.flipdown {
width: 510px; /* 312px; */
height: 110px; /* 70px; */
}
.flipdown .rotor {
font-size: 2.2rem;
margin-right: 6px;
}
.flipdown .rotor,
.flipdown .rotor-leaf,
.flipdown .rotor-leaf-front,
.flipdown .rotor-leaf-rear,
.flipdown .rotor-top,
.flipdown .rotor-bottom,
.flipdown .rotor:after {
width: 60px;
}
.flipdown .rotor-group {
padding-right: 40px;
}
.flipdown .rotor-group:last-child {
padding-right: 0px;
}
.flipdown .rotor-group-heading:before {
font-size: 1.6rem;
height: 40px;
line-height: 40px;
}
.flipdown .rotor-group:nth-child(n+1):nth-child(-n+2):before,
.flipdown .rotor-group:nth-child(n+1):nth-child(-n+2):after {
left: 69px;
}
.flipdown .rotor-group:nth-child(n+1):nth-child(-n+2):before {
bottom: 13px;
height: 16px;
width: 16px;
}
.flipdown .rotor-group:nth-child(n+1):nth-child(-n+2):after {
bottom: 29px;
height: 16px;
width: 16px;
}
.flipdown .rotor-leaf-front,
.flipdown .rotor-top {
line-height: 100px;
}
.flipdown .rotor-leaf,
.flipdown .rotor {
height: 100px;
}
.flipdown .rotor-leaf-front,
.flipdown .rotor-leaf-rear,
.flipdown .rotor-top,
.flipdown .rotor-bottom,
.flipdown .rotor:after {
height: 50px;
}
}
html {
height: 100%;
}
body {
margin: 0px;
height: 100%;
/* display: flex; */
align-items: center;
align-content: center;
}
body,
.example h1,
.example p,
.example .button {
transition: all .2s ease-in-out;
}
body.light-theme {
background-color: #151515;
}
body.light-theme .example h1 {
color: #FFFFFF;
}
body.light-theme .example p {
color: #FFFFFF;
}
body.light-theme .buttons .button {
color: #FFFFFF;
border-color: #FFFFFF;
}
body.light-theme .buttons .button:hover {
color: #151515;
background-color: #FFFFFF;
}
.example {
font-family: serif;
width: 90%; /* 550px; */
height: 20%; /* 378px; */
margin: auto;
padding: 40px;
box-sizing: border-box;
text-align: center;
}
.example .message1 {
font-family: serif;
text-align: center;
font-weight: 400;
font-size: 8em;
margin-top: 0;
margin-bottom: 20px;
}
.example .message2 {
font-family: serif;
text-align: center;
font-weight: 400;
font-size: 3em;
margin-top: 0;
margin-bottom: 20px;
}
.example .flipdown {
margin: auto;
}
.example h1 {
text-align: center;
font-weight: 100;
font-size: 6em;
margin-top: 0;
margin-bottom: 20px;
}
.example p {
text-align: center;
font-weight: 100;
margin-top: 0;
margin-bottom: 35px;
}
.example .buttons {
width: 100%;
height: 50px;
margin: 50px auto 0px auto;
display: flex;
align-items: center;
justify-content: space-around;
}
.example .buttons p {
height: 50px;
line-height: 50px;
font-weight: 400;
padding: 0px 25px 0px 0px;
color: #333;
margin: 0px;
}
.example .button {
display: inline-block;
height: 50px;
box-sizing: border-box;
line-height: 46px;
text-decoration: none;
color: #333;
padding: 0px 20px;
border: solid 2px #333;
border-radius: 4px;
text-transform: uppercase;
font-weight: 700;
transition: all .2s ease-in-out;
}
.example .button:hover {
background-color: #333;
color: #FFF;
}
.example .button i {
margin-right: 5px;
}
@media(max-width: 550px) {
.example {
width: 100%;
height: 20%; /* 362px; */
}
.example h1 {
font-size: 5em;
}
.example p {
margin-bottom: 25px;
}
.example .buttons {
width: 100%;
margin-top: 25px;
text-align: center;
display: block;
}
.example .buttons p,
.example .buttons a {
float: none;
margin: 0 auto;
}
.example .buttons p {
padding-right: 0px;
}
.example .buttons a {
display: inline-block;
}
}
</style>
</head>
<body>
<script>
/**
* @name FlipDown
* @description Flip styled countdown clock
* @author Peter Butcher (PButcher) <pbutcher93[at]gmail[dot]com>
* @param {number} uts - Time to count down to as unix timestamp
* @param {string} el - DOM element to attach FlipDown to
* @param {object} opt - Optional configuration settings
**/
class FlipDown {
constructor(uts, el = "flipdown", opt = {}) {
// If uts is not specified
if (typeof uts !== "number") {
throw new Error(
`FlipDown: Constructor expected unix timestamp, got ${typeof uts} instead.`
);
}
// If opt is specified, but not el
if (typeof el === "object") {
opt = el;
el = "flipdown";
}
// FlipDown version
this.version = "0.3.2";
// Initialised?
this.initialised = false;
// Time at instantiation in seconds
this.now = this._getTime();
// UTS to count down to
this.epoch = uts;
// UTS passed to FlipDown is in the past
this.countdownEnded = false;
// User defined callback for countdown end
this.hasEndedCallback = null;
// FlipDown DOM element
this.element = document.getElementById(el);
// Rotor DOM elements
this.rotors = [];
this.rotorLeafFront = [];
this.rotorLeafRear = [];
this.rotorTops = [];
this.rotorBottoms = [];
// Interval
this.countdown = null;
// Number of days remaining
//this.daysRemaining = 0;
// Clock values as numbers
this.clockValues = {};
// Clock values as strings
this.clockStrings = {};
// Clock values as array
this.clockValuesAsString = [];
this.prevClockValuesAsString = [];
// Parse options
this.opts = this._parseOptions(opt);
// Set options
this._setOptions();
// Print Version
console.log(`FlipDown ${this.version} (Theme: ${this.opts.theme})`);
}
/**
* @name start
* @description Start the countdown
* @author PButcher
**/
start() {
// Initialise the clock
if (!this.initialised) this._init();
// Set up the countdown interval
this.countdown = setInterval(this._tick.bind(this), 1000);
// Chainable
return this;
}
/**
* @name ifEnded
* @description Call a function once the countdown ends
* @author PButcher
* @param {function} cb - Callback
**/
ifEnded(cb) {
this.hasEndedCallback = function () {
cb();
this.hasEndedCallback = null;
};
// Chainable
return this;
}
/**
* @name _getTime
* @description Get the time in seconds (unix timestamp)
* @author PButcher
**/
_getTime() {
return new Date().getTime() / 1000;
}
/**
* @name _hasCountdownEnded
* @description Has the countdown ended?
* @author PButcher
**/
_hasCountdownEnded() {
// Countdown has ended
if (this.epoch - this.now < 0) {
this.countdownEnded = true;
// Fire the ifEnded callback once if it was set
if (this.hasEndedCallback != null) {
// Call ifEnded callback
this.hasEndedCallback();
// Remove the callback
this.hasEndedCallback = null;
}
return true;
// Countdown has not ended
} else {
this.countdownEnded = false;
return false;
}
}
/**
* @name _parseOptions
* @description Parse any passed options
* @param {object} opt - Optional configuration settings
* @author PButcher
**/
_parseOptions(opt) {
//let headings = ["Days", "Hours", "Minutes", "Seconds"];
let headings = ["Hours", "Minutes", "Seconds"];
//if (opt.headings && opt.headings.length === 4) {
if (opt.headings && opt.headings.length === 3) {
headings = opt.headings;
}
return {
// Theme
theme: opt.hasOwnProperty("theme") ? opt.theme : "dark",
headings,
};
}
/**
* @name _setOptions
* @description Set optional configuration settings
* @author PButcher
**/
_setOptions() {
// Apply theme
this.element.classList.add(`flipdown__theme-${this.opts.theme}`);
}
/**
* @name _init
* @description Initialise the countdown
* @author PButcher
**/
_init() {
this.initialised = true;
// Check whether countdown has ended and calculate how many digits the day counter needs
/*
if (this._hasCountdownEnded()) {
this.daysremaining = 0;
} else {
this.daysremaining = Math.floor(
(this.epoch - this.now) / 86400
).toString().length;
}
var dayRotorCount = this.daysremaining <= 2 ? 2 : this.daysremaining;
*/
// Create and store rotors
//for (var i = 0; i < dayRotorCount + 6; i++) {
for (var i = 0; i < 6; i++) {
this.rotors.push(this._createRotor(0));
}
// Create day rotor group
/*
var dayRotors = [];
for (var i = 0; i < dayRotorCount; i++) {
dayRotors.push(this.rotors[i]);
}
this.element.appendChild(this._createRotorGroup(dayRotors, 0));
*/
// Create other rotor groups
//var count = dayRotorCount;
var count = 0;
for (var i = 0; i < 3; i++) {
var otherRotors = [];
for (var j = 0; j < 2; j++) {
otherRotors.push(this.rotors[count]);
count++;
}
//this.element.appendChild(this._createRotorGroup(otherRotors, i + 1));
this.element.appendChild(this._createRotorGroup(otherRotors, i));
}
// Store and convert rotor nodelists to arrays
this.rotorLeafFront = Array.prototype.slice.call(
this.element.getElementsByClassName("rotor-leaf-front")
);
this.rotorLeafRear = Array.prototype.slice.call(
this.element.getElementsByClassName("rotor-leaf-rear")
);
this.rotorTop = Array.prototype.slice.call(
this.element.getElementsByClassName("rotor-top")
);
this.rotorBottom = Array.prototype.slice.call(
this.element.getElementsByClassName("rotor-bottom")
);
// Set initial values;
this._tick();
this._updateClockValues(true);
return this;
}
/**
* @name _createRotorGroup
* @description Add rotors to the DOM
* @author PButcher
* @param {array} rotors - A set of rotors
**/
_createRotorGroup(rotors, rotorIndex) {
var rotorGroup = document.createElement("div");
rotorGroup.className = "rotor-group";
var dayRotorGroupHeading = document.createElement("div");
dayRotorGroupHeading.className = "rotor-group-heading";
//dayRotorGroupHeading.id = "rotor-group-heading" + rotorIndex;
dayRotorGroupHeading.setAttribute(
"data-before",
this.opts.headings[rotorIndex]
);
rotorGroup.appendChild(dayRotorGroupHeading);
appendChildren(rotorGroup, rotors);
return rotorGroup;
}
/**
* @name _createRotor
* @description Create a rotor DOM element
* @author PButcher
* @param {number} v - Initial rotor value
**/
_createRotor(v = 0) {
var rotor = document.createElement("div");
var rotorLeaf = document.createElement("div");
var rotorLeafRear = document.createElement("figure");
var rotorLeafFront = document.createElement("figure");
var rotorTop = document.createElement("div");
var rotorBottom = document.createElement("div");
rotor.className = "rotor";
rotorLeaf.className = "rotor-leaf";
rotorLeafRear.className = "rotor-leaf-rear";
rotorLeafFront.className = "rotor-leaf-front";
rotorTop.className = "rotor-top";
rotorBottom.className = "rotor-bottom";
rotorLeafRear.textContent = v;
rotorTop.textContent = v;
rotorBottom.textContent = v;
appendChildren(rotor, [rotorLeaf, rotorTop, rotorBottom]);
appendChildren(rotorLeaf, [rotorLeafRear, rotorLeafFront]);
return rotor;
}
/**
* @name _tick
* @description Calculate current tick
* @author PButcher
**/
_tick() {
// Get time now
this.now = this._getTime();
// Between now and epoch
var diff = this.epoch - this.now <= 0 ? 0 : this.epoch - this.now;
// Days remaining
this.clockValues.d = Math.floor(diff / 86400);
diff -= this.clockValues.d * 86400;
// Hours remaining
this.clockValues.h = Math.floor(diff / 3600);
diff -= this.clockValues.h * 3600;
// Minutes remaining
this.clockValues.m = Math.floor(diff / 60);
diff -= this.clockValues.m * 60;
// Seconds remaining
this.clockValues.s = Math.floor(diff);
// Update clock values
this._updateClockValues();
// Has the countdown ended?
this._hasCountdownEnded();
}
/**
* @name _updateClockValues
* @description Update the clock face values
* @author PButcher
* @param {boolean} init - True if calling for initialisation
**/
_updateClockValues(init = false) {
// Build clock value strings
//this.clockStrings.d = pad(this.clockValues.d, 2);
this.clockStrings.h = pad(this.clockValues.h, 2);
this.clockStrings.m = pad(this.clockValues.m, 2);
this.clockStrings.s = pad(this.clockValues.s, 2);
// Concat clock value strings
this.clockValuesAsString = (
//this.clockStrings.d +
this.clockStrings.h +
this.clockStrings.m +
this.clockStrings.s
).split("");
// Update rotor values
// Note that the faces which are initially visible are:
// - rotorLeafFront (top half of current rotor)
// - rotorBottom (bottom half of current rotor)
// Note that the faces which are initially hidden are:
// - rotorTop (top half of next rotor)
// - rotorLeafRear (bottom half of next rotor)
this.rotorLeafFront.forEach((el, i) => {
el.textContent = this.prevClockValuesAsString[i];
});
this.rotorBottom.forEach((el, i) => {
el.textContent = this.prevClockValuesAsString[i];
});
function rotorTopFlip() {
this.rotorTop.forEach((el, i) => {
if (el.textContent != this.clockValuesAsString[i]) {
el.textContent = this.clockValuesAsString[i];
}
});
}
function rotorLeafRearFlip() {
this.rotorLeafRear.forEach((el, i) => {
if (el.textContent != this.clockValuesAsString[i]) {
el.textContent = this.clockValuesAsString[i];
el.parentElement.classList.add("flipped");
var flip = setInterval(
function () {
el.parentElement.classList.remove("flipped");
clearInterval(flip);
}.bind(this),
500
);
}
});
}
// Init
if (!init) {
setTimeout(rotorTopFlip.bind(this), 500);
setTimeout(rotorLeafRearFlip.bind(this), 500);
} else {
rotorTopFlip.call(this);
rotorLeafRearFlip.call(this);
}
// Save a copy of clock values for next tick
this.prevClockValuesAsString = this.clockValuesAsString;
}
}
/**
* @name pad
* @description Prefix a number with zeroes
* @author PButcher
* @param {string} n - Number to pad
* @param {number} len - Desired length of number
**/
function pad(n, len) {
n = n.toString();
return n.length < len ? pad("0" + n, len) : n;
}
/**
* @name appendChildren
* @description Add multiple children to an element
* @author PButcher
* @param {object} parent - Parent
**/
function appendChildren(parent, children) {
children.forEach((el) => {
parent.appendChild(el);
});
}
// TIMED_MESSAGE item format:
/*
[
Start Time HH,
Start Time MM,
Start Time SS,
End Time HH,
End Time MM,
End Time SS,
Large Message,
Large Message Second Language,
Small Message,
Small Message Second Language
]
*/
const TIMED_MESSAGES = [
[0,0,0,9,14,45,"You May Pass", "Pueden Pasar", "Period 1 begins at 9:15am", "El período 1 comienza a las 9:15am"],
[9,14,45,10,34,45,"Pass Required","Necesita Un Pase", "Period 1 ends at 10:35am", "El período 1 termina a las 10:35am"],
[10,34,45,10,39,45,"You May Pass", "Pueden Pasar", "Period 2 begins at 10:40am", "El período 2 comienza a las 10:40am"],
[10,39,45,11,59,45,"Pass Required","Necesita Un Pase", "Period 2 ends at 12:00pm", "El período 2 termina a las 12:00pm"],
[11,59,45,12,4,45,"You May Pass","Pueden Pasar","Lunch A Transition - No Pass Required","Transición al almuerzo A - No Se Requiere Un Pase"],
[12,4,45,12,39,45,"Pass Required","Necesita Un Pase","Lunch A ends at 12:40pm","El almuerzo A termina a las 12:40pm"],
[12,39,45,12,44,45,"You May Pass","Pueden Pasar","Lunch B Transition - No Pass Required","Transición al almuerzo - No Se Requiere Un Pase"],
[12,44,45,13,24,45,"Pass Required","Necesita Un Pase","Lunch B ends at 1:25pm","El almuerzo B termina a las 1:25pm"],
[13,24,45,13,29,45,"You May Pass", "Pueden Pasar", "Period 3 begins at 1:30pm", "El período 3 comienza a las 1:30pm"],
[13,29,45,14,49,45,"Pass Required","Necesita Un Pase", "Period 3 ends at 2:50pm", "El período 3 termina a las 2:50pm"],
[14,49,45,14,54,45,"You May Pass", "Pueden Pasar", "Period 4 begins at 2:55pm", "El período 4 comienza a las 2:55pm"],
[14,54,45,16,14,45,"Pass Required","Necesita Un Pase", "Period 4 ends at 4:15pm", "El período 4 termina a las 4:15pm"],
[16,14,45,23,59,59,"You May Pass","Pueden Pasar", "Go forth and make it a great evening.", "Sigamos adelante y tengamos una buen tarde."]
];
// Example: 1726161900.669 = timer ends at 1:25pm on 9/12/2024.
function DisplayTimerMessage(altLanguage) {
let dateNow = new Date();
let dateStart = new Date();
let dateEnd = new Date();
let headings = ["Hours", "Minutes", "Seconds"];
let headingsAlt = ["Horas", "Minutos", "Segundos"];
for (let i = 0; i < TIMED_MESSAGES.length; i++) {
dateStart.setHours(TIMED_MESSAGES[i][0]);
dateStart.setMinutes(TIMED_MESSAGES[i][1]);
dateStart.setSeconds(TIMED_MESSAGES[i][2]);
dateEnd.setHours(TIMED_MESSAGES[i][3]);
dateEnd.setMinutes(TIMED_MESSAGES[i][4]);
dateEnd.setSeconds(TIMED_MESSAGES[i][5]);
if (dateStart <= dateNow && dateNow < dateEnd) {
//let timerSeconds = ((dateEnd.getTime() - dateNow.getTime()) / 1000;
let timerEnd = dateEnd.getTime() / 1000;
//console.log("Timer set for " + timerStart);
var msg1 = document.getElementById('message1');
var msg2 = document.getElementById('message2');
//var heading0 = document.getElementById('rotor-group-heading0');
//var heading1 = document.getElementById('rotor-group-heading1');
//var heading2 = document.getElementById('rotor-group-heading2');
if (altLanguage) {
msg1.innerHTML = TIMED_MESSAGES[i][7];
msg2.innerHTML = TIMED_MESSAGES[i][9];
//heading0.setAttribute("data-before", headingsAlt[0]);
//heading1.setAttribute("data-before", headingsAlt[1]);
//heading2.setAttribute("data-before", headingsAlt[2]);
} else {
msg1.innerHTML = TIMED_MESSAGES[i][6];
msg2.innerHTML = TIMED_MESSAGES[i][8];
//heading0.setAttribute("data-before", headings[0]);
//heading1.setAttribute("data-before", headings[1]);
//heading2.setAttribute("data-before", headings[2]);
}
// Set timerEnd to seven seconds from now for testing purposes.
// TODO: comment this out.
//timerEnd = dateNow.getTime() / 1000 + 7;
return timerEnd;
}
}
return new Date().getTime() / 1000 + 60;
}
function ResetFlipDownElement() {
fdElement = document.getElementById("flipdown");
let fdParent = fdElement.parentElement;
fdParent.innerHTML = ''; // Clear all children quickly.
fdParent.innerHTML = '<div id="flipdown" class="flipdown"></div>';
var altLang = false;
var timerEnd = DisplayTimerMessage();
console.log("Timer set to " + timerEnd);
var flipdown = new FlipDown(timerEnd)
// Start the countdown
.start()
// Do something when the countdown ends
.ifEnded(() => {
console.log('The countdown has ended!');
ResetFlipDownElement();
});
}
/*
function UpdateFlipDown() {