Cleaned up and updated vars to ES6

This commit is contained in:
Paul Graffam 2016-10-06 23:10:05 -04:00
parent 7b4318dc86
commit 988d718b5a
3 changed files with 18 additions and 30 deletions

View File

@ -4,26 +4,21 @@
*/
export default {
canvas: !!window.CanvasRenderingContext2D,
webgl: (function() {
try {
var canvas = document.createElement('canvas');
return !!( window.WebGLRenderingContext && ( canvas.getContext('webgl') || canvas.getContext('experimental-webgl') ) );
} catch(e) {
return false;
}
})(),
workers: !!window.Worker,
fileapi: window.File && window.FileReader && window.FileList && window.Blob,
getWebGLErrorMessage: function() {
var element = document.createElement('div');
element.id = 'webgl-error-message';
element.style.fontFamily = 'monospace';
@ -37,7 +32,6 @@ export default {
element.style.margin = '5em auto 0';
if(!this.webgl) {
element.innerHTML = window.WebGLRenderingContext ? [
'Your graphics card does not seem to support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation" style="color:#000000">WebGL</a>.<br />',
'Find out how to get it <a href="http://get.webgl.org/" style="color:#000000">here</a>.'
@ -45,15 +39,12 @@ export default {
'Your browser does not seem to support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation" style="color:#000000">WebGL</a>.<br/>',
'Find out how to get it <a href="http://get.webgl.org/" style="color:#000000">here</a>.'
].join('\n');
}
return element;
},
addGetWebGLMessage: function(parameters) {
var parent, id, element;
parameters = parameters || {};
@ -65,7 +56,5 @@ export default {
element.id = id;
parent.appendChild(element);
}
};

View File

@ -1,16 +1,15 @@
export default class Helpers {
static throttle(fn, threshhold, scope) {
threshhold || (threshhold = 250);
var last, deferTimer;
let last, deferTimer;
return function() {
var context = scope || this;
const context = scope || this;
var now = +new Date,
const now = +new Date,
args = arguments;
if(last && now < last + threshhold) {
// hold on to it
clearTimeout(deferTimer);
deferTimer = setTimeout(function() {
last = now;

View File

@ -32,7 +32,7 @@ export default class Keyboard {
}
onBlur() {
for(let prop in this.keyCodes)
for(const prop in this.keyCodes)
this.keyCodes[prop] = false;
}
@ -41,14 +41,14 @@ export default class Keyboard {
//console.log('onKeyChange', event, event.keyCode, event.shiftKey, event.ctrlKey, event.altKey, event.metaKey)
// update this.keyCodes
let keyCode = event.keyCode;
const keyCode = event.keyCode;
this.keyCodes[keyCode] = event.type === 'keydown';
}
pressed(keyDesc) {
let keys = keyDesc.split('+');
const keys = keyDesc.split('+');
for(let i = 0; i < keys.length; i++) {
let key = keys[i];
const key = keys[i];
let pressed = false;
if(Object.keys(ALIAS).indexOf(key) != -1) {
pressed = this.keyCodes[ALIAS[key]];
@ -63,24 +63,24 @@ export default class Keyboard {
}
eventMatches(event, keyDesc) {
let aliases = ALIAS;
let aliasKeys = Object.keys(aliases);
let keys = keyDesc.split('+');
const aliases = ALIAS;
const aliasKeys = Object.keys(aliases);
const keys = keyDesc.split('+');
// log to debug
// console.log('eventMatches', event, event.keyCode, event.shiftKey, event.ctrlKey, event.altKey, event.metaKey)
for(let i = 0; i < keys.length; i++) {
let key = keys[i];
const key = keys[i];
let pressed = false;
if(key === 'shift') {
pressed = (event.shiftKey ? true : false);
pressed = event.shiftKey ? true : false;
} else if(key === 'ctrl') {
pressed = (event.ctrlKey ? true : false);
pressed = event.ctrlKey ? true : false;
} else if(key === 'alt') {
pressed = (event.altKey ? true : false);
pressed = event.altKey ? true : false;
} else if(key === 'meta') {
pressed = (event.metaKey ? true : false);
pressed = event.metaKey ? true : false;
} else if(aliasKeys.indexOf(key) !== -1) {
pressed = (event.keyCode === aliases[key]);
pressed = event.keyCode === aliases[key];
} else if(event.keyCode === key.toUpperCase().charCodeAt(0)) {
pressed = true;
}