Skip to content

Commit d08d7ae

Browse files
committed
lesson wesbos#15 done
1 parent 7572a9b commit d08d7ae

File tree

6 files changed

+91
-3
lines changed

6 files changed

+91
-3
lines changed

12 - Key Sequence Detection/index-START.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@
77
</head>
88
<body>
99
<script>
10+
const secret = 'remars';
11+
const ev = [];
12+
13+
document.addEventListener('keyup', (e) => {
14+
ev.push(e.key);
15+
console.log(ev);
16+
ev.splice(-secret.length -1, ev.length - secret.length);
17+
18+
if (ev.join('').includes(secret)) {
19+
console.log('ding dong');
20+
cornify_add();
21+
}
22+
23+
})
1024
</script>
1125
</body>
1226
</html>

13 - Slide in on Scroll/index-START.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,26 @@ <h1>Slide in on Scroll</h1>
5858
};
5959
}
6060

61+
const slideImages = document.querySelectorAll('.slide-in');
62+
63+
function scrolled(e) {
64+
slideImages.forEach(image => {
65+
const slideInAt = (window.scrollY + window.innerHeight) - image.height / 2;
66+
const imageBottom = image.offsetTop + image.height;
67+
const isHalfShow = slideInAt > image.offsetTop;
68+
const isNotScrolledPast = window.scrollY < imageBottom;
69+
if (isHalfShow && isNotScrolledPast) {
70+
image.classList.add('active');
71+
} else {
72+
image.classList.remove('active');
73+
}
74+
75+
});
76+
77+
}
78+
79+
window.addEventListener('scroll', debounce(scrolled));
80+
6181
</script>
6282

6383
<style>

14 - JavaScript References VS Copying/index-START.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414

1515
// and we want to make a copy of it.
1616

17+
const play1 = players.slice();
18+
const play2 = [].concat(players);
19+
const play3 = Array.from(players);
20+
const play4 = [...players];
21+
22+
console.log(players, play1, play2, play3, play4);
23+
24+
1725
// You might think we can just do something like this:
1826

1927
// however what happens when we update that array?
@@ -43,6 +51,13 @@
4351
};
4452

4553
// and think we make a copy:
54+
console.clear();
55+
const per = Object.assign({}, person);
56+
const per1 = {...person};
57+
const per2 = JSON.parse(JSON.stringify(person));
58+
59+
console.log(per, per1, per2, person);
60+
4661

4762
// how do we take a copy instead?
4863

15 - LocalStorage/index-START.html

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,43 @@ <h2>LOCAL TAPAS</h2>
2828
<script>
2929
const addItems = document.querySelector('.add-items');
3030
const itemsList = document.querySelector('.plates');
31-
const items = [];
31+
const items = JSON.parse(localStorage.getItem('items')) || [];
32+
33+
function addToList(e) {
34+
e.preventDefault();
35+
const text = (this.querySelector('[name=item]')).value;
36+
const item = {text, chosen: false};
37+
items.push(item);
38+
// console.log(items);
39+
reRenderList(items, itemsList);
40+
localStorage.setItem('items', JSON.stringify(items));
41+
this.reset();
42+
}
43+
44+
function reRenderList(itemList = [], listOfItems) {
45+
listOfItems.innerHTML = itemList.map((item, i) => {
46+
return `
47+
<li>
48+
<input type="checkbox" data-index=${i} id="item${i}" ${item.chosen ? 'checked' : ''} />
49+
<label for="item${i}">${item.text}</label>
50+
</li>
51+
`;
52+
}).join('');
53+
}
54+
55+
function doCheck(e) {
56+
if (!e.target.matches('input')) return;
57+
const index = e.target.dataset.index;
58+
items[index].chosen = !items[index].chosen;
59+
localStorage.setItem('items', JSON.stringify(items));
60+
reRenderList(items, itemsList);
61+
console.log(index);
62+
63+
}
64+
65+
addItems.addEventListener('submit', addToList);
66+
itemsList.addEventListener('click', doCheck);
67+
reRenderList(items, itemsList);
3268

3369
</script>
3470

Lines changed: 1 addition & 0 deletions
Loading

15 - LocalStorage/style.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
justify-content: center;
99
align-items: center;
1010
text-align: center;
11+
/* font-family: Segoe UI Symbol, Symbola; */
1112
font-family: Futura,"Trebuchet MS",Arial,sans-serif;
1213
}
1314

@@ -61,12 +62,13 @@
6162
}
6263

6364
.plates input + label:before {
64-
content: '⬜️';
65+
/* background-image: url('./square-regular.svg'); */
66+
content: '⦵';
6567
margin-right: 10px;
6668
}
6769

6870
.plates input:checked + label:before {
69-
content: '🌮';
71+
content: '🍥';
7072
}
7173

7274
.add-items {

0 commit comments

Comments
 (0)