crowds/slides/js/lib/helpers.js

55 lines
1.0 KiB
JavaScript
Raw Normal View History

2018-03-27 17:39:08 +00:00
//////////////////
// HELPERS ///////
//////////////////
Math.TAU = 6.2831853072;
// The poor man's jQuery
function $(query){
return document.querySelector(query);
}
function $all(query){
return document.querySelectorAll(query);
}
// Wide Sigmoid
function sigmoid(x){
return x / (1 + Math.abs(x));
}
// Create retina canvas
function createCanvas(canvas, width, height){
// The "canvas" arg not provided? make a new one!
if(arguments.length==2){
height = arguments[1];
2018-03-28 14:57:19 +00:00
width = arguments[0];
2018-03-27 17:39:08 +00:00
canvas = document.createElement("canvas");
}
// Set difference in width & height
canvas.width = width*2;
canvas.height = height*2;
canvas.style.width = width;
canvas.style.height = height;
return canvas;
}
// Copy an object
function cloneObject(obj){
return JSON.parse(JSON.stringify(obj));
}
2018-03-28 17:12:05 +00:00
// Get words
function getWords(wordsID){
return $("words#"+wordsID).innerHTML;
2018-04-01 16:34:52 +00:00
}
// Remove from array
function removeFromArray(array, item){
var index = array.indexOf(item);
if(index>=0) array.splice(index,1);
}