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
// Determine the event name to use for mouse and touch detection/interaction. | |
// All browsers will listen to touch. | |
var clickTouch = "touchend"; | |
if (window.navigator.pointerEnabled) { | |
// IE11 mobile event, covering mouse and touch | |
clickTouch += " pointerup"; | |
} else if (window.navigator.msPointerEnabled) { | |
// IE10 mobile event, covering mouse and touch | |
clickTouch += " MSPointerUp"; | |
} else { |
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 sortDOM = (function(){ | |
var sort = [].sort; | |
return function(elems, comparator) { | |
// Sort the elements. | |
// Make sure to get the pure elements array out of the jQuery wrapper. | |
var sortCollection = sort.call($(elems).get(), comparator); | |
// Check to make sure we have items in the collection | |
if (sortCollection.length === 0) { |
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 color = { | |
red: [31, 39], | |
green: [32, 39], | |
yellow: [33, 39], | |
blue: [34, 39], | |
magenta: [35, 39], | |
cyan: [36, 39], | |
white: [37, 39], | |
gray: [90, 39], | |
dim: [2, 22] |
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 Queue = function(){ | |
var deferArray = [], | |
running = false; | |
function recursiveExecute(done) { | |
// maintain scope | |
(function recurse(){ | |
if (running && deferArray.length) { | |
var func = deferArray.shift(); | |
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
// standardize done arguments with Continuation Passing Style | |
var createDoneArgs = function(args){ | |
var doneArgs = [].slice.call(args); | |
doneArgs.unshift(undefined); | |
return doneArgs; | |
}; | |
//usage | |
function(arg1, arg2, npcCallback) { | |
var that = this; |
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 EventEmitter = function(){ | |
var events = {}; | |
this.on = function(name, callback){ | |
name = name.toLowerCase(); | |
events[name] = events[name] || []; | |
events[name].push(callback); | |
return this; | |
}; |
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 prefix = (function(){ | |
var styles = window.getComputedStyle(document.documentElement, ''); | |
var matches = [].slice.call(styles).join(' ').match(/-(moz|webkit|ms|o)-/); | |
return (matches) ? matches.shift() : null; | |
})(); | |
// based on this post | |
// http://davidwalsh.name/vendor-prefix | |
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 downloadString(str){ | |
// get a filename | |
var filename = (prompt('Filename')); | |
if ('Blob' in window) { | |
//create file blob | |
var blob = new Blob([str], { 'type': 'text/plain;charset=utf-8' }); | |
if (window.navigator.msSaveBlob) { | |
//works in IE 10, 11 |
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 c = { | |
hash: {}, | |
useNative: true, | |
time: function(str){ | |
if (this.useNative && console && console.time) console.time(str); | |
else this.hash[str] = (new Date()).getTime(); | |
}, | |
timeEnd: function(str){ | |
if (this.useNative && console && console.time && console.timeEnd) console.timeEnd(str); | |
else if (this.hash[str]){ |
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
if (!window.console) { window.console = { log: function () {} }; } // console fix for IE8 | |
if (!console.log) { console.log = Function.prototype.bind.call(console.log, console); } // console fix for IE9 |