From bbe2d3fbbb35548979e24c6eef126a67aba6d4f0 Mon Sep 17 00:00:00 2001 From: "Boyle, Karl" Date: Thu, 15 Jun 2017 15:26:35 +0100 Subject: [PATCH 01/13] Day 1 - JS Drum Kit Solution --- .vscode/settings.json | 4 ++++ 01 - JavaScript Drum Kit/index-START.html | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..9b93e4217e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +// Place your settings in this file to overwrite the default settings +{ + "http.proxyStrictSSL": false +} \ No newline at end of file diff --git a/01 - JavaScript Drum Kit/index-START.html b/01 - JavaScript Drum Kit/index-START.html index 4070d32767..82e44a751c 100644 --- a/01 - JavaScript Drum Kit/index-START.html +++ b/01 - JavaScript Drum Kit/index-START.html @@ -58,9 +58,26 @@ + if (!audio) return; + audio.currentTime = 0; + audio.play(); + key.classList.add('playing'); + } + + function removeTransition(e) { + if (e.propertyName !== 'transform') return; + this.classList.remove('playing') + } + const keys = document.querySelectorAll('.key'); + keys.forEach(key => key.addEventListener('transitionend', removeTransition)); + + window.addEventListener('keydown', playSound); + From f20f33aa7426cc32a678be4510c6f872fd467a7c Mon Sep 17 00:00:00 2001 From: Karl Boyle Date: Thu, 15 Jun 2017 15:34:20 +0100 Subject: [PATCH 02/13] Day 1 - JS Drum Kit Solution --- .vscode/settings.json | 4 ++++ 01 - JavaScript Drum Kit/index-START.html | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..9b93e4217e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +// Place your settings in this file to overwrite the default settings +{ + "http.proxyStrictSSL": false +} \ No newline at end of file diff --git a/01 - JavaScript Drum Kit/index-START.html b/01 - JavaScript Drum Kit/index-START.html index 4070d32767..82e44a751c 100644 --- a/01 - JavaScript Drum Kit/index-START.html +++ b/01 - JavaScript Drum Kit/index-START.html @@ -58,9 +58,26 @@ + if (!audio) return; + audio.currentTime = 0; + audio.play(); + key.classList.add('playing'); + } + + function removeTransition(e) { + if (e.propertyName !== 'transform') return; + this.classList.remove('playing') + } + const keys = document.querySelectorAll('.key'); + keys.forEach(key => key.addEventListener('transitionend', removeTransition)); + + window.addEventListener('keydown', playSound); + From 40b74719511d2486b405058d46f9ccdb00167d97 Mon Sep 17 00:00:00 2001 From: Karl Boyle Date: Thu, 15 Jun 2017 15:37:33 +0100 Subject: [PATCH 03/13] Test --- 01 - JavaScript Drum Kit/index-START.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/01 - JavaScript Drum Kit/index-START.html b/01 - JavaScript Drum Kit/index-START.html index 82e44a751c..819c21560b 100644 --- a/01 - JavaScript Drum Kit/index-START.html +++ b/01 - JavaScript Drum Kit/index-START.html @@ -71,12 +71,13 @@ function removeTransition(e) { if (e.propertyName !== 'transform') return; this.classList.remove('playing') + } const keys = document.querySelectorAll('.key'); keys.forEach(key => key.addEventListener('transitionend', removeTransition)); - window.addEventListener('keydown', playSound); + window.addEventListener('keydown', playSound); From dea2d51c8537505dcc1ec9a2a54358cab7a700d0 Mon Sep 17 00:00:00 2001 From: Karl Boyle Date: Thu, 15 Jun 2017 18:10:10 +0100 Subject: [PATCH 04/13] Day 2 - JS Clock --- 02 - JS and CSS Clock/index-START.html | 32 ++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/02 - JS and CSS Clock/index-START.html b/02 - JS and CSS Clock/index-START.html index ee7eaefb1f..0d1f02c9a8 100644 --- a/02 - JS and CSS Clock/index-START.html +++ b/02 - JS and CSS Clock/index-START.html @@ -62,13 +62,41 @@ background:black; position: absolute; top:50%; + transform-origin: 100%; + transform: rotate(90deg); + transition: all 0.05s; + transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1); } - + const hours = now.getHours(); + const hourDegrees = ((hours / 12) * 360) + 90; + hourHand.style.transform = `rotate(${hourDegrees}deg)`; + + + const minutes = now.getMinutes(); + const minutesDegrees = ((minutes / 60 ) * 360) + 90; + minHand.style.transform = `rotate(${minutesDegrees}deg)`; + + + const seconds = now.getSeconds(); + const secondsDegrees = ((seconds / 60) * 360) + 90; + secondHand.style.transform = `rotate(${secondsDegrees}deg)`; + + } + + setInterval(setDate, 1000); + + From a875b4b636b3bcd975475f15cc90fefa52b1cc07 Mon Sep 17 00:00:00 2001 From: Karl Boyle Date: Thu, 15 Jun 2017 23:14:27 +0100 Subject: [PATCH 05/13] Day 3 - CSS - JS Variables --- 03 - CSS Variables/index-START.html | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/03 - CSS Variables/index-START.html b/03 - CSS Variables/index-START.html index 8a4f0d556e..68d7f5f67c 100644 --- a/03 - CSS Variables/index-START.html +++ b/03 - CSS Variables/index-START.html @@ -21,6 +21,21 @@

Update CSS Variables with JS

From f939916086f86e71f61dd4e510468561e8956bdc Mon Sep 17 00:00:00 2001 From: Karl Boyle Date: Thu, 15 Jun 2017 23:14:59 +0100 Subject: [PATCH 06/13] Day 4 - Playing with Arrays. Sort map filter reduce --- 04 - Array Cardio Day 1/index-START.html | 51 ++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/04 - Array Cardio Day 1/index-START.html b/04 - Array Cardio Day 1/index-START.html index eec0ffc31d..69a3087c01 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -31,29 +31,80 @@ // Array.prototype.filter() // 1. Filter the list of inventors for those who were born in the 1500's + const fifteen = inventors.filter(inventor => inventor.year >= 1500 && inventor.year <=1600); + console.table(fifteen); // Array.prototype.map() // 2. Give us an array of the inventors' first and last names + const fullNames = inventors.map(inventor => `${inventor.first} ${inventor.last}`); + console.log(fullNames); // Array.prototype.sort() // 3. Sort the inventors by birthdate, oldest to youngest + // const ordered = inventors.sort(function(a, b) { + // if(a.year > b.year) { + // return 1; + // } + // else { + // return -1; + // } + // }); + const ordered = inventors.sort((a,b) => a.year > b.year ? 1 : -1); + console.table(ordered); // Array.prototype.reduce() // 4. How many years did all the inventors live? + const totalYears = inventors.reduce((total, inventor) => { + return total + (inventor.passed - inventor.year); + }, 0); + console.log(totalYears); // 5. Sort the inventors by years lived + const oldest = inventors.sort(function(a,b){ + const lastguy = a.passed - a.year; + const nextguy = b.passed - b.year; + return lastguy > nextguy ? -1 : 1; + }); + + console.table(oldest); // 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name // https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris + // const category = document.querySelector('.mw-category'); + // const links = Array.from(category.querySelectorAll('a')); + + // const de = links + // .map(link => link.textContent) + // .filter(streetName => streetName.includes('de')); + // 7. sort Exercise // Sort the people alphabetically by last name + const alpha = people.sort((lastOne, nextOne) => { + const [aLast, aFirst] = lastOne.split(', ') + const [bLast, bFirst] = nextOne.split(', ') + return aLast > bLast ? -1 : 1; + }); + + console.log(alpha) + // 8. Reduce Exercise // Sum up the instances of each of these const data = ['car', 'car', 'truck', 'truck', 'bike', 'walk', 'car', 'van', 'bike', 'walk', 'car', 'van', 'car', 'truck' ]; + const transportation = data.reduce(function(obj, item) { + if(!obj[item]) { + obj[item] = 0; + } + obj[item]++; + // console.log(item); + return obj; + },{ }) + + console.log(transportation); + From d16bbaa541efa01ecd3560e3e86f69d8841c6bb2 Mon Sep 17 00:00:00 2001 From: Karl Boyle Date: Sat, 24 Jun 2017 17:29:06 +0100 Subject: [PATCH 07/13] Day 5 + Day 6 - Using Flex and Fetch --- 05 - Flex Panel Gallery/index-START.html | 34 ++++++++++++++++++++ 06 - Type Ahead/index-START.html | 41 ++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/05 - Flex Panel Gallery/index-START.html b/05 - Flex Panel Gallery/index-START.html index 31c9167e16..58132e909f 100644 --- a/05 - Flex Panel Gallery/index-START.html +++ b/05 - Flex Panel Gallery/index-START.html @@ -24,6 +24,7 @@ .panels { min-height:100vh; overflow: hidden; + display: flex; } .panel { @@ -41,6 +42,11 @@ font-size: 20px; background-size:cover; background-position:center; + flex: 1; + justify-content: center; + align-items: center; + display: flex; + flex-direction: column; } @@ -54,8 +60,18 @@ margin:0; width: 100%; transition:transform 0.5s; + + flex: 1 0 auto; + display: flex; + justify-content: center; + align-items: center; } + .panel > *:first-child { transform: translateY(-100%);} + .panel.open-active > *:first-child { transform: translateY(0);} + .panel > *:last-child { transform: translateY(100%);} + .panel.open-active > *:last-child { transform: translateY(0);} + .panel p { text-transform: uppercase; font-family: 'Amatic SC', cursive; @@ -68,6 +84,7 @@ .panel.open { font-size:40px; + flex: 5; } @@ -103,6 +120,23 @@ diff --git a/06 - Type Ahead/index-START.html b/06 - Type Ahead/index-START.html index 1436886918..b7c487f831 100644 --- a/06 - Type Ahead/index-START.html +++ b/06 - Type Ahead/index-START.html @@ -17,6 +17,47 @@ From 331488543cfb423e0d46d6761ed64fba58e2795c Mon Sep 17 00:00:00 2001 From: Karl Boyle Date: Sat, 24 Jun 2017 20:08:48 +0100 Subject: [PATCH 08/13] Day 7 + 8 Playing with ES6 Arrays and HTML5 Canvas. --- 07 - Array Cardio Day 2/index-START.html | 17 ++++- 08 - Fun with HTML5 Canvas/index-START.html | 71 ++++++++++++++++++--- 2 files changed, 78 insertions(+), 10 deletions(-) diff --git a/07 - Array Cardio Day 2/index-START.html b/07 - Array Cardio Day 2/index-START.html index 969566ff78..43b0a2533b 100644 --- a/07 - Array Cardio Day 2/index-START.html +++ b/07 - Array Cardio Day 2/index-START.html @@ -25,16 +25,31 @@ ]; // Some and Every Checks - // Array.prototype.some() // is at least one person 19 or older? + // Array.prototype.some() // is at least one person 19 or older? + const isAdult = people.some(person => ((new Date()).getFullYear()) - person.year >= 19); + console.log({isAdult}); + // Array.prototype.every() // is everyone 19 or older? + const allAdult = people.every(person => ((new Date()).getFullYear()) - person.year >= 19); + console.log({allAdult}); // Array.prototype.find() // Find is like filter, but instead returns just the one you are looking for // find the comment with the ID of 823423 + const comment = comments.find(comment => comment.id === 823423); + console.log({comment}); // Array.prototype.findIndex() // Find the comment with this ID // delete the comment with the ID of 823423 + const index = comments.findIndex(comment => comment.id === 823423); + + //comments.splice(index,1); + + const newComments = [ + ...comments.slice(0, index), + ...comments.slice(index + 1) + ]; diff --git a/08 - Fun with HTML5 Canvas/index-START.html b/08 - Fun with HTML5 Canvas/index-START.html index 37c148df07..9cc0006ccf 100644 --- a/08 - Fun with HTML5 Canvas/index-START.html +++ b/08 - Fun with HTML5 Canvas/index-START.html @@ -1,19 +1,72 @@ + HTML5 Canvas + - - + + + + - + + \ No newline at end of file From 8042fd8b71043b2b24ecabb669304958e6738a5a Mon Sep 17 00:00:00 2001 From: Karl Boyle Date: Sat, 24 Jun 2017 21:31:04 +0100 Subject: [PATCH 09/13] Day 9 Various different console tips --- 09 - Dev Tools Domination/index-START.html | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/09 - Dev Tools Domination/index-START.html b/09 - Dev Tools Domination/index-START.html index 196fffd719..c9cc2567b3 100644 --- a/09 - Dev Tools Domination/index-START.html +++ b/09 - Dev Tools Domination/index-START.html @@ -18,28 +18,62 @@ } // Regular + console.log('hello'); // Interpolated + console.log('Hello I am a %s String!', '💩'); // Styled + console.log('%cI am some great text', 'font-size:10px'); // warning! + console.warn('OH NO'); // Error :| + console.error('Shit!!'); // Info + console.info('Crocodiles eat 3-4 people per year!'); // Testing + const p =document.querySelector('p'); + + console.assert(p.classList.contains('ouch'), 'This is wrong!'); // clearing + // console.clear(); // Viewing DOM Elements + console.log(p); + console.dir(p); // Grouping together + dogs.forEach(dog => { + console.groupCollapsed(`${dog.name}`); + console.log(`This is ${dog.name}`); + console.log(`This is ${dog.name} is ${dog.age} years old`); + console.log(`This is ${dog.name} is ${dog.age * 7 } dog years`); + console.groupEnd(`${dog.name}`); + }) // counting + console.count('Karl'); + console.count('Karl'); + console.count('Wes'); + console.count('Karl'); + console.count('Karl'); // timing + console.time('fetching data'); + fetch('https://api.github.com/users/karlboyle') + .then(data => data.json()) + .then(data => { + console.timeEnd('fetching data'); + console.log(data); + }) + + // table + console.table(dogs); From 06d56e58cd5f7fd40f550e44dc1216cca6d84023 Mon Sep 17 00:00:00 2001 From: Karl Boyle Date: Mon, 26 Jun 2017 19:31:29 +0100 Subject: [PATCH 10/13] Day 10 - Playing around with Selecting Multiple checkboxes. --- .../index-START.html | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/10 - Hold Shift and Check Checkboxes/index-START.html b/10 - Hold Shift and Check Checkboxes/index-START.html index aeac48e7f9..f8b2408f31 100644 --- a/10 - Hold Shift and Check Checkboxes/index-START.html +++ b/10 - Hold Shift and Check Checkboxes/index-START.html @@ -99,6 +99,34 @@ From 06e5cee0b2ad247ab3bdb8532566c4d985eae9f4 Mon Sep 17 00:00:00 2001 From: Karl Boyle Date: Mon, 26 Jun 2017 19:31:59 +0100 Subject: [PATCH 11/13] Day 11 - Creating my own video player controls from scratch. --- 11 - Custom Video Player/index.html | 1 + 11 - Custom Video Player/scripts.js | 63 +++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/11 - Custom Video Player/index.html b/11 - Custom Video Player/index.html index 281a15eaa8..5fb677524f 100644 --- a/11 - Custom Video Player/index.html +++ b/11 - Custom Video Player/index.html @@ -19,6 +19,7 @@ + diff --git a/11 - Custom Video Player/scripts.js b/11 - Custom Video Player/scripts.js index e69de29bb2..078957504f 100644 --- a/11 - Custom Video Player/scripts.js +++ b/11 - Custom Video Player/scripts.js @@ -0,0 +1,63 @@ +/* Get Elements */ +const player = document.querySelector('.player'); +const video = player.querySelector('.viewer'); + +const progress = player.querySelector('.progress'); +const progressBar = player.querySelector('.progress__filled'); +const toggle = player.querySelector('.toggle'); +const skipButtons = player.querySelectorAll('[data-skip]'); +const ranges = player.querySelectorAll('.player__slider'); +const fullscreen = player.querySelector('.fullscreen'); + +/* Build Functions */ +function togglePlay() { + const method = video.paused ? 'play' : 'pause'; + video[method](); +} + +function updateButton() { + toggle.textContent= this.paused ? '►' : '❚ ❚'; +} + +function skip() { + video.currentTime += parseFloat(this.dataset.skip); +} + +function handleRangeUpdate(){ + video[this.name] = this.value; +} + +function handleProgress() { + const percent = (video.currentTime / video.duration ) * 100; + progressBar.style.flexBasis = `${percent}%`; +} + +function scrub(e){ + const scrubTime = ( e.offsetX / progress.offsetWidth) * video.duration; + video.currentTime = scrubTime; +} + +function toggleFullScreen() { + video.webkitRequestFullscreen(); +} + +/* Event Listeners */ +video.addEventListener('click', togglePlay); +video.addEventListener('play', updateButton); +video.addEventListener('pause', updateButton); +video.addEventListener('timeupdate', handleProgress); + +toggle.addEventListener('click', togglePlay); + +skipButtons.forEach(button => button.addEventListener('click', skip)); + +ranges.forEach(range => range.addEventListener('change', handleRangeUpdate)); +ranges.forEach(range => range.addEventListener('mousemove', handleRangeUpdate)); + +let mousedown = false; +progress.addEventListener('click', scrub); +progress.addEventListener('mousemove', (e) => mousedown && scrub(e)); +progress.addEventListener('mousedown', () => mousedown = true); +progress.addEventListener('mouseup', () => mousedown = false); + +fullscreen.addEventListener('click', toggleFullScreen); \ No newline at end of file From fe3a20ccfd781577ec8c3f9a726132aeab8b2d15 Mon Sep 17 00:00:00 2001 From: Karl Boyle Date: Mon, 26 Jun 2017 20:05:12 +0100 Subject: [PATCH 12/13] Day 12 - Key Detection + Easter egg CornifyJS --- 12 - Key Sequence Detection/index-START.html | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/12 - Key Sequence Detection/index-START.html b/12 - Key Sequence Detection/index-START.html index 8cab786140..219e5dd33d 100644 --- a/12 - Key Sequence Detection/index-START.html +++ b/12 - Key Sequence Detection/index-START.html @@ -7,6 +7,18 @@ - + \ No newline at end of file From 1e209cb2c031ff224f4e3082a2ea4b4b137ac7e5 Mon Sep 17 00:00:00 2001 From: Karl Boyle Date: Tue, 27 Jun 2017 12:56:38 +0100 Subject: [PATCH 13/13] Day 13 + 14. Playing with Scrolling Images and MouseOffset. Cloning Objects and understanding js references --- 13 - Slide in on Scroll/index-START.html | 21 +++++++++ .../index-START.html | 46 +++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/13 - Slide in on Scroll/index-START.html b/13 - Slide in on Scroll/index-START.html index 0b9fb8fccb..0b9c446c59 100644 --- a/13 - Slide in on Scroll/index-START.html +++ b/13 - Slide in on Scroll/index-START.html @@ -58,6 +58,27 @@

Slide in on Scroll

}; } + const sliderImages = document.querySelectorAll('.slide-in'); + + function checkSlide() { + sliderImages.forEach(sliderImage => { + // half way through the image + const slideInAt = (window.scrollY + window.innerHeight) - sliderImage.height / 2; + // bottom of the image + const imageBottom = sliderImage.offsetTop + sliderImage.height; + const isHalfShown = slideInAt > sliderImage.offsetTop; + const isNotScrolledPast = window.scrollY < imageBottom; + if (isHalfShown && isNotScrolledPast) { + sliderImage.classList.add('active'); + } else { + sliderImage.classList.remove('active'); + } + }); + } + + window.addEventListener('scroll', debounce(checkSlide)); + +