diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000000..00aaa3aee0 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,79 @@ +module.exports = { + root: true, + + extends: 'eslint:recommended', + + parserOptions: { + ecmaVersion: 6, + sourceType: 'script' + }, + + env: { + browser: true, + es6: true + }, + + globals: { + Ext: false, + Sillage: true, + Genois: true, + Cahier: true, + idCtx: true, + digDesinhibePage: true, + digInhibePage: true + }, + + rules: { + //Possible errors + 'comma-dangle': 'warn', + 'no-console': 'off', + 'no-debugger': 'warn', + 'no-extra-semi': 'warn', + 'no-extra-parens': ['warn', 'functions'], + + //Best practices + 'eqeqeq': 'warn', + 'no-new': 'warn', + 'no-eval': 'warn', + 'curly': 'warn', + 'no-alert': 'warn', + 'no-unused-expressions': 'warn', + 'no-else-return': 'warn', + 'no-warning-comments': 'warn', + //Best practices: complexity + 'complexity': ['warn', 10], + 'max-depth': ['warn', 3], + 'max-params': ['warn', 7], + 'default-case': ['warn'], + + //variables + 'no-undef': 'warn', + 'no-unused-vars': ['warn', { + 'vars': 'all', + 'args': 'after-used' + }], + 'no-use-before-define': ['warn', { + 'functions': false, + 'classes': false + }], + + //Stylistic issues + 'no-array-constructor': 'warn', + 'no-mixed-spaces-and-tabs': 'warn', + 'new-cap': ['warn', { + 'newIsCap': true, + 'capIsNew': true + }], + 'semi': 'warn', + 'quotes': ['warn', 'single', {'avoidEscape': true, 'allowTemplateLiterals': true}], + //'quote-props': ['warn', 'as-needed'], + 'indent': ['off', 2], //off : problem with arrays indentation + 'no-trailing-spaces': 'warn', + //'space-before-function-paren': ['warn', 'never'], + 'space-in-parens': ['warn', 'never'], + 'yoda': ['warn', 'never'], + + //ES6 + 'arrow-body-style': ['error', 'as-needed'] + } +} diff --git a/.gitignore b/.gitignore index 6e1a3738b8..620be2d256 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules/ *.log haters/ +.vscode diff --git a/.tern-project b/.tern-project new file mode 100644 index 0000000000..22bd8f4635 --- /dev/null +++ b/.tern-project @@ -0,0 +1,7 @@ +{ + "ecmaVersion": 6, + "libs": [ + "browser" + ], + "plugins": {} +} \ No newline at end of file diff --git a/01 - JavaScript Drum Kit/index-old.html b/01 - JavaScript Drum Kit/index-old.html new file mode 100644 index 0000000000..a18f2bc2ca --- /dev/null +++ b/01 - JavaScript Drum Kit/index-old.html @@ -0,0 +1,83 @@ + + + + + JS Drum Kit + + + + + +
+
+ A + clap +
+
+ S + hihat +
+
+ D + kick +
+
+ F + openhat +
+
+ G + boom +
+
+ H + ride +
+
+ J + snare +
+
+ K + tom +
+
+ L + tink +
+
+ + + + + + + + + + + + + + + diff --git a/01 - JavaScript Drum Kit/index.html b/01 - JavaScript Drum Kit/index.html index a18f2bc2ca..c4ce2b1bee 100644 --- a/01 - JavaScript Drum Kit/index.html +++ b/01 - JavaScript Drum Kit/index.html @@ -57,27 +57,7 @@ - + diff --git a/01 - JavaScript Drum Kit/script.js b/01 - JavaScript Drum Kit/script.js new file mode 100644 index 0000000000..11d728183d --- /dev/null +++ b/01 - JavaScript Drum Kit/script.js @@ -0,0 +1,34 @@ +'use strict'; + +function playsound(keycode) { + const audio = document.querySelector(`audio[data-key="${keycode}"]`); + if (!audio) { + return; + } + audio.currentTime = 0; //rewind + audio.play(); +} + +function animate(keycode) { + const key = document.querySelector(`.key[data-key="${keycode}"]`); + if (!key) { + return; + } + key.classList.add('playing'); +} + +function removeTransition(e) { + if (e.propertyName === 'transform') { + // note : this = e.target dans le contexte d'une fonction appel�e pour un evenement + this.classList.remove('playing'); + } +} + +window.addEventListener('keydown', function (e) { + const keycode = e.keyCode; + console.log('keycode: ', keycode); + playsound(keycode); + animate(keycode); + const keys = document.querySelectorAll('.key'); + keys.forEach(key => key.addEventListener('transitionend', removeTransition)); +}); diff --git a/01 - JavaScript Drum Kit/style.css b/01 - JavaScript Drum Kit/style.css index 3e0a320b37..f606e94ed1 100644 --- a/01 - JavaScript Drum Kit/style.css +++ b/01 - JavaScript Drum Kit/style.css @@ -23,7 +23,7 @@ body,html { margin:1rem; font-size: 1.5rem; padding:1rem .5rem; - transition:all .07s; + transition:all .09s; width:100px; text-align: center; color:white; diff --git a/02 - JS + CSS Clock/index-old.html b/02 - JS + CSS Clock/index-old.html new file mode 100644 index 0000000000..36c420f534 --- /dev/null +++ b/02 - JS + CSS Clock/index-old.html @@ -0,0 +1,96 @@ + + + + + Document + + + + +
+
+
+
+
+
+
+ + + + + + + diff --git a/02 - JS + CSS Clock/index.html b/02 - JS + CSS Clock/index.html index 36c420f534..9c18887319 100644 --- a/02 - JS + CSS Clock/index.html +++ b/02 - JS + CSS Clock/index.html @@ -67,30 +67,7 @@ transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1); } + - diff --git a/02 - JS + CSS Clock/script.js b/02 - JS + CSS Clock/script.js new file mode 100644 index 0000000000..2973181da8 --- /dev/null +++ b/02 - JS + CSS Clock/script.js @@ -0,0 +1,21 @@ +'use strict'; + +const secondHand = document.querySelector('.second-hand'); +const minuteHand = document.querySelector('.min-hand'); +const hourHand = document.querySelector('.hour-hand'); + +function setTime() { + const now = new Date(); + console.log(now); + const seconds = now.getSeconds(); + const minutes = now.getMinutes(); + const hours = now.getHours(); + const secondsDegrees = seconds * 6 + 90; // seconds / 60 * 360 => 360/60=6 + const minutesDegrees = minutes * 6 + 90; + const hoursDegrees = hours *15 + 90; //360/24=15 + secondHand.style.transform = `rotate(${secondsDegrees}deg)`; + minuteHand.style.transform = `rotate(${minutesDegrees}deg)`; + hourHand.style.transform = `rotate(${hoursDegrees}deg)`; +} + +setInterval(setTime, 1000); diff --git a/03 - CSS Variables/index.html b/03 - CSS Variables/index.html new file mode 100644 index 0000000000..d90e825831 --- /dev/null +++ b/03 - CSS Variables/index.html @@ -0,0 +1,75 @@ + + + + + + Scoped CSS Variables and JS + + + +

Update CSS Variables with JS

+ +
+ + + + + + + + +
+ + + + + + + + + diff --git a/03 - CSS Variables/photo-1465188162913-8fb5709d6d57.jpg b/03 - CSS Variables/photo-1465188162913-8fb5709d6d57.jpg new file mode 100644 index 0000000000..0eb31940cb Binary files /dev/null and b/03 - CSS Variables/photo-1465188162913-8fb5709d6d57.jpg differ diff --git a/03 - CSS Variables/script.js b/03 - CSS Variables/script.js new file mode 100644 index 0000000000..9e64557c59 --- /dev/null +++ b/03 - CSS Variables/script.js @@ -0,0 +1,18 @@ +'use strict'; + +const inputs = document.querySelectorAll('.controls input'); + +function handleEvent() { + // this = input sur lequel l'�v�nement a �t� d�clench�. + //using dataset to retreive personnal html attribute + const sizing = this.dataset.sizing || ''; + // magic line + /* The Document.documentElement read-only property returns the Element that is the root element of the document + (for example, the element for HTML documents).*/ + /* The HTMLElement.style property returns a CSSStyleDeclaration object that represents only the element's inline style attribute, + ignoring any applied style rules */ + document.documentElement.style.setProperty(`--${this.name}`, this.value + sizing); +} + +inputs.forEach(input => input.addEventListener('change', handleEvent)); +inputs.forEach(input => input.addEventListener('mousemove', handleEvent)); diff --git a/04 - Array Cardio Day 1/index-START.html b/04 - Array Cardio Day 1/index-START.html index 089352c8a6..931adfbe31 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -5,51 +5,6 @@ Array Cardio 💪 - + diff --git a/04 - Array Cardio Day 1/script.js b/04 - Array Cardio Day 1/script.js new file mode 100644 index 0000000000..d49a76243d --- /dev/null +++ b/04 - Array Cardio Day 1/script.js @@ -0,0 +1,79 @@ +'use strict'; +// Get your shorts on - this is an array workout! +// ## Array Cardio Day 1 + +// Some data we can work with + +const inventors = [ + { first: 'Albert', last: 'Einstein', year: 1879, passed: 1955 }, + { first: 'Isaac', last: 'Newton', year: 1643, passed: 1727 }, + { first: 'Galileo', last: 'Galilei', year: 1564, passed: 1642 }, + { first: 'Marie', last: 'Curie', year: 1867, passed: 1934 }, + { first: 'Johannes', last: 'Kepler', year: 1571, passed: 1630 }, + { first: 'Nicolaus', last: 'Copernicus', year: 1473, passed: 1543 }, + { first: 'Max', last: 'Planck', year: 1858, passed: 1947 } +]; + +const flavours = ['Chocolate Chip', 'Kulfi', 'Caramel Praline', 'Chocolate', 'Burnt Caramel', 'Pistachio', 'Rose', 'Sweet Coconut', 'Lemon Cookie', 'Toffeeness', 'Toasted Almond', 'Black Raspberry Crunch', 'Chocolate Brownies', 'Pistachio Almond', 'Strawberry', 'Lavender Honey', 'Lychee', 'Peach', 'Black Walnut', 'Birthday Cake', 'Mexican Chocolate', 'Mocha Almond Fudge', 'Raspberry']; + +const people = ['Beck, Glenn', 'Becker, Carl', 'Beckett, Samuel', 'Beddoes, Mick', 'Beecher, Henry', 'Beethoven, Ludwig', 'Begin, Menachem', 'Belloc, Hilaire', 'Bellow, Saul', 'Benchley, Robert', 'Benenson, Peter', 'Ben-Gurion, David', 'Benjamin, Walter', 'Benn, Tony', 'Bennington, Chester', 'Benson, Leana', 'Bent, Silas', 'Bentsen, Lloyd', 'Berger, Ric', 'Bergman, Ingmar', 'Berio, Luciano', 'Berle, Milton', 'Berlin, Irving', 'Berne, Eric', 'Bernhard, Sandra', 'Berra, Yogi', 'Berry, Halle', 'Berry, Wendell', 'Bethea, Erin', 'Bevan, Aneurin', 'Bevel, Ken', 'Biden, Joseph', 'Bierce, Ambrose', 'Biko, Steve', 'Billings, Josh', 'Biondo, Frank', 'Birrell, Augustine', 'Black Elk', 'Blair, Robert', 'Blair, Tony', 'Blake, William']; + +// Array.prototype.filter() +// 1. Filter the list of inventors for those who were born in the 1500's +const oldInventors = inventors.filter(inventor => inventor.year >= 1500 && inventor.year < 1600); +console.log(oldInventors); + +// Array.prototype.map() +// 2. Give us an array of the inventory first and last names +const inventorsNames = inventors.map(inventor => inventor.first + ' ' + inventor.last); +console.log(inventorsNames); + +// Array.prototype.sort() +// 3. Sort the inventors by birthdate, oldest to youngest +const sortedInventors = inventors.sort((a, b) => a.year < b.year ? -1 : 1); +console.log(sortedInventors); + +// Array.prototype.reduce() +// 4. How many years did all the inventors live? +const years = inventors.map(inventor => inventor.passed - inventor.year) + .reduce((prev, current) => prev + current, 0); +console.log(years); + + + +// 5. Sort the inventors by years lived +function inventorWithLifeSpan(inventor) { + inventor.lifeSpan = inventor.passed - inventor.year; + return inventor; +} +const sortedInventors2 = inventors.map(inventor => inventorWithLifeSpan(inventor)) + .sort((a,b) => a.lifeSpan > b.lifeSpan ? 1 : -1); +console.log('sorted 2: ', sortedInventors2); + +console.log(inventors.sort((a, b) => a.passed - a.year > b.passed - b.year ? 1 : -1)); + +// 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name +// https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris +/*Array.from(document.querySelectorAll('.mw-category li')) + .map(li => li.innerText) + // .filter(s => s.indexOf('de') !== -1); + .filter(s => s.includes('de'));*/ + + +// 7. sort Exercise +// Sort the people alphabetically by last name +console.log('sort ', people.sort()); + +// 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 sumup = data.reduce((obj, item) => { + if (!obj[item]) { + obj[item] = 1; + }else{ + obj[item] += 1; + } + return obj; +}, {}); +console.log('sumup: ', sumup); diff --git a/05 - Flex Panel Gallery/01.jpg b/05 - Flex Panel Gallery/01.jpg new file mode 100644 index 0000000000..85449feab0 Binary files /dev/null and b/05 - Flex Panel Gallery/01.jpg differ diff --git a/05 - Flex Panel Gallery/02.jpg b/05 - Flex Panel Gallery/02.jpg new file mode 100644 index 0000000000..17690ff19d Binary files /dev/null and b/05 - Flex Panel Gallery/02.jpg differ diff --git a/05 - Flex Panel Gallery/03.jpg b/05 - Flex Panel Gallery/03.jpg new file mode 100644 index 0000000000..fe35568b43 Binary files /dev/null and b/05 - Flex Panel Gallery/03.jpg differ diff --git a/05 - Flex Panel Gallery/04.jpg b/05 - Flex Panel Gallery/04.jpg new file mode 100644 index 0000000000..4f0929b060 Binary files /dev/null and b/05 - Flex Panel Gallery/04.jpg differ diff --git a/05 - Flex Panel Gallery/05.jpg b/05 - Flex Panel Gallery/05.jpg new file mode 100644 index 0000000000..b1208529bd Binary files /dev/null and b/05 - Flex Panel Gallery/05.jpg differ diff --git a/05 - Flex Panel Gallery/index.html b/05 - Flex Panel Gallery/index.html new file mode 100644 index 0000000000..353e39c9e6 --- /dev/null +++ b/05 - Flex Panel Gallery/index.html @@ -0,0 +1,135 @@ + + + + + Flex Panels 💪 + + + + + + +
+
+

Hey

+

Let's

+

Dance

+
+
+

Give

+

Take

+

Receive

+
+
+

Experience

+

It

+

Today

+
+
+

Give

+

All

+

You can

+
+
+

Life

+

In

+

Motion

+
+
+ + + + + diff --git a/05 - Flex Panel Gallery/script.js b/05 - Flex Panel Gallery/script.js new file mode 100644 index 0000000000..0af2149936 --- /dev/null +++ b/05 - Flex Panel Gallery/script.js @@ -0,0 +1,17 @@ +'use strict'; + +const panels = document.querySelectorAll('.panel'); + +function togglePanel() { + this.classList.toggle('open'); +} + +function toggleActive(e) { + console.log(this.classList); + if (e.propertyName.includes('flex')) { + this.classList.toggle('open-active'); + } +} + +panels.forEach(panel => panel.addEventListener('click', togglePanel)); +panels.forEach(panel => panel.addEventListener('transitionend', toggleActive)); diff --git a/06 - Type Ahead/index.html b/06 - Type Ahead/index.html new file mode 100644 index 0000000000..a053a1c68b --- /dev/null +++ b/06 - Type Ahead/index.html @@ -0,0 +1,21 @@ + + + + + Type Ahead 👀 + + + + +
+ + +
+ + + + + diff --git a/06 - Type Ahead/script.js b/06 - Type Ahead/script.js new file mode 100644 index 0000000000..980531d3bc --- /dev/null +++ b/06 - Type Ahead/script.js @@ -0,0 +1,38 @@ +'use strict'; + +const endpoint = 'https://gist.githubusercontent.com/Miserlou/c5cd8364bf9b2420bb29/raw/2bf258763cdddd704f8ffd3ea9a3e81d25e2c6f6/cities.json'; + +let cities = []; + +fetch(endpoint) + .then(blob => blob.json()) + .then(data => cities = data); + +function findMatches(wordToMatch, cities) { + return cities.filter((place) => { + const regexp = new RegExp(wordToMatch, 'gi'); + return place.city.match(regexp) || place.state.match(regexp); + }); +} + +function numberWithCommas(x) { + return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); +} + +function displayMatcher(){ + const matches = findMatches(this.value, cities); + const regexp = new RegExp(this.value, 'gi'); + const html = matches.map(place => { + const cityName = place.city.replace(regexp, `${this.value}`); + const stateName = place.state.replace(regexp, `${this.value}`); + return ` +
  • + ${cityName}, ${stateName} + ${numberWithCommas(place.population)} +
  • + `; + }).join(''); + document.querySelector('.suggestions').innerHTML = html; +} + +document.querySelector('.search').addEventListener('keyup', displayMatcher); diff --git a/07 - Array Cardio Day 2/index.html b/07 - Array Cardio Day 2/index.html new file mode 100644 index 0000000000..bae9677d00 --- /dev/null +++ b/07 - Array Cardio Day 2/index.html @@ -0,0 +1,10 @@ + + + + + Document + + + + + diff --git a/07 - Array Cardio Day 2/script.js b/07 - Array Cardio Day 2/script.js new file mode 100644 index 0000000000..db1d8b0565 --- /dev/null +++ b/07 - Array Cardio Day 2/script.js @@ -0,0 +1,40 @@ +'use strict'; + +const people = [ + { name: 'Wes', year: 1988 }, + { name: 'Kait', year: 1986 }, + { name: 'Irv', year: 1970 }, + { name: 'Lux', year: 2015 } +]; + +const comments = [ + { text: 'Love this!', id: 523423 }, + { text: 'Super good', id: 823423 }, + { text: 'You are the best', id: 2039842 }, + { text: 'Ramen in my fav food ever', id: 123523 }, + { text: 'Nice Nice Nice!', id: 542328 } +]; + +const isAdult = people.some(adult => new Date().getFullYear() - adult.year >= 19); +console.log(isAdult); + +const allAdults = people.every(adult => new Date().getFullYear() - adult.year >= 19); +console.log(allAdults); + + +//Find the comment with the id of 823423 +const comment = comments.find(c => c.id === 823423); +console.log(comment.text); + +const index = comments.findIndex(c => c.id === 823423); + +// normal way +comments.splice(index, 1); +console.log(comments); + +//redux way ? +// const newArray = [ +// ...comments.slice(0, index), +// ...comments.slice(index + 1) +// ]; +// console.log(newArray); diff --git a/08 - Fun with HTML5 Canvas/index-START.html b/08 - Fun with HTML5 Canvas/index-START.html index 37c148df07..fb049cdccb 100644 --- a/08 - Fun with HTML5 Canvas/index-START.html +++ b/08 - Fun with HTML5 Canvas/index-START.html @@ -6,8 +6,7 @@ - + + + + diff --git a/08 - Fun with HTML5 Canvas/script.js b/08 - Fun with HTML5 Canvas/script.js new file mode 100644 index 0000000000..8bd3297f51 --- /dev/null +++ b/08 - Fun with HTML5 Canvas/script.js @@ -0,0 +1,70 @@ +'use strict'; + +const canvas = document.querySelector('#draw'); + +canvas.width = window.innerWidth; +canvas.height = window.innerHeight; + +const ctx = canvas.getContext('2d'); + +ctx.lineCap = 'round'; // fin de la ligne +ctx.lineJoin = 'round'; // comment se rejoignent les lignes + +ctx.globalCompositeOperation = 'xor'; // let's make it trippy + +// flag to know when we are actually drawing +let isDrawing = false; + +let lastX; +let lastY; + +let hue = 0; +let lineWidth = 5; +let lineGrowing = true; + +function draw(event) { + if (!isDrawing) { + return; + } + + // colore, le monde, sans feutres, sans �preuves ni bombes + ctx.strokeStyle = `hsl(${hue}, 100%, 50%)`; + hue++; + hue = hue%360; + // gestion de la taille du trait + ctx.lineWidth = lineWidth; + if (lineWidth > 150 || lineWidth < 5) { + // flip the direction ! + lineGrowing = !lineGrowing; + } + if (lineGrowing) { + lineWidth++; + } else { + lineWidth--; + } + + // let's draw ! + lastX = lastX || event.offsetX; + lastY = lastY || event.offsetY; + ctx.beginPath(); + ctx.moveTo(lastX, lastY); // moves the starting point of a line + ctx.lineTo(event.offsetX, event.offsetY); + ctx.stroke(); // does the actual drawing + + // lastX = event.offsetX; + // lastY = event.offsetY; + // same as above, with es6 destructuring + [lastX, lastY] = [event.offsetX, event.offsetY]; +} + +// function tooggleIsDrawing(event) { +// isDrawing = event.type === 'mousedown' ? true : false; +// } + +canvas.addEventListener('mousemove', draw); +canvas.addEventListener('mousedown', (event) => { + [lastX, lastY] = [event.offsetX, event.offsetY]; + isDrawing = true; +}); +canvas.addEventListener('mouseup', () => isDrawing = false); +canvas.addEventListener('mouseout', () => isDrawing = false); diff --git a/09 - Dev Tools Domination/index.html b/09 - Dev Tools Domination/index.html new file mode 100644 index 0000000000..e390708716 --- /dev/null +++ b/09 - Dev Tools Domination/index.html @@ -0,0 +1,14 @@ + + + + + Console Tricks! + + + +

    ×BREAK×DOWN×

    + + + + + diff --git a/09 - Dev Tools Domination/script.js b/09 - Dev Tools Domination/script.js new file mode 100644 index 0000000000..af9d2db3ee --- /dev/null +++ b/09 - Dev Tools Domination/script.js @@ -0,0 +1,47 @@ +'use strict'; + +const dogs = [{ name: 'Snickers', age: 2 }, { name: 'hugo', age: 8 }]; + +function makeGreen() { + const p = document.querySelector('p'); + p.style.color = '#BADA55'; + p.style.fontSize = '50px'; +} + +// Regular + +// Interpolated + +// Styled + +// warning! + +// Error :| + +// Info + +// Testing + +// clearing + +// Viewing DOM Elements + +// Grouping together +dogs.forEach(dog => { + // console.group(dog.name); + console.groupCollapsed(dog.name); + console.log('this is ', dog.name); + console.log(`${dog.name} is ${dog.age} years old`); + console.groupEnd(dog.name); +}); + +// counting + +// timing +console.time('test'); +fetch('https://api.github.com/users/fthebaud') + .then(data => data.json()) + .then(data => { + console.log(data); + console.timeEnd('test'); + }); diff --git a/10 - Hold Shift and Check Checkboxes/index.html b/10 - Hold Shift and Check Checkboxes/index.html new file mode 100644 index 0000000000..2006d22301 --- /dev/null +++ b/10 - Hold Shift and Check Checkboxes/index.html @@ -0,0 +1,108 @@ + + + + + Document + + + + +
    +
    + +

    This is an inbox layout.

    +
    +
    + +

    Check one item

    +
    +
    + +

    Hold down your Shift key

    +
    +
    + +

    Check a lower item

    +
    +
    + +

    Everything inbetween should also be set to checked

    +
    +
    + +

    Try do it with out any libraries

    +
    +
    + +

    Just regular JavaScript

    +
    +
    + +

    Good Luck!

    +
    +
    + +

    Don't forget to tweet your result!

    +
    +
    + + + + diff --git a/10 - Hold Shift and Check Checkboxes/script.js b/10 - Hold Shift and Check Checkboxes/script.js new file mode 100644 index 0000000000..6c561794e6 --- /dev/null +++ b/10 - Hold Shift and Check Checkboxes/script.js @@ -0,0 +1,41 @@ +'use strict'; + +// Useless, there is an event.shifKey ! +// let isShiftDown = false; + +// document.addEventListener('keydown', event => { +// console.log(event.code); +// isShiftDown = event.keyCode === 16; +// console.log('isShiftDown: ', isShiftDown); +// }); +// +// document.addEventListener('keyup', () => { +// isShiftDown = false; +// console.log('isShiftDown: ', isShiftDown); +// }); + +let lastCheckBox; + +const checkboxes = document.querySelectorAll('input[type="checkbox"]'); +checkboxes.forEach(checkbox => checkbox.addEventListener('click', checkboxChange)); // for a checkbox, click event will fire even if we use the keyboard + +function checkboxChange(event) { + // if (!isShiftDown) return; //eslint-disable-line curly + let inBetween = false; + if (event.shiftKey && this.checked && lastCheckBox) { + checkboxes.forEach(checkbox => { + if (inBetween) { + checkbox.checked = true; + } + if (checkbox === this || checkbox === lastCheckBox) { + inBetween = !inBetween; + } + }); + } + lastCheckBox = this; + if (this.checked) { + lastCheckBox = this; + } else { + lastCheckBox = null; + } +} diff --git a/11 - Custom Video Player/index.html b/11 - Custom Video Player/index.html index fe2b55b394..d8fb5e0ca6 100644 --- a/11 - Custom Video Player/index.html +++ b/11 - Custom Video Player/index.html @@ -15,10 +15,11 @@
    - + + diff --git a/11 - Custom Video Player/scripts.js b/11 - Custom Video Player/scripts.js index e69de29bb2..76f7fa5d95 100644 --- a/11 - Custom Video Player/scripts.js +++ b/11 - Custom Video Player/scripts.js @@ -0,0 +1,88 @@ +'use strict'; + +// grab the elements +const player = document.querySelector('.player'); +const video = player.querySelector('video'); +const progress = player.querySelector('.progress'); +const progressBar = player.querySelector('.progress__filled'); +const toggle = player.querySelector('.toggle'); +const ranges = player.querySelectorAll('[type="range"]'); +const skipButtons = player.querySelectorAll('[data-skip]'); + + +// functions +function togglePlay() { + if (video.paused) { + video.play(); + } else { + video.pause(); + } +} + +function togglePlayIfSpace(event) { + if (event.keyCode === 32) { + togglePlay(); + } +} + +function updateButton() { + const icon = this.paused ? '►' : '❚❚'; + toggle.textContent = icon; +} + +function skip() { + const time = Number.parseFloat(this.dataset.skip); + video.currentTime += time; +} + +function handleRangeUpdate() { + video[this.name] = this.value; +} + +function handleProgress() { + const percentage = video.currentTime / video.duration * 100; + progressBar.style.flexBasis = percentage + '%'; +} + +function scrub(event) { + const scrubTime = event.offsetX / progress.offsetWidth * video.duration; + video.currentTime = scrubTime; +} + +// hook up the event listeners +video.addEventListener('click', togglePlay); +toggle.addEventListener('click', togglePlay); +document.addEventListener('keydown', togglePlayIfSpace); + +video.addEventListener('play', updateButton); +video.addEventListener('pause', updateButton); +video.addEventListener('timeupdate', handleProgress); + +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', (event) => mouseDown && scrub(event)); +progress.addEventListener('mousedown', () => {mouseDown = true;}); +progress.addEventListener('mouseup', () => mouseDown = false); + + +const fullScreenButton = document.querySelector('button#fullscreen'); + +let fullscreen = false; +function toggleFullScreen() { + if (!fullscreen) { + console.log(window.innerWidth, window.innerHeight); + document.querySelector('body').style.margin = '0'; + document.querySelector('body').style.overflow = 'hidden'; + player.style.minWidth = `${window.innerWidth}px`; + player.style.maxHeight = `${window.innerHeight}px`; + } else { + player.style.minWidth = '750px'; + } + fullscreen = !fullscreen; +} + +fullScreenButton.addEventListener('click', toggleFullScreen); diff --git a/12 - Key Sequence Detection/index.html b/12 - Key Sequence Detection/index.html new file mode 100644 index 0000000000..62313eec90 --- /dev/null +++ b/12 - Key Sequence Detection/index.html @@ -0,0 +1,11 @@ + + + + + Key Detection + + + + + + diff --git a/12 - Key Sequence Detection/script.js b/12 - Key Sequence Detection/script.js new file mode 100644 index 0000000000..82a2e8f8e8 --- /dev/null +++ b/12 - Key Sequence Detection/script.js @@ -0,0 +1,16 @@ +'use strict'; + +const secretCode = ['b', 'e', 'f', 'a', 'ArrowUp']; +let pressed = []; + + +document.addEventListener('keyup', (event) => { + pressed.push(event.key); + if (pressed.length > secretCode.length) { + pressed.shift(); + } + let match = pressed.every((key, index) => key === secretCode[index]); + if(match){ + cornify_add(); //eslint-disable-line no-undef + } +}); diff --git a/13 - Slide in on Scroll/index.html b/13 - Slide in on Scroll/index.html new file mode 100644 index 0000000000..ea69b982ab --- /dev/null +++ b/13 - Slide in on Scroll/index.html @@ -0,0 +1,104 @@ + + + + + Document + + + +
    + +

    Slide in on Scroll

    + +

    Consectetur adipisicing elit. Tempore tempora rerum, est autem cupiditate, corporis a qui libero ipsum delectus quidem dolor at nulla, adipisci veniam in reiciendis aut asperiores omnis blanditiis quod quas laborum nam! Fuga ad tempora in aspernatur pariaturlores sunt esse magni, ut, dignissimos.

    +

    Lorem ipsum cupiditate, corporis a qui libero ipsum delectus quidem dolor at nulla, adipisci veniam in reiciendis aut asperiores omnis blanditiis quod quas laborum nam! Fuga ad tempora in aspernatur pariatur fugit quibusdam dolores sunt esse magni, ut, dignissimos.

    +

    Adipisicing elit. Tempore tempora rerum..

    +

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempore tempora rerum, est autem cupiditate, corporis a qui libero ipsum delectus quidem dolor at nulla, adipisci veniam in reiciendis aut asperiores omnis blanditiis quod quas laborum nam! Fuga ad tempora in aspernatur pariatur fugit quibusdam dolores sunt esse magni, ut, dignissimos.

    +

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempore tempora rerum, est autem cupiditate, corporis a qui libero ipsum delectus quidem dolor at nulla, adipisci veniam in reiciendis aut asperiores omnis blanditiis quod quas laborum nam! Fuga ad tempora in aspernatur pariatur fugit quibusdam dolores sunt esse magni, ut, dignissimos.

    +

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempore tempora rerum, est autem cupiditate, corporis a qui libero ipsum delectus quidem dolor at nulla, adipisci veniam in reiciendis aut asperiores omnis blanditiis quod quas laborum nam! Fuga ad tempora in aspernatur pariatur fugit quibusdam dolores sunt esse magni, ut, dignissimos.

    + + + +

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptates, deserunt facilis et iste corrupti omnis tenetur est. Iste ut est dicta dolor itaque adipisci, dolorum minima, veritatis earum provident error molestias. Ratione magni illo sint vel velit ut excepturi consectetur suscipit, earum modi accusamus voluptatem nostrum, praesentium numquam, reiciendis voluptas sit id quisquam. Consequatur in quis reprehenderit modi perspiciatis necessitatibus saepe, quidem, suscipit iure natus dignissimos ipsam, eligendi deleniti accusantium, rerum quibusdam fugit perferendis et optio recusandae sed ratione. Culpa, dolorum reprehenderit harum ab voluptas fuga, nisi eligendi natus maiores illum quas quos et aperiam aut doloremque optio maxime fugiat doloribus. Eum dolorum expedita quam, nesciunt

    + + + +

    at provident praesentium atque quas rerum optio dignissimos repudiandae ullam illum quibusdam. Vel ad error quibusdam, illo ex totam placeat. Quos excepturi fuga, molestiae ea quisquam minus, ratione dicta consectetur officia omnis, doloribus voluptatibus? Veniam ipsum veritatis architecto, provident quas consequatur doloremque quam quidem earum expedita, ad delectus voluptatum, omnis praesentium nostrum qui aspernatur ea eaque adipisci et cumque ab? Ea voluptatum dolore itaque odio. Eius minima distinctio harum, officia ab nihil exercitationem. Tempora rem nemo nam temporibus molestias facilis minus ipsam quam doloribus consequatur debitis nesciunt tempore officiis aperiam quisquam, molestiae voluptates cum, fuga culpa. Distinctio accusamus quibusdam, tempore perspiciatis dolorum optio facere consequatur quidem ullam beatae architecto, ipsam sequi officiis dignissimos amet impedit natus necessitatibus tenetur repellendus dolor rem! Dicta dolorem, iure, facilis illo ex nihil ipsa amet officia, optio temporibus eum autem odit repellendus nisi. Possimus modi, corrupti error debitis doloribus dicta libero earum, sequi porro ut excepturi nostrum ea voluptatem nihil culpa? Ullam expedita eligendi obcaecati reiciendis velit provident omnis quas qui in corrupti est dolore facere ad hic, animi soluta assumenda consequuntur reprehenderit! Voluptate dolor nihil veniam laborum voluptas nisi pariatur sed optio accusantium quam consectetur, corrupti, sequi et consequuntur, excepturi doloremque. Tempore quis velit corporis neque fugit non sequi eaque rem hic. Facere, inventore, aspernatur. Accusantium modi atque, asperiores qui nobis soluta cumque suscipit excepturi possimus doloremque odit saepe perferendis temporibus molestiae nostrum voluptatum quis id sint quidem nesciunt culpa. Rerum labore dolor beatae blanditiis praesentium explicabo velit optio esse aperiam similique, voluptatem cum, maiores ipsa tempore. Reiciendis sed culpa atque inventore, nam ullam enim expedita consectetur id velit iusto alias vitae explicabo nemo neque odio reprehenderit soluta sint eaque. Aperiam, qui ut tenetur, voluptate doloremque officiis dicta quaerat voluptatem rerum natus magni. Eum amet autem dolor ullam.

    + + + +

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Distinctio maiores adipisci quibusdam repudiandae dolor vero placeat esse sit! Quibusdam saepe aperiam explicabo placeat optio, consequuntur nihil voluptatibus expedita quia vero perferendis, deserunt et incidunt eveniet temporibus doloremque possimus facilis. Possimus labore, officia dolore! Eaque ratione saepe, alias harum laboriosam deserunt laudantium blanditiis eum explicabo placeat reiciendis labore iste sint. Consectetur expedita dignissimos, non quos distinctio, eos rerum facilis eligendi. Asperiores laudantium, rerum ratione consequatur, culpa consectetur possimus atque ab tempore illum non dolor nesciunt. Neque, rerum. A vel non incidunt, quod doloremque dignissimos necessitatibus aliquid laboriosam architecto at cupiditate commodi expedita in, quae blanditiis. Deserunt labore sequi, repellat laboriosam est, doloremque culpa reiciendis tempore excepturi. Enim nostrum fugit itaque vel corporis ullam sed tenetur ipsa qui rem quam error sint, libero. Laboriosam rem, ratione. Autem blanditiis

    + + +

    laborum neque repudiandae quam, cumque, voluptate veritatis itaque, placeat veniam ad nisi. Expedita, laborum reprehenderit ratione soluta velit natus, odit mollitia. Corporis rerum minima fugiat in nostrum. Assumenda natus cupiditate hic quidem ex, quas, amet ipsum esse dolore facilis beatae maxime qui inventore, iste? Maiores dignissimos dolore culpa debitis voluptatem harum, excepturi enim reiciendis, tempora ab ipsam illum aspernatur quasi qui porro saepe iure sunt eligendi tenetur quaerat ducimus quas sequi omnis aperiam suscipit! Molestiae obcaecati officiis quo, ratione eveniet, provident pariatur. Veniam quasi expedita distinctio, itaque molestiae sequi, dolorum nisi repellendus quia facilis iusto dignissimos nam? Tenetur fugit quos autem nihil, perspiciatis expedita enim tempore, alias ab maiores quis necessitatibus distinctio molestias eum, quidem. Delectus impedit quidem laborum, fugit vel neque quo, ipsam, quasi aspernatur quas odio nihil? Veniam amet reiciendis blanditiis quis reprehenderit repudiandae neque, ab ducimus, odit excepturi voluptate saepe ipsam. Voluptatem eum error voluptas porro officiis, amet! Molestias, fugit, ut! Tempore non magnam, amet, facere ducimus accusantium eos veritatis neque.

    + + + +

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Distinctio maiores adipisci quibusdam repudiandae dolor vero placeat esse sit! Quibusdam saepe aperiam explicabo placeat optio, consequuntur nihil voluptatibus expedita quia vero perferendis, deserunt et incidunt eveniet temporibus doloremque possimus facilis. Possimus labore, officia dolore! Eaque ratione saepe, alias harum laboriosam deserunt laudantium blanditiis eum explicabo placeat reiciendis labore iste sint. Consectetur expedita dignissimos, non quos distinctio, eos rerum facilis eligendi. Asperiores laudantium, rerum ratione consequatur, culpa consectetur possimus atque ab tempore illum non dolor nesciunt. Neque, rerum. A vel non incidunt, quod doloremque dignissimos necessitatibus aliquid laboriosam architecto at cupiditate commodi expedita in, quae blanditiis. Deserunt labore sequi, repellat laboriosam est, doloremque culpa reiciendis tempore excepturi. Enim nostrum fugit itaque vel corporis ullam sed tenetur ipsa qui rem quam error sint, libero. Laboriosam rem, ratione. Autem blanditiis laborum neque repudiandae quam, cumque, voluptate veritatis itaque, placeat veniam ad nisi. Expedita, laborum reprehenderit ratione soluta velit natus, odit mollitia. Corporis rerum minima fugiat in nostrum. Assumenda natus cupiditate hic quidem ex, quas, amet ipsum esse dolore facilis beatae maxime qui inventore, iste? Maiores dignissimos dolore culpa debitis voluptatem harum, excepturi enim reiciendis, tempora ab ipsam illum aspernatur quasi qui porro saepe iure sunt eligendi tenetur quaerat ducimus quas sequi omnis aperiam suscipit! Molestiae obcaecati officiis quo, ratione eveniet, provident pariatur. Veniam quasi expedita distinctio, itaque molestiae sequi, dolorum nisi repellendus quia facilis iusto dignissimos nam? Tenetur fugit quos autem nihil, perspiciatis expedita enim tempore, alias ab maiores quis necessitatibus distinctio molestias eum, quidem. Delectus impedit quidem laborum, fugit vel neque quo, ipsam, quasi aspernatur quas odio nihil? Veniam amet reiciendis blanditiis quis reprehenderit repudiandae neque, ab ducimus, odit excepturi voluptate saepe ipsam. Voluptatem eum error voluptas porro officiis, amet! Molestias, fugit, ut! Tempore non magnam, amet, facere ducimus accusantium eos veritatis neque.

    +

    Lorem ipsum dolor sit amet, consectetur adipisicing elit. Distinctio maiores adipisci quibusdam repudiandae dolor vero placeat esse sit! Quibusdam saepe aperiam explicabo placeat optio, consequuntur nihil voluptatibus expedita quia vero perferendis, deserunt et incidunt eveniet temporibus doloremque possimus facilis. Possimus labore, officia dolore! Eaque ratione saepe, alias harum laboriosam deserunt laudantium blanditiis eum explicabo placeat reiciendis labore iste sint. Consectetur expedita dignissimos, non quos distinctio, eos rerum facilis eligendi. Asperiores laudantium, rerum ratione consequatur, culpa consectetur possimus atque ab tempore illum non dolor nesciunt. Neque, rerum. A vel non incidunt, quod doloremque dignissimos necessitatibus aliquid laboriosam architecto at cupiditate commodi expedita in, quae blanditiis. Deserunt labore sequi, repellat laboriosam est, doloremque culpa reiciendis tempore excepturi. Enim nostrum fugit itaque vel corporis ullam sed tenetur ipsa qui rem quam error sint, libero. Laboriosam rem, ratione. Autem blanditiis laborum neque repudiandae quam, cumque, voluptate veritatis itaque, placeat veniam ad nisi. Expedita, laborum reprehenderit ratione soluta velit natus, odit mollitia. Corporis rerum minima fugiat in nostrum. Assumenda natus cupiditate hic quidem ex, quas, amet ipsum esse dolore facilis beatae maxime qui inventore, iste? Maiores dignissimos dolore culpa debitis voluptatem harum, excepturi enim reiciendis, tempora ab ipsam illum aspernatur quasi qui porro saepe iure sunt eligendi tenetur quaerat ducimus quas sequi omnis aperiam suscipit! Molestiae obcaecati officiis quo, ratione eveniet, provident pariatur. Veniam quasi expedita distinctio, itaque molestiae sequi, dolorum nisi repellendus quia facilis iusto dignissimos nam? Tenetur fugit quos autem nihil, perspiciatis expedita enim tempore, alias ab maiores quis necessitatibus distinctio molestias eum, quidem. Delectus impedit quidem laborum, fugit vel neque quo, ipsam, quasi aspernatur quas odio nihil? Veniam amet reiciendis blanditiis quis reprehenderit repudiandae neque, ab ducimus, odit excepturi voluptate saepe ipsam. Voluptatem eum error voluptas porro officiis, amet! Molestias, fugit, ut! Tempore non magnam, amet, facere ducimus accusantium eos veritatis neque.

    + + + + +
    + + + + + + + diff --git a/13 - Slide in on Scroll/script.js b/13 - Slide in on Scroll/script.js new file mode 100644 index 0000000000..17a92dfd46 --- /dev/null +++ b/13 - Slide in on Scroll/script.js @@ -0,0 +1,57 @@ +'use strict'; + +// Returns a function, that, as long as it continues to be invoked, will not be triggered. +// The function will be called after it stops being called for N milliseconds. + +/* +Start with no timeout. +If the produced function is called, clear and reset the timeout. +If the timeout is hit, call the original function. + */ + +function debounce(func, wait = 20) { + var timeout; + return function() { + // console.log('----- START -----'); + var context = this, args = arguments; + var later = function() { + // console.log(`RAZ du timeout (${timeout})`); + timeout = null; + }; + var callNow = !timeout; + // console.log('clear timeout: ', timeout); + clearTimeout(timeout); + timeout = setTimeout(later, wait); + // console.log('set timeout: ', timeout); + if (callNow) { + func.apply(context, args); + } + // console.log('----- STOP -----'); + }; +} + +const sliderImages = document.querySelectorAll('.slide-in'); + +function checkSlide() { + sliderImages.forEach(sliderImage => { + console.log(sliderImage.src); + console.log('offsetTop: ', sliderImage.offsetTop); + // position du bas de la page + const bottomOfThePage = window.scrollY + window.innerHeight ; + console.log('slideInAt: ' + bottomOfThePage); + // bottom of the image + const imageBottom = sliderImage.offsetTop + sliderImage.height; + console.log('imageBottom: ' + imageBottom); + + // half way through the image + const isHalfShown = bottomOfThePage > sliderImage.offsetTop + (sliderImage.height / 2); + const isNotScrolledPast = window.scrollY < imageBottom; + if (isHalfShown && isNotScrolledPast) { + sliderImage.classList.add('active'); + } else { + sliderImage.classList.remove('active'); + } + }); +} + +window.addEventListener('scroll', debounce(checkSlide)); diff --git a/14 - JavaScript References VS Copying/index.html b/14 - JavaScript References VS Copying/index.html new file mode 100644 index 0000000000..7221ea40c9 --- /dev/null +++ b/14 - JavaScript References VS Copying/index.html @@ -0,0 +1,10 @@ + + + + + JS Reference VS Copy + + + + + diff --git a/14 - JavaScript References VS Copying/script.js b/14 - JavaScript References VS Copying/script.js new file mode 100644 index 0000000000..d9eca8ee94 --- /dev/null +++ b/14 - JavaScript References VS Copying/script.js @@ -0,0 +1,80 @@ +'use strict'; + +// start with strings, numbers and booleans +// type primitif => passage par copie + +// Let's say we have an array +const players = ['Wes', 'Sarah', 'Ryan', 'Poppy']; + +// and we want to make a copy of it. + +// objet => passage par reference + +// You might think we can just do something like this: + +// however what happens when we update that array? + +// now here is the problem! + +// oh no - we have edited the original array too! + +// Why? It's because that is an array reference, not an array copy. They both point to the same array! + +// So, how do we fix this? We take a copy instead! +var copy = players.slice(); +var copy2 = [].concat(players); +var copy3 = [...players]; +var copy4 = Array.from(players); + + +// one day + +// or create a new array and concat the old one in + +// or use the new ES6 Spread + +// now when we update it, the original one isn't changed + +// The same thing goes for objects, let's say we have a person object + +// with Objects +const captain = { + name: 'igloo', + age: 76 +} + + +// and think we make a copy: + +// how do we take a copy instead? +const marin = Object.assign({}, captain, {age: 99, barbe: true}); +console.log(marin); + +// We will hopefully soon see the object ...spread + +// Things to note - this is only 1 level deep - both for Arrays and Objects. lodash has a cloneDeep method, but you should think twice before using it. + +// => SHALLOW COPY! + + + + +let obj1 = { + name: 'obj1', + age: { + number: 60, + unit: 'years' + } +}; + +const obj2 = Object.assign({}, obj1); + +//Poor man's deep clone, not recommended. Probably not the best performance wise ! +const obj3 = JSON.parse(JSON.stringify(obj1)); + +obj1.age.unit = 'months'; + + +console.log(obj1); +console.log(obj2); +console.log(obj3); diff --git a/15 - LocalStorage/index.html b/15 - LocalStorage/index.html new file mode 100644 index 0000000000..901678f5de --- /dev/null +++ b/15 - LocalStorage/index.html @@ -0,0 +1,36 @@ + + + + + LocalStorage + + + + + + + + + + + + +
    +

    LOCAL TAPAS

    +

    + +
    + + +
    +
    + + + + + diff --git a/15 - LocalStorage/script.js b/15 - LocalStorage/script.js new file mode 100644 index 0000000000..cf065b0ade --- /dev/null +++ b/15 - LocalStorage/script.js @@ -0,0 +1,50 @@ +'use strict'; + +const addItems = document.querySelector('.add-items'); //form +const itemsList = document.querySelector('.plates'); +const items = JSON.parse(localStorage.getItem('items')) || []; + +function addItem(event) { + // par defaut lors d'un submit le formulaire recharge la page / envoie des données au serveur + // on veut empecher ça (we are going to do this client side) + event.preventDefault(); + const text = this.querySelector('[name="item"]').value; + const item = { + text, //ES6 to the rescue + done: false + }; + // clear the input : reset the form + this.reset(); + items.push(item); + populateList(items, itemsList); + localStorage.setItem('items', JSON.stringify(items)); +} + +function populateList(plates = [], domList) { + domList.innerHTML = plates.map((plate, index) => { + return ` +
  • + + +
  • + `; + }).join(''); +} + +function toggleDone(event) { + if (!event.target.matches('input')) return; //eslint-disable-line curly + const el = event.target; + const index = el.dataset.index; + items[index].done = !items[index].done; + localStorage.setItem('items', JSON.stringify(items)); + // populateList(items, itemsList); +} + + +// we listen to 'submit', this event will be sent when there is a click on the submit button or enter +addItems.addEventListener('submit', addItem); + +// event delegation : we listen on the list, not on its children +itemsList.addEventListener('click', toggleDone); + +populateList(items, itemsList); diff --git a/15 - LocalStorage/style.css b/15 - LocalStorage/style.css index 3514871ab3..a211a45623 100644 --- a/15 - LocalStorage/style.css +++ b/15 - LocalStorage/style.css @@ -55,18 +55,18 @@ } - .plates input { + /*.plates input { display: none; - } + }*/ - .plates input + label:before { + /*.plates input + label:before { content: '⬜️'; margin-right: 10px; - } + }*/ - .plates input:checked + label:before { + /*.plates input:checked + label:before { content: '🌮'; - } + }*/ .add-items { margin-top: 20px; diff --git a/16 - Mouse Move Shadow/index.html b/16 - Mouse Move Shadow/index.html new file mode 100644 index 0000000000..4dc11b24fe --- /dev/null +++ b/16 - Mouse Move Shadow/index.html @@ -0,0 +1,37 @@ + + + + + Mouse Shadow + + + +
    +

    🔥WOAH!

    +
    + + + + + + + diff --git a/16 - Mouse Move Shadow/script.js b/16 - Mouse Move Shadow/script.js new file mode 100644 index 0000000000..de5b3a7598 --- /dev/null +++ b/16 - Mouse Move Shadow/script.js @@ -0,0 +1,27 @@ +'use strict'; + +const hero = document.querySelector('.hero'); +const text = hero.querySelector('h1'); +const walk = 100; // distance max => max coordinates are going to be -50 et +50 around the element + +const {offsetHeight: height, offsetWidth: width} = hero; + +function shadow(event) { + let {offsetX: x, offsetY: y} = event; + //this = hero, but event.target = hero or h1 (children of hero) + if (this !== event.target) { + x += event.target.offsetLeft; + y += event.target.offsetTop; + } + + const xwalk = Math.round(x / width * walk - walk / 2); + const ywalk = Math.round(y / height * walk - walk / 2); + console.log(xwalk, ywalk); + text.style.textShadow = ` + ${xwalk}px ${ywalk}px 0 rgb(87, 140, 32), + ${xwalk * -1}px ${ywalk * - 1}px 0 rgb(164, 111, 5) + `; +} + + +hero.addEventListener('mousemove', shadow); diff --git a/17 - Sort Without Articles/index.html b/17 - Sort Without Articles/index.html new file mode 100644 index 0000000000..6c442bcfae --- /dev/null +++ b/17 - Sort Without Articles/index.html @@ -0,0 +1,48 @@ + + + + + Sort Without Articles + + + + + + + + + + + diff --git a/17 - Sort Without Articles/script.js b/17 - Sort Without Articles/script.js new file mode 100644 index 0000000000..cae70a9af7 --- /dev/null +++ b/17 - Sort Without Articles/script.js @@ -0,0 +1,31 @@ +'use strict'; + +const bands = ['The Plot in You', 'The Devil Wears Prada', 'Pierce the Veil', 'Norma Jean', 'The Bled', 'Say Anything', 'The Midway State', +'We Came as Romans', 'Counterparts', 'Oh, Sleeper', 'A Skylit Drive', 'Anywhere But Here', 'An Old Dog', 'YOLO brothers']; + + +// const forbidden = ['a', 'an', 'the', 'A', 'An', 'The']; +// +// function cleanWord(str) { +// const firstWord = str.split(' ')[0]; +// if (forbidden.includes(firstWord)) { +// const regexp = new RegExp(firstWord); +// return str.replace(regexp, '').substr(1); +// } +// return str; +// } + +function strip(word) { + return word.replace(/^a |an |the /i, ''); +} + +bands.sort((word1, word2) => strip(word1) > strip(word2) ? 1 : -1); + +console.log(bands); + + +function renderBands(bands) { + return bands.map(b => `
  • ${b}
  • `).join(''); +} + +document.querySelector('#bands').innerHTML = renderBands(bands); diff --git a/18 - Adding Up Times with Reduce/index.html b/18 - Adding Up Times with Reduce/index.html new file mode 100644 index 0000000000..4b37419937 --- /dev/null +++ b/18 - Adding Up Times with Reduce/index.html @@ -0,0 +1,186 @@ + + + + + Videos + + + + + + diff --git a/18 - Adding Up Times with Reduce/script.js b/18 - Adding Up Times with Reduce/script.js new file mode 100644 index 0000000000..d9f5b3f389 --- /dev/null +++ b/18 - Adding Up Times with Reduce/script.js @@ -0,0 +1,20 @@ +'use strict'; + +const timeNodes = Array.from(document.querySelectorAll('[data-time]')); + +const seconds = timeNodes + .map(node => node.dataset.time) + .map(time => { + const [mins, secs] = time.split(':').map(Number.parseFloat); //parseInt ne fonctionne pas car on lui passe un mauvaise radix + return mins * 60 + secs; + }) + .reduce((a, b) => a + b, 0); + +const hours = Math.floor(seconds / 3600); + + +const minutesLeft = Math.floor((seconds%3600) / 60); + +const secondsLeft = seconds%60; + +console.log(seconds, hours, minutesLeft, secondsLeft); diff --git a/19 - Webcam Fun/index.html b/19 - Webcam Fun/index.html index d4ffc4dc2a..8fa7d97b3a 100755 --- a/19 - Webcam Fun/index.html +++ b/19 - Webcam Fun/index.html @@ -9,7 +9,7 @@
    - +