-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsidelineES6.html
More file actions
executable file
·649 lines (518 loc) · 18.1 KB
/
sidelineES6.html
File metadata and controls
executable file
·649 lines (518 loc) · 18.1 KB
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
<!DOCTYPE html>
<html>
<!-- What I authored here: The JS: (none) The CSS: 20% The text content: 90% -->
<head>
<title>Modern Javascript | Evan Genest</title>
<meta charset="utf-8">
<script src="https://kit.fontawesome.com/c0497ccda4.js"></script>
<link rel="icon" type="image/png" href="images/dryer.png" />
<style type="text/css">
*,
*::before,
*::after {
margin: 0;
padding: 0;
box-sizing: border-box;
}
@font-face {
font-family: Deibi;
src: url(./fonts/deibi.otf);
}
:root{
--main-color: #F45B69;
}
body {
font-family: "Helvetica Neue", sans-serif;
}
a:link {
color: white;
}
a:hover {
color: yellow;
}
a:visited {
color: white;
}
h1 a:hover {
color: yellow;
}
/* .section SECTION
–––––––––––––––––––––––––––––––––––––––––––––––––– */
.section {
padding: 1.1rem 0;
border-bottom: solid var(--main-color) 0.8rem;
}
section.timeline ol li div time{
z-index: 2;
/* todo THIS DOESNT KEEP CARDS BEHIND THE BUTTONS*/
}
.section .container {
width: 90%;
max-width: 1200px;
margin: 0 auto;
text-align: center;
}
.section h1 {
font-size: 2.5rem;
}
section.timeline ol li div time {
color: var(--main-color);
font-size: 1.5rem;
font-family: Deibi;
}
section.section div.container h1 {
font-family: Deibi;
font-size: 3rem;
color: white;
text-shadow: 2px 2px 18px #000000;
}
.lined {
float: left ;
}
.cleared {
clear: both;
}
.tiny-text-holder {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
xborder: solid black 0.2rem;
height: 3rem;
}
.tiny-text {
font-size: 0.8rem;
xborder: solid black 0.2rem;
color: black;
margin: auto 2rem;
}
/* TIMELINE
–––––––––––––––––––––––––––––––––––––––––––––––––– */
/*http://www.heropatterns.com/ made the following background pattern */
.timeline {
white-space: nowrap;
overflow-x: hidden;
background-color: #eeeeee;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='88' height='88' viewBox='0 0 88 88'%3E%3Cg fill='%23e0e0e0' fill-opacity='0.4'%3E%3Cpath fill-rule='evenodd' d='M29.42 29.41c.36-.36.58-.85.58-1.4V0h-4v26H0v4h28c.55 0 1.05-.22 1.41-.58h.01zm0 29.18c.36.36.58.86.58 1.4V88h-4V62H0v-4h28c.56 0 1.05.22 1.41.58zm29.16 0c-.36.36-.58.85-.58 1.4V88h4V62h26v-4H60c-.55 0-1.05.22-1.41.58h-.01zM62 26V0h-4v28c0 .55.22 1.05.58 1.41.37.37.86.59 1.41.59H88v-4H62zM18 36c0-1.1.9-2 2-2h10a2 2 0 1 1 0 4H20a2 2 0 0 1-2-2zm0 16c0-1.1.9-2 2-2h10a2 2 0 1 1 0 4H20a2 2 0 0 1-2-2zm16-26a2 2 0 0 1 2-2 2 2 0 0 1 2 2v4a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-4zm16 0a2 2 0 0 1 2-2 2 2 0 0 1 2 2v4a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-4zM34 58a2 2 0 0 1 2-2 2 2 0 0 1 2 2v4a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-4zm16 0a2 2 0 0 1 2-2 2 2 0 0 1 2 2v4a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-4zM34 78a2 2 0 0 1 2-2 2 2 0 0 1 2 2v6a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-6z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 0 0 4zm-48 0a2 2 0 1 0 0-4 2 2 0 0 0 0 4zm0-48a2 2 0 1 0 0-4 2 2 0 0 0 0 4zm24 32a10 10 0 1 1 0-20 10 10 0 0 1 0 20zm0-4a6 6 0 1 0 0-12 6 6 0 0 0 0 12zm36-36a6 6 0 1 1 0-12 6 6 0 0 1 0 12zm0-4a2 2 0 1 0 0-4 2 2 0 0 0 0 4zM10 44c0-1.1.9-2 2-2h8a2 2 0 1 1 0 4h-8a2 2 0 0 1-2-2zm56 0c0-1.1.9-2 2-2h8a2 2 0 1 1 0 4h-8a2 2 0 0 1-2-2zm8 24c0-1.1.9-2 2-2h8a2 2 0 1 1 0 4h-8a2 2 0 0 1-2-2zM3 68c0-1.1.9-2 2-2h8a2 2 0 1 1 0 4H5a2 2 0 0 1-2-2zm0-48c0-1.1.9-2 2-2h8a2 2 0 1 1 0 4H5a2 2 0 0 1-2-2zm71 0c0-1.1.9-2 2-2h8a2 2 0 1 1 0 4h-8a2 2 0 0 1-2-2zm6 66a6 6 0 1 1 0-12 6 6 0 0 1 0 12zm0-4a2 2 0 1 0 0-4 2 2 0 0 0 0 4zM8 86a6 6 0 1 1 0-12 6 6 0 0 1 0 12zm0-4a2 2 0 1 0 0-4 2 2 0 0 0 0 4zm0-68A6 6 0 1 1 8 2a6 6 0 0 1 0 12zm0-4a2 2 0 1 0 0-4 2 2 0 0 0 0 4zm36 36a2 2 0 1 0 0-4 2 2 0 0 0 0 4z'/%3E%3C/g%3E%3C/svg%3E");
}
.timeline ol {
font-size: 0;
width: 100vw;
padding: 250px 0;
transition: all 1s;
}
.timeline ol li {
position: relative;
display: inline-block;
list-style-type: none;
width: 160px;
height: 3px;
background: #fff;
}
.timeline ol li:last-child {
width: 280px;
}
.timeline ol li:not(:first-child) {
margin-left: 14px;
}
.timeline ol li:not(:last-child)::after {
content: '';
position: absolute;
top: 50%;
left: calc(100% + 1px);
bottom: 0;
width: 12px;
height: 12px;
transform: translateY(-50%);
border-radius: 50%;
background: var(--main-color);
}
.timeline ol li div {
position: absolute;
left: calc(100% + 7px);
width: 280px;
padding: 15px;
font-size: 1rem;
white-space: normal;
color: black;
background: white;
}
.timeline ol li div::before {
content: '';
position: absolute;
top: 100%;
left: 0;
width: 0;
height: 0;
border-style: solid;
}
.timeline ol li:nth-child(odd) div {
top: -16px;
transform: translateY(-100%);
}
.timeline ol li:nth-child(odd) div::before {
top: 100%;
border-width: 8px 8px 0 0;
border-color: white transparent transparent transparent;
}
.timeline ol li:nth-child(even) div {
top: calc(100% + 16px);
}
.timeline ol li:nth-child(even) div::before {
top: -8px;
border-width: 8px 0 0 8px;
border-color: transparent transparent transparent white;
}
.timeline time {
display: block;
font-size: 1.2rem;
font-weight: bold;
margin-bottom: 8px;
}
/* ARROWS and BUTTONS
–––––––––––––––––––––––––––––––––––––––––––––––––– */
button.arrow {
background: transparent;
border: none;
cursor: pointer;
outline: none;
font-size: 2rem;
z-index: 99;
}
button.arrow:hover {
color: yellow;
}
.timeline .arrows {
display: flex;
justify-content: center;
margin-bottom: 20px;
}
.timeline .arrows .arrow__prev {
margin-right: 20px;
}
.timeline .disabled {
opacity: .5;
}
.timeline .arrows img {
width: 45px;
height: 45px;
}
.button-2 {
background-color:var(--main-color);
-moz-border-radius:35px;
-webkit-border-radius:35px;
border-radius:20px;
border:3px solid white;
display:inline-block;
cursor:pointer;
color:white;
font-family:"Trebuchet MS", monospace;
font-size:17px;
padding:8px 12px;
text-decoration:none;
text-shadow:1px 2px 4px #2b665e;
margin: 12px;
z-index: 99;
}
.button-2:hover {
background-color:#456990;
color: yellow;
}
.button-2:active {
position:relative;
top:1px;
}
/* GENERAL MEDIA QUERIES
–––––––––––––––––––––––––––––––––––––––––––––––––– */
@media screen and (max-width: 599px) {
.timeline ol,
.timeline ol li {
width: auto;
}
.timeline ol {
padding: 0;
transform: none !important;
}
.timeline ol li {
display: block;
height: auto;
background: transparent;
}
.timeline ol li:first-child {
margin-top: 25px;
}
.timeline ol li:not(:first-child) {
margin-left: auto;
}
.timeline ol li div {
width: 94%;
height: auto !important;
margin: 0 auto 25px;
}
.timeline ol li div {
position: static;
}
.timeline ol li:nth-child(odd) div {
transform: none;
}
.timeline ol li:nth-child(odd) div::before,
.timeline ol li:nth-child(even) div::before {
left: 50%;
top: 100%;
transform: translateX(-50%);
border: none;
border-left: 1px solid white;
height: 25px;
}
.timeline ol li:last-child,
.timeline ol li:nth-last-child(2) div::before,
.timeline ol li:not(:last-child)::after,
.timeline .arrows {
display: none;
}
}
</style>
</head>
<body>
<section class="section" >
<div class="container">
<h1 class="lined"><a href="https://webapplog.com/es6/" > Top Ten ES6 Features</a></h1>
<div class="tiny-text-holder" >
<div class="lined tiny-text"><p>I made these notecards to help me study.<br>I borrowed and pasted several resources to create this page. <br>Scroll the timeline using arrows on the keyboard or leftclick the arrows.</p></div>
</div>
<div class="cleared"></div>
</div>
</section>
<section class="timeline">
<ol>
<li>
<div>
<time>Default Parameters</time> <p> These are written as EQUALS in the arguments. So...<br>var link = function(height = 50, color = 'red', url = 'http://example.com') { ... }
</p></div>
</li>
<li>
<div>
<time>Template Literals</time> <p>Instead of sticking the variable inside a 'string sandwich', you can use tic marks as quotes. e.g. let s = `Hello ${my-dude}.`
</p></div>
</li>
<li>
<div>
<time>Multi-line strings</time> <p id="slider-1">The tic mark "`" can do multi-line quotes.
</p></div>
</li>
<li>
<div>
<img src="https://picsum.photos/250/140?grayscale&random=1" alt="Check out es6-features.org (not my site).">
</div>
</li>
<li>
<div>
<time>... three dots ...</time> <p> This is the ES6 Spread Operator.
</p></div>
</li>
<li>
<div>
<time>Computed Property Name</time> <p> In React we can add a partial state to the setState() function. We do it succinctly: <br>this.setState({<br>
[name]: value<br>});
</p></div>
</li>
<li>
<div>
<time>"CLASS" #1</time> <p> You can make a class now. React uses class. Things in React can't be stateful unless they are a CLASS.
</p></div>
</li>
<li>
<div>
<time>Destructuring #1</time> <p> ES5 version:
</p><img src="images/code1-120x43.png"><p>
ES6 version:
var {username, password} = req.body
</p></div>
</li>
<li>
<div>
<img src="https://picsum.photos/250/140?grayscale&random=2" alt="Check out https://exploringjs.com/es6">
</div>
</li>
<li>
<div>
<time>Destructuring #2</time> <p class="tiny-text"> I call this "The Chopper". Feed in an IMPLIED property of the object and, with the same name, it pops out as an available argument. Example syntax: const {foo} = this.props<br>const {bar} = this.state<br> where foo and bar were properties of those rightside objects. See p. 20 in Pragmatic Programmer React by Fischer!
</p></div>
</li>
<li>
<div>
<time>Implied Return</time> <p> Fat arrow functions with one ARG can look like this in React: item => ELEMENT foo {item.toUpperCase()} bar /ELEMENT
</p></div>
</li>
<li>
<div>
<time>"CLASS" #2</time> <p> Very OO!<br/>methods have no "function" keyword! Typical methods have render(), constructor(), and constructor(props) followed by super(props)
</p></div>
</li>
<li>
<div>
<time>CLASS #3</time> <p> Outside of React, the constructor might look like CONSTRUCTOR(first, last){this.first = first; this.last = last}<br/>And then call with:<br />const author1 = new Person("rachel", "carson");
</p></div>
</li>
<li>
<div>
<time>CONST</time> <p> Cannot reassign CONST if a primitive. But CAN add properties til the sun goes down.<br/><br /> Make CONST your default mode. It shows your commitment to immutability. :^)
</p></div>
</li>
<li>
<div>
<time>LITERALS</time> <p> New object literal syntax
</p></div>
</li>
</li>
<li>
<div>
<time>SPREAD</time> <p> Rest & Spread
</p></div>
</li> </li>
<li>
<div>
<time>CLASS</time> <p> "Use class in React components but avoid them otherwise, generally." -Samer Goba
</p></div>
</li> </li>
<li>
<div>
<time>Shadowing the <code>this</code></time> <p> Inside of an ES6 arrow function, you can see an inherited <code>this</code> from the outer scope.
</p></div>
</li> </li>
<li>
<div>
<time>YABBA</time> <p> Yabba, Dabba, Do!
</p></div>
</li> <li></li>
</ol>
<div class="arrows lined">
<button class="arrow arrow__prev disabled" disabled>
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/162656/arrow_prev.svg" alt="prev timeline arrow">
</button>
<button class="arrow arrow__next">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/162656/arrow_next.svg" alt="next timeline arrow">
</button>
</div>
<a href="https://webapplog.com/es6/" class="button-2 lined" title="Thanks for the list of favorite ES6 features!">thanks Azat!</a>
<a href="https://webdesign.tutsplus.com/tutorials/building-a-horizontal-timeline-with-css-and-javascript--cms-28378" class="button-2 lined" title="Thanks for 90% of the CSS and JS on this page!" >thanks Envato!</a>
<a href="https://heropatterns.com/" id="handle" title="Thanks for the SVG background." class="button-2 lined">thanks HeroPatterns!</a>
<a href="https://picsum.photos" title="Thanks for the random photos." class="button-2 lined">thanks Picsum!</a>
</section>
<script type="text/javascript">
/*
I was surprised how much CSS there was to this.
It does not look impressive but there is a bunch of CSS to make the divs go sideways.
Then, there is a bunch of JS to make the animation and the arrows.
George Martsoukos does a patient job of explaining the JS for this in a tutorial https://webdesign.tutsplus.com/tutorials/building-a-horizontal-timeline-with-css-and-javascript--cms-28378
*/
// TEST TODO
// console.log( document.getElementsByTagName('div')[0].attributes.length + " apple--->");
// console.log(document.getElementById('slider-1').attributes.length);
// console.log(document.getElementsByTagName('ol')[0].childNodes);
(function() {
// VARIABLES
// TODO put this back: timeline = document.querySelector(".timeline ol"),
var
timeline = document.getElementsByTagName('ol')[0],
elH = document.querySelectorAll(".timeline li > div"),
arrows = document.querySelectorAll(".timeline .arrows .arrow"),
arrowPrev = document.querySelector(".timeline .arrows .arrow__prev"),
arrowNext = document.querySelector(".timeline .arrows .arrow__next"),
firstItem = document.querySelector(".timeline li:first-child"),
lastItem = document.querySelector(".timeline li:last-child"),
xScrolling = 560,
disabledClass = "disabled";
// START
window.addEventListener("DOMContentLoaded", init);
function init() {
setEqualHeights(elH);
animateTl(xScrolling, arrows, timeline);
setKeyboardFn(arrowPrev, arrowNext);
}
// SET EQUAL HEIGHTS this is very cool! October 1, 2019
function setEqualHeights(el) {
let counter = 0;
for (let i = 0; i < el.length; i++) {
const singleHeight = el[i].offsetHeight;
if (counter < singleHeight) {
counter = singleHeight;
}
}
for (let i = 0; i < el.length; i++) {
el[i].style.height = `${counter}px`;
}
}
// CHECK IF AN ELEMENT IS IN VIEWPORT
// http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport
function isElementInViewport(el) {
const rect = el.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
// SET STATE OF PREV/NEXT ARROWS
function setBtnState(el, flag = true) {
if (flag) {
el.classList.add(disabledClass);
} else {
if (el.classList.contains(disabledClass)) {
el.classList.remove(disabledClass);
}
el.disabled = false;
}
}
// ANIMATE TIMELINE
function animateTl(scrolling, el, tl) {
let counter = 0;
for (let i = 0; i < el.length; i++) {
el[i].addEventListener("click", function() {
if (!arrowPrev.disabled) {
arrowPrev.disabled = true;
}
if (!arrowNext.disabled) {
arrowNext.disabled = true;
}
const sign = (this.classList.contains("arrow__prev")) ? "" : "-";
if (counter === 0) {
tl.style.transform = `translateX(-${scrolling}px)`;
} else {
const tlStyle = getComputedStyle(tl);
// add more browser prefixes if needed here
const tlTransform = tlStyle.getPropertyValue("-webkit-transform") || tlStyle.getPropertyValue("transform");
const values = parseInt(tlTransform.split(",")[4]) + parseInt(`${sign}${scrolling}`);
tl.style.transform = `translateX(${values}px)`;
}
setTimeout(() => {
isElementInViewport(firstItem) ? setBtnState(arrowPrev) : setBtnState(arrowPrev, false);
isElementInViewport(lastItem) ? setBtnState(arrowNext) : setBtnState(arrowNext, false);
}, 600);
counter++;
});
}
}
// ADD BASIC KEYBOARD FUNCTIONALITY
function setKeyboardFn(prev, next) {
// console.log("Works 122.");
document.addEventListener("keydown", (e) => {
if ((e.which === 37) || (e.which === 39)) {
const timelineOfTop = timeline.offsetTop;
const y = window.pageYOffset;
if (timelineOfTop !== y) {
window.scrollTo(0, timelineOfTop);
}
if (e.which === 37) {
prev.click();
} else if (e.which === 39) {
next.click();
}
}
});
}
})();
</script>
</body>
</html>