This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Just add water | |
const = document.getElementById('water'); // Demo | |
/** | |
* setFPS sets the frame rate of the rAF function | |
* with minimum overhead. | |
* @Copyright Julien Etienne 2015 | |
* @License MIT | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// new Date().getTime() is only used to set inital time once for outdated browsers. | |
/** | |
* setFPS sets the frame rate of the rAF function | |
* with minimum overhead. | |
* @Copyright Julien Etienne 2015 | |
* @License MIT | |
*/ | |
function setFPS(callback, rAF, fps) { | |
// indexOf polyfill from MDN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Gets the DOM element, index is optional | |
* @param {String} type Selector type | |
* @param {String} element Selector reference | |
* @param {Number} index Collection index. | |
* @return {Object} node | HTMLCollection. | |
*/ | |
function get(type, element, index) { | |
var elementReference, htmlObject, | |
hasIndex = typeof index == 'number'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const delay = (callback, duration) => { | |
let startTime = 0; | |
let terminate = false; | |
const raf = requestAnimationFrame; | |
const loop = (timestamp) => { | |
startTime = startTime || timestamp; | |
if (timestamp > startTime + duration && !terminate && callback) | |
return callback(),terminate = true; | |
raf(loop); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Creates an equalateral triangle inside a given SVG parent node. | |
* @Author Julien Etienne - 2015 | |
* @param {Number} sideLength - Length of side | |
* @param {Array} centerPosition - central position the of triangle. | |
* @param {Object} parentNode - The parentNode of the new triangle. | |
* @return {Object} - The polygon element. | |
*/ | |
function equilateral(sideLength, centerPosition, parentNode) { | |
var points, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isObjectLiteral(value){ | |
return value === Object(value) && Object.prototype.toString.call(value) !== '[object Array]'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function flattenObject(ob) { | |
let toReturn = {}; | |
let flatObject; | |
for (let i in ob) { | |
console.log(i+ ' ' + typeof(ob[i])); | |
if (!ob.hasOwnProperty(i)) { | |
continue; | |
} | |
//Exclude arrays from the final result | |
//Check this http://stackoverflow.com/questions/4775722/check-if-object-is-array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div className="hello" id="world"> | |
<h1>Hello World!</h1> | |
<p>How are you?</p> | |
<figure className="img-section"> | |
<figcaption>Three different breeds of dogs</figcaption> | |
<img alt="Maltese Terrier" src="dog1.jpg" /> | |
<img alt="Black Labrador" src="dog2.jpg" /> | |
</figure> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
div({ class: 'hello', id: 'world' }, | |
h1('Hello World!'), | |
p('How are you?'), | |
figure({ class: 'img-section' }, | |
figcaption('Three different breeds of dogs.'), | |
img({ alt: 'Maltese Terrier', src: 'dog1.jpg' }), | |
img({ alt: 'Black Labrador', src: 'dog2.jpg' }) | |
) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createNodes, div, h1, p, figure, figcaption, img } from 'hypertext'; | |
const helloWorldTree = | |
div({ class: 'hello', id: 'world' }, | |
h1('Hello World!'), | |
p('How are you?'), | |
figure({ class: 'img-section' }, | |
figcaption('Three different breeds of dogs.'), | |
img({ alt: 'Maltese Terrier', src: 'dog1.jpg' }), | |
img({ alt: 'Black Labrador', src: 'dog2.jpg' } }) |