From d4c5fc4e99bef5b4276b6ae47a0c44008c7381c3 Mon Sep 17 00:00:00 2001 From: Andrew Ellis Date: Wed, 21 Dec 2016 15:06:22 -0500 Subject: [PATCH] added stuff --- 01 - JavaScript Drum Kit/index-START.html | 34 ++++++ 01 - JavaScript Drum Kit/style.css | 8 +- 02 - JS + CSS Clock/index-START.html | 58 ++++++++++ 03 - CSS Variables/index-START.html | 47 ++++++++ 04 - Array Cardio Day 1/index-START.html | 61 ++++++++++- 05 - Flex Panel Gallery/index-START.html | 41 +++++++ 06 - Type Ahead/index-START.html | 39 +++++++ 08 - Fun with HTML5 Canvas/index-START.html | 67 ++++++++++++ .../index-START.html | 28 +++++ .../{index.html => index-FINISHED.html} | 2 +- 11 - Custom Video Player/index-Start.html | 28 +++++ 11 - Custom Video Player/scripts-START.js | 58 ++++++++++ 11 - Custom Video Player/scripts.js | 0 12 - Key Sequence Detection/index-START.html | 34 ++++++ node_stuff/linked_list.js | 51 +++++++++ node_stuff/package.json | 15 +++ node_stuff/test/LinkedList.js | 100 ++++++++++++++++++ 17 files changed, 665 insertions(+), 6 deletions(-) rename 11 - Custom Video Player/{index.html => index-FINISHED.html} (95%) create mode 100644 11 - Custom Video Player/index-Start.html create mode 100644 11 - Custom Video Player/scripts-START.js delete mode 100644 11 - Custom Video Player/scripts.js create mode 100644 node_stuff/linked_list.js create mode 100644 node_stuff/package.json create mode 100644 node_stuff/test/LinkedList.js diff --git a/01 - JavaScript Drum Kit/index-START.html b/01 - JavaScript Drum Kit/index-START.html index 4070d32767..535402add4 100644 --- a/01 - JavaScript Drum Kit/index-START.html +++ b/01 - JavaScript Drum Kit/index-START.html @@ -58,7 +58,41 @@ diff --git a/01 - JavaScript Drum Kit/style.css b/01 - JavaScript Drum Kit/style.css index 3e0a320b37..ddc0fa661b 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 0.07s; width:100px; text-align: center; color:white; @@ -32,11 +32,15 @@ body,html { } .playing { - transform:scale(1.1); + transform:scale(1.3); border-color:#ffc600; box-shadow: 0 0 10px #ffc600; } +.boom { + transform: scale(2); +} + kbd { display: block; font-size: 40px; diff --git a/02 - JS + CSS Clock/index-START.html b/02 - JS + CSS Clock/index-START.html index 240705d8fe..e039f70503 100644 --- a/02 - JS + CSS Clock/index-START.html +++ b/02 - JS + CSS Clock/index-START.html @@ -61,12 +61,70 @@ background:black; position: absolute; top:50%; + transform-origin: right; + } + .hour-hand { + height: 10px; + } + .min-hand { + height: 8px; } diff --git a/03 - CSS Variables/index-START.html b/03 - CSS Variables/index-START.html index bf0f33e3ba..a308115ebf 100644 --- a/03 - CSS Variables/index-START.html +++ b/03 - CSS Variables/index-START.html @@ -26,6 +26,10 @@

Update CSS Variables with JS

misc styles, nothing to do with CSS variables */ + img { + transition: all .5s; + } + body { text-align: center; } @@ -53,6 +57,49 @@

Update CSS Variables with JS

diff --git a/04 - Array Cardio Day 1/index-START.html b/04 - Array Cardio Day 1/index-START.html index 6e28e357d0..876ac83369 100644 --- a/04 - Array Cardio Day 1/index-START.html +++ b/04 - Array Cardio Day 1/index-START.html @@ -27,29 +27,84 @@ // Array.prototype.filter() // 1. Filter the list of inventors for those who were born in the 1500's + const sixteenth = inventors.filter( ({ year }) => 1500 <= year && year <= 1599 ); + console.table( sixteenth ); // Array.prototype.map() // 2. Give us an array of the inventory first and last names + // + const firstAndLasts = inventors.map( ({ first, last }) => { + + return `${first} ${last}`; + } ); + console.log( firstAndLasts ); // Array.prototype.sort() // 3. Sort the inventors by birthdate, oldest to youngest - + const sorted = inventors.sort( ( first, second ) => { + return first.year > second.year ? 1 : -1; + }); + console.table( sorted ); // Array.prototype.reduce() // 4. How many years did all the inventors live? - + const reducto = inventors.reduce( ( prev, curr ) => { + return prev + ( curr.passed - curr.year ); + }, 0 ); + console.log( reducto ); // 5. Sort the inventors by years lived + const sortedYears = inventors.sort( ( first, second ) => { + return ( first.passed - first.year ) > ( second.passed = second.year ) ? 1 : -1; + }); + console.table( sortedYears ); // 6. create a list of Boulevards in Paris that contain 'de' anywhere in the name // https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris + // + function parseDes( doc ) { + const list = Array.prototype.slice.call( doc.querySelectorAll('.mw-category ul>li') ); + return list + .filter( el => /de/.test( el.textContent ) ) + .map( ({ textContent }) => textContent ); + } + const req = new XMLHttpRequest() + let frag = document.createDocumentFragment(); + + function end() { + let el = document.createElement('div'); + el.innerHTML = req.responseText; + frag.appendChild( el ); + + const nameList = parseDes( frag ); + console.log( nameList ); + } + req.addEventListener( 'load', end ); + req.addEventListener( 'error', err => console.error ); + req.addEventListener( 'abort', err => console.error ); + + + const url = 'https://en.wikipedia.org/wiki/Category:Boulevards_in_Paris'; + req.open( 'GET', url, true ); + req.setRequestHeader('Access-Control-Allow-Origin', '*' ); + req.setRequestHeader('Content-Type', 'text/plain' ); + req.send(); + // 7. sort Exercise // Sort the people alphabetically by last name - + const sortedThree = people.sort( ( a, b ) => { + return a.toLowerCase() > b.toLowerCase() ? 1 : -1; + } ); + console.log(sortedThree ); // 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 sumData = data.reduce( ( prev, curr ) => { + prev[ curr ] += 1; + return prev; + }, { car: 0, truck: 0, bike: 0, walk: 0, van: 0 } ); + console.log( sumData ); diff --git a/05 - Flex Panel Gallery/index-START.html b/05 - Flex Panel Gallery/index-START.html index e1d643ad5c..ad11f6857b 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,12 @@ font-size: 20px; background-size:cover; background-position:center; + flex: 1; + + justify-content: center; + display: flex; + flex-direction: column; + } @@ -54,6 +61,11 @@ margin:0; width: 100%; transition:transform 0.5s; + border: 1px solid red; + flex: 1 0 auto; + display: flex; + justify-content: center; + align-items: center; } .panel p { @@ -66,8 +78,22 @@ font-size: 4em; } + .panel > *:first-child { + transform: translateY(-100%); + } + .panel > *:last-child { + transform: translateY(100%); + } + .panel.open-active > *:first-child { + transform: translateY(0); + } + .panel.open-active > *:last-child { + transform: translateY(0); + } + .panel.open { font-size:40px; + flex: 5; } .cta { @@ -108,6 +134,21 @@ diff --git a/06 - Type Ahead/index-START.html b/06 - Type Ahead/index-START.html index 1436886918..22c8d9a915 100644 --- a/06 - Type Ahead/index-START.html +++ b/06 - Type Ahead/index-START.html @@ -16,6 +16,45 @@ diff --git a/08 - Fun with HTML5 Canvas/index-START.html b/08 - Fun with HTML5 Canvas/index-START.html index 37c148df07..5a0fecca93 100644 --- a/08 - Fun with HTML5 Canvas/index-START.html +++ b/08 - Fun with HTML5 Canvas/index-START.html @@ -5,14 +5,81 @@ HTML5 Canvas +
Clear
diff --git a/10 - Hold Shift and Check Checkboxes/index-START.html b/10 - Hold Shift and Check Checkboxes/index-START.html index eb7ed310bb..6b54101e03 100644 --- a/10 - Hold Shift and Check Checkboxes/index-START.html +++ b/10 - Hold Shift and Check Checkboxes/index-START.html @@ -104,6 +104,34 @@ diff --git a/11 - Custom Video Player/index.html b/11 - Custom Video Player/index-FINISHED.html similarity index 95% rename from 11 - Custom Video Player/index.html rename to 11 - Custom Video Player/index-FINISHED.html index fe2b55b394..dee25cd7d0 100644 --- a/11 - Custom Video Player/index.html +++ b/11 - Custom Video Player/index-FINISHED.html @@ -22,6 +22,6 @@ - + diff --git a/11 - Custom Video Player/index-Start.html b/11 - Custom Video Player/index-Start.html new file mode 100644 index 0000000000..0903a3230c --- /dev/null +++ b/11 - Custom Video Player/index-Start.html @@ -0,0 +1,28 @@ + + + + + HTML Video Player + + + + +
+ + +
+
+
+
+ + + + + + +
+
+ + + + diff --git a/11 - Custom Video Player/scripts-START.js b/11 - Custom Video Player/scripts-START.js new file mode 100644 index 0000000000..43ebbcfbd3 --- /dev/null +++ b/11 - Custom Video Player/scripts-START.js @@ -0,0 +1,58 @@ +const video = document.querySelector('video'); +const [ ...buttons ] = document.querySelectorAll('button'); +const [ ...ranges ] = document.querySelectorAll('input[type="range"]'); +const progress = document.querySelector('.progress'); +const player = document.querySelector('.player'); +let scrubbing = false; + +function playPause( { currentTarget } ) { + if ( !( currentTarget = video ) ) { + return; + } + + if ( video.paused ) { + video.play(); + } else { + video.pause(); + } +} + +function skip( { currentTarget: { dataset: { skip } } } ) { + const timeToSeek = Number( skip ); + video.currentTime += timeToSeek; +} + +function setRange( ev ) { + const property = ev.currentTarget.name; + const val = ev.currentTarget.value; + video[ property ] = val; +} + +function scrubaDub( ev ) { + if ( scrubbing ) { + const ratio = ( ( ev.clientX - player.offsetLeft ) / ev.currentTarget.offsetWidth ); + const progBar = ev.currentTarget.children[ 0 ]; + progBar.style['flex-basis'] = `${ ratio * 100 }%`; + video.currentTime = video.duration * ratio; + } + + if ( ev.type === 'mouseup' ) { + scrubbing = false; + } +} + +video.addEventListener( 'click', playPause ); + +buttons.forEach( button => button.addEventListener( 'click', skip ) ); +ranges.forEach( range => range.addEventListener( 'input', setRange ) ); + + + +progress.addEventListener( 'mousedown', () => scrubbing = true ); +document.addEventListener( 'mouseout', ev => { + if ( ev.currentTarget === video ) { + scrubbing = false; + } +}); +progress.addEventListener( 'mouseup', scrubaDub ); +progress.addEventListener( 'mousemove', scrubaDub ); diff --git a/11 - Custom Video Player/scripts.js b/11 - Custom Video Player/scripts.js deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/12 - Key Sequence Detection/index-START.html b/12 - Key Sequence Detection/index-START.html index 8cab786140..97e4616e1a 100644 --- a/12 - Key Sequence Detection/index-START.html +++ b/12 - Key Sequence Detection/index-START.html @@ -7,6 +7,40 @@ diff --git a/node_stuff/linked_list.js b/node_stuff/linked_list.js new file mode 100644 index 0000000000..20d65621a2 --- /dev/null +++ b/node_stuff/linked_list.js @@ -0,0 +1,51 @@ +class LinkedList { + constructor() { + this._list = []; + + } + + get list() { + return this._list; + } + + set list( val ) { + return true; + } + + push( value ) { + const newNode = new Node({ + next: null, + previous: null, + value + }); + + + if( this._list.length === 0 ) { + this._list.push( newNode ); + return; + } + + const oldNode = this._list.pop(); + + + oldNode.next = newNode; + newNode.previous = oldNode; + this._list.push( oldNode ); + this._list.push( newNode ); + } + + remove( node ) { + + } +} + + +class Node { + constructor({ next, previous, value }) { + Object.assign( this, { next, previous, value } ); + } +} + + + +module.exports = new LinkedList(); diff --git a/node_stuff/package.json b/node_stuff/package.json new file mode 100644 index 0000000000..e3f74c83e5 --- /dev/null +++ b/node_stuff/package.json @@ -0,0 +1,15 @@ +{ + "name": "node_stuff", + "version": "1.0.0", + "description": "", + "main": "linked_list.js", + "directories": { + "test": "test" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC" +} diff --git a/node_stuff/test/LinkedList.js b/node_stuff/test/LinkedList.js new file mode 100644 index 0000000000..7988e4b860 --- /dev/null +++ b/node_stuff/test/LinkedList.js @@ -0,0 +1,100 @@ +const assert = require('chai').assert; +const path = '../linked_list.js'; +const rewire = require('rewire'); + +describe( 'LL export', function() { + it( 'should export a function', function() { + const LL = rewire( path ); + assert.isObject(LL); + }) + + + describe( 'initialize', function() { + it( 'it should have a list property', function() { + const LL = rewire( path ); + + assert.property( LL, 'list' ); + assert.isArray( LL.list ); + assert.equal( LL.list.length, 0 ); + }); + + + it( 'list property should not change list property', function() { + const LL = rewire( path ); + LL.list = 'foo'; + assert.notEqual( LL.list, 'foo' ); + }); + + }); + + describe( '#push', function() { + + it( 'should have method push', function() { + const LL = rewire( path ); + assert.isFunction( LL.push ); + }); + + + it( 'should add a node to list', function() { + const LL = rewire( path ); + const dummyObj = { foo: 'bar' }; + LL.push( dummyObj ); + assert.equal( LL.list.length, 1 ); + assert.equal( LL.list[0].value, dummyObj ); + assert.equal( LL.list[0].previous, null ); + assert.equal( LL.list[0].next, null ); + }); + + it( 'new node should have reference to previous node', function() { + const LL = rewire( path ); + const dummyObj = { foo: 'bar' }; + const dummyObjTwo = { foo: 'bar' }; + + LL.push( dummyObj ); + LL.push( dummyObjTwo ); + + + assert.equal( LL.list.length, 2 ); + assert.equal( LL.list[1].previous.value, dummyObj ); + }); + + it( 'should update previous node to have next', function() { + const LL = rewire( path ); + const dummyObj = { foo: 'bar' }; + const dummyObjTwo = { foo: 'bar' }; + + LL.push( dummyObj ); + LL.push( dummyObjTwo ); + + + assert.equal( LL.list[ 0 ].value, dummyObj, 'dummyone' ); + assert.equal( LL.list[ 1 ].value, dummyObjTwo, 'value of second element should be dummyObj'); + assert.equal( LL.list[ 0 ].next, LL.list[ 1 ] ); + }); + + }); + + describe('#remove()', () => { + + + it( 'should have remove method', () => { + const LL = rewire( path ); + assert.isFunction( LL.remove ); + }); + it( 'should reattach disconnected nodes', () => { + const LL = rewire( path ); + const dummyOne = { foo: 'bar' }; + const dummyTwo = { bar: 'baz' }; + const dummyThree = { bing: 'boom' }; + + LL.push( dummyOne ); + LL.push( dummyTwo ); + LL.push( dummyThree ); + + + LL + }); + + }) + +})