Cleaned up and updated vars to ES6
This commit is contained in:
parent
7b4318dc86
commit
988d718b5a
|
@ -4,26 +4,21 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
||||||
canvas: !!window.CanvasRenderingContext2D,
|
canvas: !!window.CanvasRenderingContext2D,
|
||||||
webgl: (function() {
|
webgl: (function() {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
var canvas = document.createElement('canvas');
|
var canvas = document.createElement('canvas');
|
||||||
|
|
||||||
return !!( window.WebGLRenderingContext && ( canvas.getContext('webgl') || canvas.getContext('experimental-webgl') ) );
|
return !!( window.WebGLRenderingContext && ( canvas.getContext('webgl') || canvas.getContext('experimental-webgl') ) );
|
||||||
|
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
}
|
}
|
||||||
})(),
|
})(),
|
||||||
|
|
||||||
workers: !!window.Worker,
|
workers: !!window.Worker,
|
||||||
fileapi: window.File && window.FileReader && window.FileList && window.Blob,
|
fileapi: window.File && window.FileReader && window.FileList && window.Blob,
|
||||||
|
|
||||||
getWebGLErrorMessage: function() {
|
getWebGLErrorMessage: function() {
|
||||||
|
|
||||||
var element = document.createElement('div');
|
var element = document.createElement('div');
|
||||||
element.id = 'webgl-error-message';
|
element.id = 'webgl-error-message';
|
||||||
element.style.fontFamily = 'monospace';
|
element.style.fontFamily = 'monospace';
|
||||||
|
@ -37,7 +32,6 @@ export default {
|
||||||
element.style.margin = '5em auto 0';
|
element.style.margin = '5em auto 0';
|
||||||
|
|
||||||
if(!this.webgl) {
|
if(!this.webgl) {
|
||||||
|
|
||||||
element.innerHTML = window.WebGLRenderingContext ? [
|
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 />',
|
'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>.'
|
'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/>',
|
'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>.'
|
'Find out how to get it <a href="http://get.webgl.org/" style="color:#000000">here</a>.'
|
||||||
].join('\n');
|
].join('\n');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return element;
|
return element;
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
addGetWebGLMessage: function(parameters) {
|
addGetWebGLMessage: function(parameters) {
|
||||||
|
|
||||||
var parent, id, element;
|
var parent, id, element;
|
||||||
|
|
||||||
parameters = parameters || {};
|
parameters = parameters || {};
|
||||||
|
@ -65,7 +56,5 @@ export default {
|
||||||
element.id = id;
|
element.id = id;
|
||||||
|
|
||||||
parent.appendChild(element);
|
parent.appendChild(element);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
export default class Helpers {
|
export default class Helpers {
|
||||||
static throttle(fn, threshhold, scope) {
|
static throttle(fn, threshhold, scope) {
|
||||||
threshhold || (threshhold = 250);
|
threshhold || (threshhold = 250);
|
||||||
var last, deferTimer;
|
let last, deferTimer;
|
||||||
|
|
||||||
return function() {
|
return function() {
|
||||||
var context = scope || this;
|
const context = scope || this;
|
||||||
|
|
||||||
var now = +new Date,
|
const now = +new Date,
|
||||||
args = arguments;
|
args = arguments;
|
||||||
|
|
||||||
if(last && now < last + threshhold) {
|
if(last && now < last + threshhold) {
|
||||||
// hold on to it
|
|
||||||
clearTimeout(deferTimer);
|
clearTimeout(deferTimer);
|
||||||
deferTimer = setTimeout(function() {
|
deferTimer = setTimeout(function() {
|
||||||
last = now;
|
last = now;
|
||||||
|
|
|
@ -32,7 +32,7 @@ export default class Keyboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
onBlur() {
|
onBlur() {
|
||||||
for(let prop in this.keyCodes)
|
for(const prop in this.keyCodes)
|
||||||
this.keyCodes[prop] = false;
|
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)
|
//console.log('onKeyChange', event, event.keyCode, event.shiftKey, event.ctrlKey, event.altKey, event.metaKey)
|
||||||
|
|
||||||
// update this.keyCodes
|
// update this.keyCodes
|
||||||
let keyCode = event.keyCode;
|
const keyCode = event.keyCode;
|
||||||
this.keyCodes[keyCode] = event.type === 'keydown';
|
this.keyCodes[keyCode] = event.type === 'keydown';
|
||||||
}
|
}
|
||||||
|
|
||||||
pressed(keyDesc) {
|
pressed(keyDesc) {
|
||||||
let keys = keyDesc.split('+');
|
const keys = keyDesc.split('+');
|
||||||
for(let i = 0; i < keys.length; i++) {
|
for(let i = 0; i < keys.length; i++) {
|
||||||
let key = keys[i];
|
const key = keys[i];
|
||||||
let pressed = false;
|
let pressed = false;
|
||||||
if(Object.keys(ALIAS).indexOf(key) != -1) {
|
if(Object.keys(ALIAS).indexOf(key) != -1) {
|
||||||
pressed = this.keyCodes[ALIAS[key]];
|
pressed = this.keyCodes[ALIAS[key]];
|
||||||
|
@ -63,24 +63,24 @@ export default class Keyboard {
|
||||||
}
|
}
|
||||||
|
|
||||||
eventMatches(event, keyDesc) {
|
eventMatches(event, keyDesc) {
|
||||||
let aliases = ALIAS;
|
const aliases = ALIAS;
|
||||||
let aliasKeys = Object.keys(aliases);
|
const aliasKeys = Object.keys(aliases);
|
||||||
let keys = keyDesc.split('+');
|
const keys = keyDesc.split('+');
|
||||||
// log to debug
|
// log to debug
|
||||||
// console.log('eventMatches', event, event.keyCode, event.shiftKey, event.ctrlKey, event.altKey, event.metaKey)
|
// console.log('eventMatches', event, event.keyCode, event.shiftKey, event.ctrlKey, event.altKey, event.metaKey)
|
||||||
for(let i = 0; i < keys.length; i++) {
|
for(let i = 0; i < keys.length; i++) {
|
||||||
let key = keys[i];
|
const key = keys[i];
|
||||||
let pressed = false;
|
let pressed = false;
|
||||||
if(key === 'shift') {
|
if(key === 'shift') {
|
||||||
pressed = (event.shiftKey ? true : false);
|
pressed = event.shiftKey ? true : false;
|
||||||
} else if(key === 'ctrl') {
|
} else if(key === 'ctrl') {
|
||||||
pressed = (event.ctrlKey ? true : false);
|
pressed = event.ctrlKey ? true : false;
|
||||||
} else if(key === 'alt') {
|
} else if(key === 'alt') {
|
||||||
pressed = (event.altKey ? true : false);
|
pressed = event.altKey ? true : false;
|
||||||
} else if(key === 'meta') {
|
} else if(key === 'meta') {
|
||||||
pressed = (event.metaKey ? true : false);
|
pressed = event.metaKey ? true : false;
|
||||||
} else if(aliasKeys.indexOf(key) !== -1) {
|
} else if(aliasKeys.indexOf(key) !== -1) {
|
||||||
pressed = (event.keyCode === aliases[key]);
|
pressed = event.keyCode === aliases[key];
|
||||||
} else if(event.keyCode === key.toUpperCase().charCodeAt(0)) {
|
} else if(event.keyCode === key.toUpperCase().charCodeAt(0)) {
|
||||||
pressed = true;
|
pressed = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue