diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..77794a20e9 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,5 @@ +root = true + +[*] +indent_style = tab +indent_size = 2 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6e1a3738b8..9af9f4fb13 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ node_modules/ *.log haters/ +*.js +*.js.map diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000000..0f7ea8b148 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Launch Chrome against localhost, with sourcemaps", + "type": "chrome", + "request": "launch", + "url": "http://localhost:8080", + "sourceMaps": true, + "webRoot": "${workspaceRoot}" + }, + { + "name": "Attach to Chrome, with sourcemaps", + "type": "chrome", + "request": "attach", + "port": 9222, + "sourceMaps": true, + "webRoot": "${workspaceRoot}" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..193806a477 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,16 @@ +{ + "typescript.check.workspaceVersion": false, + "files.exclude": { + "**/.git": true, + "**/.svn": true, + "**/.hg": true, + "**/.DS_Store": true, + "**/*.js": { + "when": "$(basename).ts" + } + }, + "typescript.tsdk": "./node_modules/typescript/lib", + "editor.formatOnSave": true, + "editor.tabSize": 2, + "editor.insertSpaces": false +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000000..dbb12dd67f --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,11 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "0.1.0", + "command": "tsc", + "isShellCommand": true, + "args": ["-w", "-p", "."], + "showOutput": "silent", + "isWatching": true, + "problemMatcher": "$tsc-watch" +} \ 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..85de0afbfd 100644 --- a/01 - JavaScript Drum Kit/index-START.html +++ b/01 - JavaScript Drum Kit/index-START.html @@ -57,9 +57,7 @@ - + diff --git a/01 - JavaScript Drum Kit/index.ts b/01 - JavaScript Drum Kit/index.ts new file mode 100644 index 0000000000..af983fc74b --- /dev/null +++ b/01 - JavaScript Drum Kit/index.ts @@ -0,0 +1,37 @@ +var keysDown: INumberMap = {}; + +window.addEventListener("keydown", (e) => { + const audio = document.querySelector(`audio[data-key="${e.keyCode}"]`); + if (!audio) return; + + if (keysDown[e.keyCode]) return; + + keysDown[e.keyCode] = true; + + const key = document.querySelector(`.key[data-key="${e.keyCode}"]`); + key && key.classList.add('playing'); + audio.currentTime = 0; + audio.play(); +}); + +window.addEventListener("keyup", (e) => { + e.key + if (keysDown[e.keyCode]) { + keysDown[e.keyCode] = false; + } +}) + + + +function removeTransition(e: TransitionEvent) { + if (e.propertyName !== 'transform') return; // skip it if it's not a transform + this.classList.remove('playing'); +} + +const keys = document.querySelectorAll('.key'); +console.log(keys); +// keys.forEach(key => key.addEventListener('transitionend', removeTransition)); + +for (var key of keys) { + key.addEventListener('transitionend', removeTransition); +} \ No newline at end of file diff --git a/define.d.ts b/define.d.ts new file mode 100644 index 0000000000..437977d19e --- /dev/null +++ b/define.d.ts @@ -0,0 +1,2 @@ +interface IStringMap { [key: string]: T; } +interface INumberMap { [key: number]: T; } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000000..c4b7b7cbbd --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "target": "es6", + "module": "commonjs", + "sourceMap": true, + "noImplicitAny": true, + "strictNullChecks": true, + "alwaysStrict": true + } +} \ No newline at end of file