Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 73c01a0

Browse files
committed
Code for ch 12 and 13
1 parent 9ff8e59 commit 73c01a0

File tree

5 files changed

+74
-3
lines changed

5 files changed

+74
-3
lines changed

11 - Custom Video Player/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<link rel="stylesheet" href="style.css">
77
</head>
88
<body>
9-
109
<div class="player">
1110
<video class="player__video viewer" src="https://player.vimeo.com/external/194837908.sd.mp4?s=c350076905b78c67f74d7ee39fdb4fef01d12420&profile_id=164"></video>
1211

11 - Custom Video Player/scripts.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
const player = document.querySelector('.player');
2+
const video = player.querySelector('.viewer');
3+
const progress = player.querySelector('.progress');
4+
const progressBar = player.querySelector('.progress__filled');
5+
const toggle = player.querySelector('.toggle');
6+
const skipButtons = player.querySelectorAll('[data-skip]');
7+
const ranges = player.querySelectorAll('.player__slider');
8+
9+
function togglePlay() {
10+
const method = video.paused ? 'play' : 'pause';
11+
video[method]();
12+
}
13+
14+
function updateButton() {
15+
toggle.textContent = this.paused ? '►' : '❚ ❚';
16+
}
17+
18+
function skip() {
19+
video.currentTime += parseFloat(this.dataset.skip);
20+
}
21+
22+
function handleRangeUpdate() {
23+
video[this.name] = this.value;
24+
}
25+
26+
function handleProgress() {
27+
const percent = (video.currentTime / video.duration) * 100;
28+
progressBar.style.flexBasis = `${percent}%`;
29+
}
30+
31+
function scrub(e) {
32+
const scrubTime = (e.offsetX / progress.offsetWidth) * video.duration;
33+
video.currentTime = scrubTime;
34+
}
35+
36+
video.addEventListener('click', togglePlay);
37+
video.addEventListener('play', updateButton);
38+
video.addEventListener('pause', updateButton);
39+
video.addEventListener('timeupdate', handleProgress);
40+
41+
skipButtons.forEach(button => button.addEventListener('click', skip));
42+
43+
ranges.forEach(range => range.addEventListener('change', handleRangeUpdate));
44+
45+
// TODO: Improve, only use with clicked flag
46+
ranges.forEach(range => range.addEventListener('mousemove', handleRangeUpdate));
47+
48+
toggle.addEventListener('click', togglePlay);
49+
50+
let mouseDown = false;
51+
progress.addEventListener('click', scrub);
52+
progress.addEventListener('mousemove', (e) => mouseDown && scrub(e));
53+
54+
progress.addEventListener('mousedown', () => mouseDown = true);
55+
progress.addEventListener('mouseup', () => mouseDown = false);
56+
57+
// TODO: Add fullscreen button to bottom right

12 - Key Sequence Detection/index-START.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
<head>
44
<meta charset="UTF-8">
55
<title>Key Detection</title>
6+
<link rel="stylesheet" href="style.css">
67
<script type="text/javascript" src="http://www.cornify.com/js/cornify.js"></script>
78
</head>
89
<body>
9-
<script>
10-
</script>
10+
11+
<script src="scripts.js"></script>
1112
</body>
1213
</html>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const pressed = [];
2+
const secretCode = 'omgwtfbbqmybffjill';
3+
4+
window.addEventListener('keyup', (e) => {
5+
pressed.push(e.key);
6+
// constantly expunges extraneous characters
7+
pressed.splice(-secretCode.length - 1, pressed.length - secretCode.length);
8+
9+
if (pressed.join('').includes(secretCode)) {
10+
console.log('result!');
11+
cornify_add();
12+
}
13+
});

12 - Key Sequence Detection/style.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/* styles */

0 commit comments

Comments
 (0)