This file contains hidden or 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
/** | |
* Pad a number, in string format, with leading zeros. | |
* @param {number|string} num The number to pad | |
* @param {number} [size] The target length | |
* @returns {string} The padded number. | |
*/ | |
function pad(num, size) { | |
size = size || 2; | |
var s = num + ""; | |
while (s.length < size) s = "0" + s; |
This file contains hidden or 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
//simple sync function | |
function sync(/* funcsArray, done, seedDataArgs */) { | |
var args = Array.prototype.slice.call(arguments, 0); | |
//functions array to sync is first | |
var funcs = args.shift(); | |
//done callback is second | |
var done = args.shift(); | |
//all remaining arguments are the seed data | |
var counter = funcs.length; |
This file contains hidden or 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
//a constructor | |
function Thing(a, b, c, d){ | |
//a private constructor | |
function Thing(){ | |
//we don't care about d | |
this.d = d; | |
} | |
//a is read-only | |
Thing.prototype.getA = function(){ return a; }; |
This file contains hidden or 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
/** | |
* support for `Element.getBoudingClientRect()` goes back to IE5, FF3, and Chrome 1 | |
* it's great for getting the placement of a DOM element | |
* it is supposed to include `top`, `bottom`, `left`, and `right` in browser coordinates | |
* newer browsers also return `width` and `height` | |
* this code patches that, allowing all browsers access to the `widht` and `height` | |
*/ | |
function standardizeBoundingBox(bb) { | |
//IE8 does not have width and height in bounding boxes | |
return { |
This file contains hidden or 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
//this code will check if there is any overlap between two elements | |
//it was made to be used to check if a portion of a scrollably div is visible inside its wrapper | |
function isInView(containerBB, elBB) { | |
return (!( | |
elBB.top >= containerBB.bottom || | |
elBB.left >= containerBB.right || | |
elBB.bottom <= containerBB.top || | |
elBB.right <= containerBB.left | |
)); | |
} |
This file contains hidden or 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
var isZero = function(val){ return Math.abs(val) < 1.0e-14; } | |
var isNegative = function(val){ return (val < 0) ? true : val === 0 && (1/val)===-Infinity; } |
This file contains hidden or 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
var forEach = function(obj, cb, context){ | |
// check for a native forEach function | |
var native = [].forEach, | |
hasProp = Object.prototype.hasOwnProperty; | |
// if there is a native function, use it | |
if (native && obj.forEach === native) { | |
//don't bother if there is no function | |
cb && obj.forEach(cb, context); | |
} |
This file contains hidden or 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 getStyle(className) { | |
var parseRuleText = function(rule){ | |
var text = rule.split('{').pop().split('}').shift(); | |
var cssRules = {}; | |
var lines = text.split(';'); | |
forEach(lines, function(line){ | |
var rule = line.split(':'); | |
if (rule[0].trim()) cssRules[rule[0].trim()] = rule[1].trim(); |
This file contains hidden or 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
.transparent-background{ | |
/* IE8 transparent background fix -- #aaRRGGBB */ | |
-ms-filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#a6000000', endColorstr='#a6000000'); | |
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr='#a6000000', endColorstr='#a6000000'); | |
background: rgba(0,0,0,.65); | |
} |
This file contains hidden or 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
//IE8 compatible cancel of event | |
ev.stopPropagation ? ev.stopPropagation() : ev.cancelBubble = true; | |
ev.preventDefault ? ev.preventDefault() : ev.returnValue = false; |