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
/** | |
* Return a random number between min/max where the mean | |
* result is approximately the mode across a uniform distribution. | |
* @param min {Number} - lower limit of range (inclusive) | |
* @param max {Number} - upper limit of range (inclusive) | |
* @return {Function} - a function that returns a random number between 'min' and 'max' | |
*/ | |
var genRandomFromRangeFn = function(min, max) { | |
return function() { | |
var res = Math.round(Math.random() * (max - min)) + min; |
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 extend(/* objects */) { | |
var args = [].slice.call(arguments,0), | |
base = args.shift(), | |
len = args.length; | |
while (args.length) { | |
var o = args.pop(); | |
for (var prop in o) { | |
// properties override those existing | |
if (typeof base[prop] === 'undefined' && typeof o[prop] !== 'function') { | |
base[prop] = o[prop]; |
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 (root, factory) { | |
if (typeof define === 'function' && define.amd) { | |
// AMD. Register as an anonymous module. | |
define([], factory); | |
} else if (typeof exports === 'object') { | |
// Node. Does not work with strict CommonJS, but | |
// only CommonJS-like environments that support module.exports, | |
// like Node. | |
module.exports = factory(); | |
} else { |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<style type="text/css"> | |
.moveable { | |
border: 1px solid red; | |
display: inline-block; | |
padding: 2px; | |
font-family: sans-serif; | |
} |
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 (factory) { | |
if (typeof exports == 'object') { | |
factory(require('jquery')); | |
} else if (typeof define == 'function' && define.amd) { | |
define(['jquery'], factory); | |
} else { | |
factory(jQuery); | |
} | |
}(function($) { | |
'use strict'; |
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
{ | |
// JSHint Default Configuration File | |
// See http://jshint.com/docs/ for more details | |
"maxerr" : 50, // {int} Maximum error before stopping | |
// Enforcing | |
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.) | |
"camelcase" : false, // true: Identifiers must be in camelCase | |
"curly" : true, // true: Require {} for every new block or scope |
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 parseUrl(url) { | |
var _url = (url || window.location.href).match(/^(?:(https?:)\/\/)?([^\?\#\/\:]+)(?::(\d+))?([^\?\#]+)?(\?[^#]+)?(#[^\s]+)?$/), | |
params = _url[5] || false; | |
if (!_url.length) { | |
// couldn't parse url string | |
return false; | |
} | |
if (params && !/^$/.test(params)) { |
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 xhr(){ | |
try { | |
return new XMLHttpRequest(); | |
}catch(e){} | |
try { | |
return new ActiveXObject("Msxml3.XMLHTTP"); | |
}catch(e){} | |
try { | |
return new ActiveXObject("Msxml2.XMLHTTP.6.0"); | |
}catch(e){} |
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
var Promise = function() { | |
this.resolve_callbacks = []; | |
this.reject_callbacks = []; | |
this.state = null; | |
}; | |
Promise.prototype = { | |
then: function(resolvefn, rejectfn) { | |
if (this.state == 'resolved') { | |
resolvefn(); |
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
/** Faster rounding function to avoid heavy use of Math.round */ | |
function round(n) { | |
return (n + 0.5) << 0; | |
} | |
/** | |
* Wrapper for getBoundingClientRect that returns a | |
* subset ('top','left') and includes a 'width' and 'height'. | |
* It also rounds the pixel measurements to the nearest integer value | |
* |