Comparing version 0.1.7 to 0.1.8
@@ -7,37 +7,37 @@ var cwd = process.cwd(); | ||
figlet = figlet.replace(/\n/g, '\n *'); | ||
figlet = figlet.replace(/\n/g, '\n *'); | ||
var source = require('chug')('scripts'); | ||
var source = require('chug')('scripts'); | ||
source.concat('jymin.js') | ||
.each(function (asset) { | ||
var locations = source.getLocations(); | ||
locations.forEach(function (location, index) { | ||
locations[index] = location.replace( | ||
/^.*\/node_modules\/([a-z]+)\/(.*?)$/, | ||
' * https://github.com/zerious/$1/blob/master/$2'); | ||
}); | ||
asset.setContent( | ||
"/**\n" + | ||
" *" + figlet + "\n" + | ||
" *\n" + | ||
" * http://lighter.io/jymin\n" + | ||
" * MIT License\n" + | ||
" *\n" + | ||
" * If you're seeing this in production, you really should minify.\n" + | ||
" *\n" + | ||
" * Source files:\n" + | ||
locations.join("\n") + "\n" + | ||
" */\n\n\n" + | ||
"this.jymin = {version: '" + exports.version + "'};\n\n" + | ||
asset.getContent()); | ||
}) | ||
.wrap('window, document, location, Math') | ||
.minify() | ||
.each(function (asset) { | ||
asset.content = addEval(asset.content); | ||
asset.minifiedContent = addEval(asset.minifiedContent); | ||
}) | ||
.write(cwd, 'jymin.js') | ||
.write(cwd, 'jymin.min.js', 'minified'); | ||
source.concat('jymin.js') | ||
.each(function (asset) { | ||
var locations = source.getLocations(); | ||
locations.forEach(function (location, index) { | ||
locations[index] = location.replace( | ||
/^.*\/node_modules\/([a-z]+)\/(.*?)$/, | ||
' * https://github.com/zerious/$1/blob/master/$2'); | ||
}); | ||
asset.setContent( | ||
"/**\n" + | ||
" *" + figlet + "\n" + | ||
" *\n" + | ||
" * http://lighter.io/jymin\n" + | ||
" * MIT License\n" + | ||
" *\n" + | ||
" * If you're seeing this in production, you really should minify.\n" + | ||
" *\n" + | ||
" * Source files:\n" + | ||
locations.join("\n") + "\n" + | ||
" */\n\n\n" + | ||
"this.jymin = {version: '" + exports.version + "'};\n\n" + | ||
asset.getContent()); | ||
}) | ||
.wrap('window, document, location, Math') | ||
.minify() | ||
.each(function (asset) { | ||
asset.content = addEval(asset.content); | ||
asset.minifiedContent = addEval(asset.minifiedContent); | ||
}) | ||
.write(cwd, 'jymin.js') | ||
.write(cwd, 'jymin.min.js', 'minified'); | ||
@@ -47,6 +47,6 @@ }); | ||
function addEval(code) { | ||
return code.replace( | ||
/([$_a-z]+) ?= ?JSON\.parse\(([$_a-z]+)\)/i, | ||
'eval("eval.J="+$2);$1=eval.J'); | ||
return code.replace( | ||
/([$_a-z]+) ?= ?JSON\.parse\(([$_a-z]+)\)/i, | ||
'eval("eval.J="+$2);$1=eval.J'); | ||
} | ||
function md5(s) { | ||
function add32(a, b) { | ||
return (a + b) & 0xFFFFFFFF; | ||
} | ||
if (md5('hello') != '5d41402abc4b2a76b9719d911017c592') { | ||
function add32(x, y) { | ||
var lsw = (x & 0xFFFF) + (y & 0xFFFF), | ||
msw = (x >> 16) + (y >> 16) + (lsw >> 16); | ||
return (msw << 16) | (lsw & 0xFFFF); | ||
} | ||
} | ||
function md5cycle(x, k) { | ||
var a = x[0], | ||
b = x[1], | ||
c = x[2], | ||
d = x[3]; | ||
a = ff(a, b, c, d, k[0], 7, -680876936); | ||
d = ff(d, a, b, c, k[1], 12, -389564586); | ||
c = ff(c, d, a, b, k[2], 17, 606105819); | ||
b = ff(b, c, d, a, k[3], 22, -1044525330); | ||
a = ff(a, b, c, d, k[4], 7, -176418897); | ||
d = ff(d, a, b, c, k[5], 12, 1200080426); | ||
c = ff(c, d, a, b, k[6], 17, -1473231341); | ||
b = ff(b, c, d, a, k[7], 22, -45705983); | ||
a = ff(a, b, c, d, k[8], 7, 1770035416); | ||
d = ff(d, a, b, c, k[9], 12, -1958414417); | ||
c = ff(c, d, a, b, k[10], 17, -42063); | ||
b = ff(b, c, d, a, k[11], 22, -1990404162); | ||
a = ff(a, b, c, d, k[12], 7, 1804603682); | ||
d = ff(d, a, b, c, k[13], 12, -40341101); | ||
c = ff(c, d, a, b, k[14], 17, -1502002290); | ||
b = ff(b, c, d, a, k[15], 22, 1236535329); | ||
a = gg(a, b, c, d, k[1], 5, -165796510); | ||
d = gg(d, a, b, c, k[6], 9, -1069501632); | ||
c = gg(c, d, a, b, k[11], 14, 643717713); | ||
b = gg(b, c, d, a, k[0], 20, -373897302); | ||
a = gg(a, b, c, d, k[5], 5, -701558691); | ||
d = gg(d, a, b, c, k[10], 9, 38016083); | ||
c = gg(c, d, a, b, k[15], 14, -660478335); | ||
b = gg(b, c, d, a, k[4], 20, -405537848); | ||
a = gg(a, b, c, d, k[9], 5, 568446438); | ||
d = gg(d, a, b, c, k[14], 9, -1019803690); | ||
c = gg(c, d, a, b, k[3], 14, -187363961); | ||
b = gg(b, c, d, a, k[8], 20, 1163531501); | ||
a = gg(a, b, c, d, k[13], 5, -1444681467); | ||
d = gg(d, a, b, c, k[2], 9, -51403784); | ||
c = gg(c, d, a, b, k[7], 14, 1735328473); | ||
b = gg(b, c, d, a, k[12], 20, -1926607734); | ||
a = hh(a, b, c, d, k[5], 4, -378558); | ||
d = hh(d, a, b, c, k[8], 11, -2022574463); | ||
c = hh(c, d, a, b, k[11], 16, 1839030562); | ||
b = hh(b, c, d, a, k[14], 23, -35309556); | ||
a = hh(a, b, c, d, k[1], 4, -1530992060); | ||
d = hh(d, a, b, c, k[4], 11, 1272893353); | ||
c = hh(c, d, a, b, k[7], 16, -155497632); | ||
b = hh(b, c, d, a, k[10], 23, -1094730640); | ||
a = hh(a, b, c, d, k[13], 4, 681279174); | ||
d = hh(d, a, b, c, k[0], 11, -358537222); | ||
c = hh(c, d, a, b, k[3], 16, -722521979); | ||
b = hh(b, c, d, a, k[6], 23, 76029189); | ||
a = hh(a, b, c, d, k[9], 4, -640364487); | ||
d = hh(d, a, b, c, k[12], 11, -421815835); | ||
c = hh(c, d, a, b, k[15], 16, 530742520); | ||
b = hh(b, c, d, a, k[2], 23, -995338651); | ||
a = ii(a, b, c, d, k[0], 6, -198630844); | ||
d = ii(d, a, b, c, k[7], 10, 1126891415); | ||
c = ii(c, d, a, b, k[14], 15, -1416354905); | ||
b = ii(b, c, d, a, k[5], 21, -57434055); | ||
a = ii(a, b, c, d, k[12], 6, 1700485571); | ||
d = ii(d, a, b, c, k[3], 10, -1894986606); | ||
c = ii(c, d, a, b, k[10], 15, -1051523); | ||
b = ii(b, c, d, a, k[1], 21, -2054922799); | ||
a = ii(a, b, c, d, k[8], 6, 1873313359); | ||
d = ii(d, a, b, c, k[15], 10, -30611744); | ||
c = ii(c, d, a, b, k[6], 15, -1560198380); | ||
b = ii(b, c, d, a, k[13], 21, 1309151649); | ||
a = ii(a, b, c, d, k[4], 6, -145523070); | ||
d = ii(d, a, b, c, k[11], 10, -1120210379); | ||
c = ii(c, d, a, b, k[2], 15, 718787259); | ||
b = ii(b, c, d, a, k[9], 21, -343485551); | ||
x[0] = add32(a, x[0]); | ||
x[1] = add32(b, x[1]); | ||
x[2] = add32(c, x[2]); | ||
x[3] = add32(d, x[3]); | ||
} | ||
function cmn(q, a, b, x, s, t) { | ||
a = add32(add32(a, q), add32(x, t)); | ||
return add32((a << s) | (a >>> (32 - s)), b); | ||
} | ||
function ff(a, b, c, d, x, s, t) { | ||
return cmn((b & c) | ((~b) & d), a, b, x, s, t); | ||
} | ||
function gg(a, b, c, d, x, s, t) { | ||
return cmn((b & d) | (c & (~d)), a, b, x, s, t); | ||
} | ||
function hh(a, b, c, d, x, s, t) { | ||
return cmn(b ^ c ^ d, a, b, x, s, t); | ||
} | ||
function ii(a, b, c, d, x, s, t) { | ||
return cmn(c ^ (b | (~d)), a, b, x, s, t); | ||
} | ||
function md51(s) { | ||
txt = ''; | ||
var n = s.length, | ||
state = [1732584193, -271733879, -1732584194, 271733878], | ||
i; | ||
for (i = 64; i <= s.length; i += 64) { | ||
md5cycle(state, md5blk(s.substring(i - 64, i))); | ||
} | ||
s = s.substring(i - 64); | ||
var tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
for (i = 0; i < s.length; i++) | ||
tail[i >> 2] |= s.charCodeAt(i) << ((i % 4) << 3); | ||
tail[i >> 2] |= 0x80 << ((i % 4) << 3); | ||
if (i > 55) { | ||
md5cycle(state, tail); | ||
for (i = 0; i < 16; i++) tail[i] = 0; | ||
} | ||
tail[14] = n * 8; | ||
md5cycle(state, tail); | ||
return state; | ||
} | ||
/* there needs to be support for Unicode here, | ||
* unless we pretend that we can redefine the MD-5 | ||
* algorithm for multi-byte characters (perhaps | ||
* by adding every four 16-bit characters and | ||
* shortening the sum to 32 bits). Otherwise | ||
* I suggest performing MD-5 as if every character | ||
* was two bytes--e.g., 0040 0025 = @%--but then | ||
* how will an ordinary MD-5 sum be matched? | ||
* There is no way to standardize text to something | ||
* like UTF-8 before transformation; speed cost is | ||
* utterly prohibitive. The JavaScript standard | ||
* itself needs to look at this: it should start | ||
* providing access to strings as preformed UTF-8 | ||
* 8-bit unsigned value arrays. | ||
*/ | ||
function md5blk(s) { /* I figured global was faster. */ | ||
var md5blks = [], | ||
i; /* Andy King said do it this way. */ | ||
for (i = 0; i < 64; i += 4) { | ||
md5blks[i >> 2] = s.charCodeAt(i) + (s.charCodeAt(i + 1) << 8) + (s.charCodeAt(i + 2) << 16) + (s.charCodeAt(i + 3) << 24); | ||
} | ||
return md5blks; | ||
} | ||
var hex_chr = '0123456789abcdef'.split(''); | ||
function rhex(n) { | ||
var s = '', | ||
j = 0; | ||
for (; j < 4; j++) | ||
s += hex_chr[(n >> (j * 8 + 4)) & 0x0F] + hex_chr[(n >> (j * 8)) & 0x0F]; | ||
return s; | ||
} | ||
function hex(x) { | ||
for (var i = 0; i < x.length; i++) | ||
x[i] = rhex(x[i]); | ||
return x.join(''); | ||
} | ||
return hex(md51(s)); | ||
function add32(a, b) { | ||
return (a + b) & 0xFFFFFFFF; | ||
} | ||
if (md5('hello') != '5d41402abc4b2a76b9719d911017c592') { | ||
function add32(x, y) { | ||
var lsw = (x & 0xFFFF) + (y & 0xFFFF), | ||
msw = (x >> 16) + (y >> 16) + (lsw >> 16); | ||
return (msw << 16) | (lsw & 0xFFFF); | ||
} | ||
} | ||
function md5cycle(x, k) { | ||
var a = x[0], | ||
b = x[1], | ||
c = x[2], | ||
d = x[3]; | ||
a = ff(a, b, c, d, k[0], 7, -680876936); | ||
d = ff(d, a, b, c, k[1], 12, -389564586); | ||
c = ff(c, d, a, b, k[2], 17, 606105819); | ||
b = ff(b, c, d, a, k[3], 22, -1044525330); | ||
a = ff(a, b, c, d, k[4], 7, -176418897); | ||
d = ff(d, a, b, c, k[5], 12, 1200080426); | ||
c = ff(c, d, a, b, k[6], 17, -1473231341); | ||
b = ff(b, c, d, a, k[7], 22, -45705983); | ||
a = ff(a, b, c, d, k[8], 7, 1770035416); | ||
d = ff(d, a, b, c, k[9], 12, -1958414417); | ||
c = ff(c, d, a, b, k[10], 17, -42063); | ||
b = ff(b, c, d, a, k[11], 22, -1990404162); | ||
a = ff(a, b, c, d, k[12], 7, 1804603682); | ||
d = ff(d, a, b, c, k[13], 12, -40341101); | ||
c = ff(c, d, a, b, k[14], 17, -1502002290); | ||
b = ff(b, c, d, a, k[15], 22, 1236535329); | ||
a = gg(a, b, c, d, k[1], 5, -165796510); | ||
d = gg(d, a, b, c, k[6], 9, -1069501632); | ||
c = gg(c, d, a, b, k[11], 14, 643717713); | ||
b = gg(b, c, d, a, k[0], 20, -373897302); | ||
a = gg(a, b, c, d, k[5], 5, -701558691); | ||
d = gg(d, a, b, c, k[10], 9, 38016083); | ||
c = gg(c, d, a, b, k[15], 14, -660478335); | ||
b = gg(b, c, d, a, k[4], 20, -405537848); | ||
a = gg(a, b, c, d, k[9], 5, 568446438); | ||
d = gg(d, a, b, c, k[14], 9, -1019803690); | ||
c = gg(c, d, a, b, k[3], 14, -187363961); | ||
b = gg(b, c, d, a, k[8], 20, 1163531501); | ||
a = gg(a, b, c, d, k[13], 5, -1444681467); | ||
d = gg(d, a, b, c, k[2], 9, -51403784); | ||
c = gg(c, d, a, b, k[7], 14, 1735328473); | ||
b = gg(b, c, d, a, k[12], 20, -1926607734); | ||
a = hh(a, b, c, d, k[5], 4, -378558); | ||
d = hh(d, a, b, c, k[8], 11, -2022574463); | ||
c = hh(c, d, a, b, k[11], 16, 1839030562); | ||
b = hh(b, c, d, a, k[14], 23, -35309556); | ||
a = hh(a, b, c, d, k[1], 4, -1530992060); | ||
d = hh(d, a, b, c, k[4], 11, 1272893353); | ||
c = hh(c, d, a, b, k[7], 16, -155497632); | ||
b = hh(b, c, d, a, k[10], 23, -1094730640); | ||
a = hh(a, b, c, d, k[13], 4, 681279174); | ||
d = hh(d, a, b, c, k[0], 11, -358537222); | ||
c = hh(c, d, a, b, k[3], 16, -722521979); | ||
b = hh(b, c, d, a, k[6], 23, 76029189); | ||
a = hh(a, b, c, d, k[9], 4, -640364487); | ||
d = hh(d, a, b, c, k[12], 11, -421815835); | ||
c = hh(c, d, a, b, k[15], 16, 530742520); | ||
b = hh(b, c, d, a, k[2], 23, -995338651); | ||
a = ii(a, b, c, d, k[0], 6, -198630844); | ||
d = ii(d, a, b, c, k[7], 10, 1126891415); | ||
c = ii(c, d, a, b, k[14], 15, -1416354905); | ||
b = ii(b, c, d, a, k[5], 21, -57434055); | ||
a = ii(a, b, c, d, k[12], 6, 1700485571); | ||
d = ii(d, a, b, c, k[3], 10, -1894986606); | ||
c = ii(c, d, a, b, k[10], 15, -1051523); | ||
b = ii(b, c, d, a, k[1], 21, -2054922799); | ||
a = ii(a, b, c, d, k[8], 6, 1873313359); | ||
d = ii(d, a, b, c, k[15], 10, -30611744); | ||
c = ii(c, d, a, b, k[6], 15, -1560198380); | ||
b = ii(b, c, d, a, k[13], 21, 1309151649); | ||
a = ii(a, b, c, d, k[4], 6, -145523070); | ||
d = ii(d, a, b, c, k[11], 10, -1120210379); | ||
c = ii(c, d, a, b, k[2], 15, 718787259); | ||
b = ii(b, c, d, a, k[9], 21, -343485551); | ||
x[0] = add32(a, x[0]); | ||
x[1] = add32(b, x[1]); | ||
x[2] = add32(c, x[2]); | ||
x[3] = add32(d, x[3]); | ||
} | ||
function cmn(q, a, b, x, s, t) { | ||
a = add32(add32(a, q), add32(x, t)); | ||
return add32((a << s) | (a >>> (32 - s)), b); | ||
} | ||
function ff(a, b, c, d, x, s, t) { | ||
return cmn((b & c) | ((~b) & d), a, b, x, s, t); | ||
} | ||
function gg(a, b, c, d, x, s, t) { | ||
return cmn((b & d) | (c & (~d)), a, b, x, s, t); | ||
} | ||
function hh(a, b, c, d, x, s, t) { | ||
return cmn(b ^ c ^ d, a, b, x, s, t); | ||
} | ||
function ii(a, b, c, d, x, s, t) { | ||
return cmn(c ^ (b | (~d)), a, b, x, s, t); | ||
} | ||
function md51(s) { | ||
txt = ''; | ||
var n = s.length, | ||
state = [1732584193, -271733879, -1732584194, 271733878], | ||
i; | ||
for (i = 64; i <= s.length; i += 64) { | ||
md5cycle(state, md5blk(s.substring(i - 64, i))); | ||
} | ||
s = s.substring(i - 64); | ||
var tail = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | ||
for (i = 0; i < s.length; i++) | ||
tail[i >> 2] |= s.charCodeAt(i) << ((i % 4) << 3); | ||
tail[i >> 2] |= 0x80 << ((i % 4) << 3); | ||
if (i > 55) { | ||
md5cycle(state, tail); | ||
for (i = 0; i < 16; i++) tail[i] = 0; | ||
} | ||
tail[14] = n * 8; | ||
md5cycle(state, tail); | ||
return state; | ||
} | ||
/* there needs to be support for Unicode here, | ||
* unless we pretend that we can redefine the MD-5 | ||
* algorithm for multi-byte characters (perhaps | ||
* by adding every four 16-bit characters and | ||
* shortening the sum to 32 bits). Otherwise | ||
* I suggest performing MD-5 as if every character | ||
* was two bytes--e.g., 0040 0025 = @%--but then | ||
* how will an ordinary MD-5 sum be matched? | ||
* There is no way to standardize text to something | ||
* like UTF-8 before transformation; speed cost is | ||
* utterly prohibitive. The JavaScript standard | ||
* itself needs to look at this: it should start | ||
* providing access to strings as preformed UTF-8 | ||
* 8-bit unsigned value arrays. | ||
*/ | ||
function md5blk(s) { /* I figured global was faster. */ | ||
var md5blks = [], | ||
i; /* Andy King said do it this way. */ | ||
for (i = 0; i < 64; i += 4) { | ||
md5blks[i >> 2] = s.charCodeAt(i) + (s.charCodeAt(i + 1) << 8) + (s.charCodeAt(i + 2) << 16) + (s.charCodeAt(i + 3) << 24); | ||
} | ||
return md5blks; | ||
} | ||
var hex_chr = '0123456789abcdef'.split(''); | ||
function rhex(n) { | ||
var s = '', | ||
j = 0; | ||
for (; j < 4; j++) | ||
s += hex_chr[(n >> (j * 8 + 4)) & 0x0F] + hex_chr[(n >> (j * 8)) & 0x0F]; | ||
return s; | ||
} | ||
function hex(x) { | ||
for (var i = 0; i < x.length; i++) | ||
x[i] = rhex(x[i]); | ||
return x.join(''); | ||
} | ||
return hex(md51(s)); | ||
} |
656
jymin.js
/** | ||
* _ _ ___ _ _____ | ||
* | |_ _ _ __ ___ (_)_ __ __ __/ _ \ / ||___ | | ||
* _ | | | | | '_ ` _ \| | '_ \ \ \ / / | | || | / / | ||
* | |_| | |_| | | | | | | | | | | \ V /| |_| || |_ / / | ||
* \___/ \__, |_| |_| |_|_|_| |_| \_/ \___(_)_(_)_/ | ||
* |___/ | ||
* _ _ ___ _ ___ | ||
* | |_ _ _ __ ___ (_)_ __ __ __/ _ \ / | ( _ ) | ||
* _ | | | | | '_ ` _ \| | '_ \ \ \ / / | | || | / _ \ | ||
* | |_| | |_| | | | | | | | | | | \ V /| |_| || || (_) | | ||
* \___/ \__, |_| |_| |_|_|_| |_| \_/ \___(_)_(_)___/ | ||
* |___/ | ||
* | ||
@@ -31,3 +31,3 @@ * http://lighter.io/jymin | ||
this.jymin = {version: '0.1.7'}; | ||
this.jymin = {version: '0.1.8'}; | ||
@@ -46,52 +46,52 @@ /** | ||
var getResponse = function ( | ||
url, // string*: The URL to request data from. | ||
data, // object: Data to post. The method is automagically "POST" if data is truey, otherwise "GET". | ||
onSuccess, // function: Callback to run on success. `onSuccess(response, request)`. | ||
onFailure, // function: Callback to run on failure. `onFailure(response, request)`. | ||
evalJson // boolean: Whether to evaluate the response as JSON. | ||
url, // string*: The URL to request data from. | ||
data, // object: Data to post. The method is automagically "POST" if data is truey, otherwise "GET". | ||
onSuccess, // function: Callback to run on success. `onSuccess(response, request)`. | ||
onFailure, // function: Callback to run on failure. `onFailure(response, request)`. | ||
evalJson // boolean: Whether to evaluate the response as JSON. | ||
) { | ||
// If the optional data argument is omitted, shuffle it out. | ||
if (typeof data == 'function') { | ||
evalJson = onFailure; | ||
onFailure = onSuccess; | ||
onSuccess = data; | ||
data = 0; | ||
} | ||
var request; | ||
if (window.XMLHttpRequest) { | ||
request = new XMLHttpRequest(); | ||
} else if (window.ActiveXObject) { | ||
request = new ActiveXObject('Microsoft.XMLHTTP'); | ||
} else { | ||
return false; | ||
} | ||
if (request) { | ||
request.onreadystatechange = function() { | ||
if (request.readyState == 4) { | ||
var isSuccess = (request.status == 200); | ||
var callback = isSuccess ? | ||
onSuccess || globalResponseSuccessHandler : | ||
onFailure || globalResponseFailureHandler; | ||
var response = request.responseText; | ||
if (isSuccess && evalJson) { | ||
try { | ||
// Trick Uglify into thinking there's no eval. | ||
var e = window.eval; | ||
e('eval.J=' + response); | ||
response = e.J; | ||
} | ||
catch (e) { | ||
log('ERROR: Could not parse JSON: "' + response + '"'); | ||
} | ||
} | ||
callback(response, request); | ||
} | ||
}; | ||
request.open(data ? 'POST' : 'GET', url, true); | ||
if (data) { | ||
request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | ||
} | ||
request.send(data || null); | ||
} | ||
return true; | ||
// If the optional data argument is omitted, shuffle it out. | ||
if (typeof data == 'function') { | ||
evalJson = onFailure; | ||
onFailure = onSuccess; | ||
onSuccess = data; | ||
data = 0; | ||
} | ||
var request; | ||
if (window.XMLHttpRequest) { | ||
request = new XMLHttpRequest(); | ||
} else if (window.ActiveXObject) { | ||
request = new ActiveXObject('Microsoft.XMLHTTP'); | ||
} else { | ||
return false; | ||
} | ||
if (request) { | ||
request.onreadystatechange = function() { | ||
if (request.readyState == 4) { | ||
var isSuccess = (request.status == 200); | ||
var callback = isSuccess ? | ||
onSuccess || globalResponseSuccessHandler : | ||
onFailure || globalResponseFailureHandler; | ||
var response = request.responseText; | ||
if (isSuccess && evalJson) { | ||
try { | ||
// Trick Uglify into thinking there's no eval. | ||
var e = window.eval; | ||
e('eval.J=' + response); | ||
response = e.J; | ||
} | ||
catch (e) { | ||
log('ERROR: Could not parse JSON: "' + response + '"'); | ||
} | ||
} | ||
callback(response, request); | ||
} | ||
}; | ||
request.open(data ? 'POST' : 'GET', url, true); | ||
if (data) { | ||
request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | ||
} | ||
request.send(data || null); | ||
} | ||
return true; | ||
}; | ||
@@ -104,7 +104,7 @@ | ||
var getJson = function ( | ||
url, // string*: The URL to request data from. | ||
onSuccess, // function: Callback to run on success. `onSuccess(response, request)`. | ||
onFailure // function: Callback to run on failure. `onFailure(response, request)`. | ||
url, // string*: The URL to request data from. | ||
onSuccess, // function: Callback to run on success. `onSuccess(response, request)`. | ||
onFailure // function: Callback to run on failure. `onFailure(response, request)`. | ||
) { | ||
return getResponse(url, onSuccess, onFailure, true); | ||
return getResponse(url, onSuccess, onFailure, true); | ||
}; | ||
@@ -119,8 +119,8 @@ | ||
var animate = function ( | ||
element, // string|DOMElement*: Element or ID of element to animate. | ||
styleTransitions, // object*: cssText values to animate through. | ||
onFinish, // function: Callback to execute when animation is complete. | ||
frameCount, // integer: Number of frames to animate through. (Default: 40) | ||
frameDelay, // integer: Number of milliseconds between frames. (Default: 20ms) | ||
frameIndex // integer: Index of the frame to start on. (Default: 0) | ||
element, // string|DOMElement*: Element or ID of element to animate. | ||
styleTransitions, // object*: cssText values to animate through. | ||
onFinish, // function: Callback to execute when animation is complete. | ||
frameCount, // integer: Number of frames to animate through. (Default: 40) | ||
frameDelay, // integer: Number of milliseconds between frames. (Default: 20ms) | ||
frameIndex // integer: Index of the frame to start on. (Default: 0) | ||
) { | ||
@@ -164,3 +164,3 @@ if (element = getElement(element)) { | ||
var stopAnimation = function ( | ||
element // string|DOMElement*: Element or ID of element to cancel the animation on. | ||
element // string|DOMElement*: Element or ID of element to cancel the animation on. | ||
) { | ||
@@ -176,4 +176,4 @@ if (element = getElement(element)) { | ||
var forEach = function ( | ||
array, // Array*: The array to iterate over. | ||
callback // function*: The function to call on each item. `callback(item, index, array)` | ||
array, // Array*: The array to iterate over. | ||
callback // function*: The function to call on each item. `callback(item, index, array)` | ||
) { | ||
@@ -194,4 +194,4 @@ if (array) { | ||
var forIn = function ( | ||
object, // object*: The object to iterate over. | ||
callback // function*: The function to call on each pair. `callback(value, key, object)` | ||
object, // object*: The object to iterate over. | ||
callback // function*: The function to call on each pair. `callback(value, key, object)` | ||
) { | ||
@@ -212,9 +212,9 @@ if (object) { | ||
var decorateObject = function ( | ||
object, // object*: The object to decorate. | ||
decorations // object*: The object to iterate over. | ||
object, // object*: The object to decorate. | ||
decorations // object*: The object to iterate over. | ||
) { | ||
if (object && decorations) { | ||
forIn(decorations, function (value, key) { | ||
object[key] = value; | ||
}); | ||
forIn(decorations, function (value, key) { | ||
object[key] = value; | ||
}); | ||
} | ||
@@ -229,13 +229,13 @@ return object; | ||
var getAllCookies = function () { | ||
var str = document.cookie; | ||
var decode = decodeURIComponent; | ||
var obj = {}; | ||
var pairs = str.split(/ *; */); | ||
var pair; | ||
if ('' == pairs[0]) return obj; | ||
for (var i = 0; i < pairs.length; ++i) { | ||
pair = pairs[i].split('='); | ||
obj[decode(pair[0])] = decode(pair[1]); | ||
} | ||
return obj; | ||
var str = document.cookie; | ||
var decode = decodeURIComponent; | ||
var obj = {}; | ||
var pairs = str.split(/ *; */); | ||
var pair; | ||
if ('' == pairs[0]) return obj; | ||
for (var i = 0; i < pairs.length; ++i) { | ||
pair = pairs[i].split('='); | ||
obj[decode(pair[0])] = decode(pair[1]); | ||
} | ||
return obj; | ||
}; | ||
@@ -248,5 +248,5 @@ | ||
var getCookie = function ( | ||
name // string*: Name of the cookie. | ||
name // string*: Name of the cookie. | ||
) { | ||
return getAllCookies()[name]; | ||
return getAllCookies()[name]; | ||
}; | ||
@@ -258,20 +258,20 @@ | ||
var setCookie = function ( | ||
name, // string*: Name of the cookie. | ||
value, // string*: Value to set. | ||
options // object: Name/value pairs for options including "maxage", "expires", "path", "domain" and "secure". | ||
name, // string*: Name of the cookie. | ||
value, // string*: Value to set. | ||
options // object: Name/value pairs for options including "maxage", "expires", "path", "domain" and "secure". | ||
) { | ||
options = options || {}; | ||
var encode = encodeURIComponent; | ||
var str = encode(name) + '=' + encode(value); | ||
if (null == value) { | ||
options.maxage = -1; | ||
} | ||
if (options.maxage) { | ||
options.expires = new Date(+new Date + options.maxage); | ||
} | ||
if (options.path) str += ';path=' + options.path; | ||
if (options.domain) str += ';domain=' + options.domain; | ||
if (options.expires) str += ';expires=' + options.expires.toUTCString(); | ||
if (options.secure) str += ';secure'; | ||
document.cookie = str; | ||
options = options || {}; | ||
var encode = encodeURIComponent; | ||
var str = encode(name) + '=' + encode(value); | ||
if (null == value) { | ||
options.maxage = -1; | ||
} | ||
if (options.maxage) { | ||
options.expires = new Date(+new Date + options.maxage); | ||
} | ||
if (options.path) str += ';path=' + options.path; | ||
if (options.domain) str += ';domain=' + options.domain; | ||
if (options.expires) str += ';expires=' + options.expires.toUTCString(); | ||
if (options.secure) str += ';secure'; | ||
document.cookie = str; | ||
}; | ||
@@ -283,5 +283,5 @@ | ||
var deleteCookie = function deleteCookie( | ||
name // string*: Name of the cookie. | ||
name // string*: Name of the cookie. | ||
) { | ||
setCookie(name, null); | ||
setCookie(name, null); | ||
}; | ||
@@ -294,6 +294,6 @@ | ||
var getTime = function ( | ||
date // Date: Date object. (Default: now) | ||
date // Date: Date object. (Default: now) | ||
) { | ||
date = date || new Date(); | ||
return date.getTime(); | ||
date = date || new Date(); | ||
return date.getTime(); | ||
}; | ||
@@ -735,51 +735,51 @@ | ||
var bind = function ( | ||
element, // DOMElement|string*: Element or ID of element to bind to. | ||
eventName, // string*: Name of event (e.g. "click", "mouseover", "keyup"). | ||
eventHandler, // function*: Function to run when the event is triggered. `eventHandler(element, event, target, customData)` | ||
customData, // object: Custom data to pass through to the event handler when it's triggered. | ||
multiBindCustomData | ||
element, // DOMElement|string*: Element or ID of element to bind to. | ||
eventName, // string*: Name of event (e.g. "click", "mouseover", "keyup"). | ||
eventHandler, // function*: Function to run when the event is triggered. `eventHandler(element, event, target, customData)` | ||
customData, // object: Custom data to pass through to the event handler when it's triggered. | ||
multiBindCustomData | ||
) { | ||
// Allow multiple events to be bound at once using a space-delimited string. | ||
if (containsString(eventName, ' ')) { | ||
forEach(eventName.split(' '), function (singleEventName) { | ||
bind(element, singleEventName, eventHandler, customData, multiBindCustomData); | ||
}); | ||
return; | ||
} | ||
// Allow multiple events to be bound at once using a space-delimited string. | ||
if (containsString(eventName, ' ')) { | ||
forEach(eventName.split(' '), function (singleEventName) { | ||
bind(element, singleEventName, eventHandler, customData, multiBindCustomData); | ||
}); | ||
return; | ||
} | ||
// Ensure that we have an element, not just an ID. | ||
if (element = getElement(element)) { | ||
// Ensure that we have an element, not just an ID. | ||
if (element = getElement(element)) { | ||
// Invoke the event handler with the event information and the target element. | ||
var callback = function(event) { | ||
// Fall back to window.event for IE. | ||
event = event || window.event; | ||
// Fall back to srcElement for IE. | ||
var target = event.target || event.srcElement; | ||
// Defeat Safari text node bug. | ||
if (target.nodeType == 3) { | ||
target = getParent(target); | ||
} | ||
var relatedTarget = event.relatedTarget || event.toElement; | ||
if (eventName == 'mouseout') { | ||
while (relatedTarget = getParent(relatedTarget)) { | ||
if (relatedTarget == target) { | ||
return; | ||
} | ||
} | ||
} | ||
return eventHandler(element, event, target, multiBindCustomData || customData); | ||
}; | ||
// Invoke the event handler with the event information and the target element. | ||
var callback = function(event) { | ||
// Fall back to window.event for IE. | ||
event = event || window.event; | ||
// Fall back to srcElement for IE. | ||
var target = event.target || event.srcElement; | ||
// Defeat Safari text node bug. | ||
if (target.nodeType == 3) { | ||
target = getParent(target); | ||
} | ||
var relatedTarget = event.relatedTarget || event.toElement; | ||
if (eventName == 'mouseout') { | ||
while (relatedTarget = getParent(relatedTarget)) { | ||
if (relatedTarget == target) { | ||
return; | ||
} | ||
} | ||
} | ||
return eventHandler(element, event, target, multiBindCustomData || customData); | ||
}; | ||
// Bind using whatever method we can use. | ||
if (element.addEventListener) { | ||
element.addEventListener(eventName, callback, true); | ||
} | ||
else if (element.attachEvent) { | ||
element.attachEvent('on' + eventName, callback); | ||
} | ||
else { | ||
element['on' + eventName] = callback; | ||
} | ||
} | ||
// Bind using whatever method we can use. | ||
if (element.addEventListener) { | ||
element.addEventListener(eventName, callback, true); | ||
} | ||
else if (element.attachEvent) { | ||
element.attachEvent('on' + eventName, callback); | ||
} | ||
else { | ||
element['on' + eventName] = callback; | ||
} | ||
} | ||
}; | ||
@@ -791,8 +791,8 @@ | ||
var stopEvent = function ( | ||
event // object*: Event to be canceled. | ||
event // object*: Event to be canceled. | ||
) { | ||
event.cancelBubble = true; | ||
if (event.stopPropagation) { | ||
event.stopPropagation(); | ||
} | ||
event.cancelBubble = true; | ||
if (event.stopPropagation) { | ||
event.stopPropagation(); | ||
} | ||
}; | ||
@@ -804,8 +804,8 @@ | ||
var bindFocusChange = function ( | ||
element, // DOMElement|string* | ||
eventHandler, | ||
customData | ||
element, // DOMElement|string* | ||
eventHandler, | ||
customData | ||
) { | ||
bind(element, 'focus', eventHandler, true, customData); | ||
bind(element, 'blur', eventHandler, false, customData); | ||
bind(element, 'focus', eventHandler, true, customData); | ||
bind(element, 'blur', eventHandler, false, customData); | ||
}; | ||
@@ -817,11 +817,11 @@ | ||
var bindHover = function ( | ||
element, | ||
eventHandler, | ||
customData | ||
element, | ||
eventHandler, | ||
customData | ||
) { | ||
var ieVersion = getBrowserVersionOrZero('msie'); | ||
var HOVER_OVER = 'mouse' + (ieVersion ? 'enter' : 'over'); | ||
var HOVER_OUT = 'mouse' + (ieVersion ? 'leave' : 'out'); | ||
bind(element, HOVER_OVER, eventHandler, true, customData); | ||
bind(element, HOVER_OUT, eventHandler, false, customData); | ||
var ieVersion = getBrowserVersionOrZero('msie'); | ||
var HOVER_OVER = 'mouse' + (ieVersion ? 'enter' : 'over'); | ||
var HOVER_OUT = 'mouse' + (ieVersion ? 'leave' : 'out'); | ||
bind(element, HOVER_OVER, eventHandler, true, customData); | ||
bind(element, HOVER_OUT, eventHandler, false, customData); | ||
}; | ||
@@ -861,9 +861,9 @@ | ||
var onHover = function ( | ||
element, | ||
tagAndClass, | ||
eventHandler, | ||
customData | ||
element, | ||
tagAndClass, | ||
eventHandler, | ||
customData | ||
) { | ||
on(element, tagAndClass, 'mouseover', eventHandler, true, customData); | ||
on(element, tagAndClass, 'mouseout', eventHandler, false, customData); | ||
on(element, tagAndClass, 'mouseover', eventHandler, true, customData); | ||
on(element, tagAndClass, 'mouseout', eventHandler, false, customData); | ||
}; | ||
@@ -875,7 +875,7 @@ | ||
var bindClick = function ( | ||
element, | ||
eventHandler, | ||
customData | ||
element, | ||
eventHandler, | ||
customData | ||
) { | ||
bind(element, 'click', eventHandler, customData); | ||
bind(element, 'click', eventHandler, customData); | ||
}; | ||
@@ -887,15 +887,15 @@ | ||
var bindWindowLoad = function ( | ||
callback, | ||
windowObject | ||
callback, | ||
windowObject | ||
) { | ||
// Default to the run after the window we're in. | ||
windowObject = windowObject || window; | ||
// If the window is already loaded, run the callback now. | ||
if (isLoaded(windowObject.document)) { | ||
callback(); | ||
} | ||
// Otherwise, defer the callback. | ||
else { | ||
bind(windowObject, 'load', callback); | ||
} | ||
// Default to the run after the window we're in. | ||
windowObject = windowObject || window; | ||
// If the window is already loaded, run the callback now. | ||
if (isLoaded(windowObject.document)) { | ||
callback(); | ||
} | ||
// Otherwise, defer the callback. | ||
else { | ||
bind(windowObject, 'load', callback); | ||
} | ||
}; | ||
@@ -908,9 +908,9 @@ | ||
var isLoaded = function ( | ||
object | ||
object | ||
) { | ||
var state = object.readyState; | ||
// In all browsers, documents will reach readyState=="complete". | ||
// In IE, scripts can reach readyState=="loaded" or readyState=="complete". | ||
// In non-IE browsers, we can bind to script.onload instead of checking script.readyState. | ||
return state == 'complete' || (object.tagName == 'script' && state == 'loaded'); | ||
var state = object.readyState; | ||
// In all browsers, documents will reach readyState=="complete". | ||
// In IE, scripts can reach readyState=="loaded" or readyState=="complete". | ||
// In non-IE browsers, we can bind to script.onload instead of checking script.readyState. | ||
return state == 'complete' || (object.tagName == 'script' && state == 'loaded'); | ||
}; | ||
@@ -922,8 +922,17 @@ | ||
var focusElement = function ( | ||
element | ||
element, | ||
delay | ||
) { | ||
element = getElement(element); | ||
if (element) { | ||
element.focus(); | ||
} | ||
var focus = function () { | ||
element = getElement(element); | ||
if (element) { | ||
element.focus(); | ||
} | ||
}; | ||
if (typeof delay == 'undefined') { | ||
focus(); | ||
} | ||
else { | ||
setTimeout(focus, delay); | ||
} | ||
}; | ||
@@ -935,68 +944,96 @@ | ||
var doOnce = function ( | ||
method, | ||
args, | ||
delay | ||
method, | ||
args, | ||
delay | ||
) { | ||
clearTimeout(method.t); | ||
method.t = setTimeout(function () { | ||
clearTimeout(method.t); | ||
method.call(args); | ||
}, delay || 9); | ||
clearTimeout(method.t); | ||
method.t = setTimeout(function () { | ||
clearTimeout(method.t); | ||
method.call(args); | ||
}, delay || 9); | ||
}; | ||
/** | ||
* Set or reset a timeout, and save it for possible cancellation. | ||
*/ | ||
var addTimeout = function ( | ||
elementOrString, | ||
callback, | ||
delay | ||
) { | ||
var isString = (typeof elementOrString == 'string'); | ||
var object = isString ? addTimeout : elementOrString; | ||
var key = isString ? elementOrString : 'T'; | ||
clearTimeout(object[key]); | ||
if (callback) { | ||
if (typeof delay == 'undefined') { | ||
delay = 9; | ||
} | ||
object[key] = setTimeout(callback, delay); | ||
} | ||
}; | ||
/** | ||
* Remove a timeout from an element or from the addTimeout method. | ||
*/ | ||
var removeTimeout = function ( | ||
elementOrString | ||
) { | ||
addTimeout(elementOrString, false); | ||
}; | ||
/** | ||
* Get or set the value of a form element. | ||
*/ | ||
var valueOf = function ( | ||
input, | ||
value | ||
input, | ||
value | ||
) { | ||
input = getElement(input); | ||
var type = input.type; | ||
var isCheckbox = type == 'checkbox'; | ||
var isRadio = type == 'radio'; | ||
var isSelect = /select/.test(type); | ||
// TODO: Make this work for select boxes and other stuff too. | ||
if (typeof value == 'undefined') { | ||
value = input.value; | ||
if (isCheckbox) { | ||
return input.checked ? value : null; | ||
} | ||
else if (isSelect) { | ||
return input.options[input.selectedIndex].value; | ||
} | ||
} | ||
else { | ||
if (isCheckbox) { | ||
input.checked = value ? true : false; | ||
} | ||
else if (isSelect) { | ||
forEach(input.options, function (option, index) { | ||
if (option.value == value) { | ||
input.selectedIndex = index; | ||
} | ||
}); | ||
} | ||
else { | ||
input.value = value; | ||
} | ||
} | ||
return input.value; | ||
input = getElement(input); | ||
var type = input.type; | ||
var isCheckbox = type == 'checkbox'; | ||
var isRadio = type == 'radio'; | ||
var isSelect = /select/.test(type); | ||
if (typeof value == 'undefined') { | ||
value = input.value; | ||
if (isCheckbox) { | ||
return input.checked ? value : null; | ||
} | ||
else if (isSelect) { | ||
return input.options[input.selectedIndex].value; | ||
} | ||
} | ||
else { | ||
if (isCheckbox) { | ||
input.checked = value ? true : false; | ||
} | ||
else if (isSelect) { | ||
forEach(input.options, function (option, index) { | ||
if (option.value == value) { | ||
input.selectedIndex = index; | ||
} | ||
}); | ||
} | ||
else { | ||
input.value = value; | ||
} | ||
} | ||
return input.value; | ||
}; | ||
/** | ||
* Return a history object. | ||
* Return a history object. | ||
*/ | ||
var getHistory = function () { | ||
var history = window.history || {}; | ||
forEach(['push', 'replace'], function (key) { | ||
var fn = history[key + 'State']; | ||
history[key] = function (href) { | ||
if (fn) { | ||
fn.apply(history, [null, null, href]); | ||
} else { | ||
// TODO: Create a backward compatible history push. | ||
} | ||
}; | ||
}); | ||
return history; | ||
var history = window.history || {}; | ||
forEach(['push', 'replace'], function (key) { | ||
var fn = history[key + 'State']; | ||
history[key] = function (href) { | ||
if (fn) { | ||
fn.apply(history, [null, null, href]); | ||
} else { | ||
// TODO: Create a backward compatible history push. | ||
} | ||
}; | ||
}); | ||
return history; | ||
}; | ||
@@ -1008,5 +1045,5 @@ | ||
var pushHistory = function ( | ||
href | ||
href | ||
) { | ||
getHistory().push(href); | ||
getHistory().push(href); | ||
}; | ||
@@ -1018,5 +1055,5 @@ | ||
var replaceHistory = function ( | ||
href | ||
href | ||
) { | ||
getHistory().replace(href); | ||
getHistory().replace(href); | ||
}; | ||
@@ -1028,5 +1065,5 @@ | ||
var popHistory = function ( | ||
href | ||
href | ||
) { | ||
getHistory().back(); | ||
getHistory().back(); | ||
}; | ||
@@ -1038,4 +1075,4 @@ | ||
var log = function ( | ||
message, | ||
object | ||
message, | ||
object | ||
) { | ||
@@ -1052,14 +1089,13 @@ if (window.console && console.log) { | ||
}; | ||
/** | ||
* If the argument is numeric, return a number, otherwise return zero. | ||
* If the argument is numeric, return a number, otherwise return zero. | ||
* @param {Object} n | ||
*/ | ||
var forceNumber = function ( | ||
number, | ||
defaultNumber | ||
number, | ||
defaultNumber | ||
) { | ||
defaultNumber = defaultNumber || 0; | ||
number *= 1; | ||
return isNaN(number) ? defaultNumber : number; | ||
defaultNumber = defaultNumber || 0; | ||
number *= 1; | ||
return isNaN(number) ? defaultNumber : number; | ||
}; | ||
@@ -1071,3 +1107,3 @@ | ||
var isString = function ( | ||
object | ||
object | ||
) { | ||
@@ -1081,4 +1117,4 @@ return typeof object == 'string'; | ||
var containsString = function ( | ||
string, | ||
substring | ||
string, | ||
substring | ||
) { | ||
@@ -1092,5 +1128,5 @@ return ('' + string).indexOf(substring) > -1; | ||
var trimString = function ( | ||
string | ||
string | ||
) { | ||
return ('' + string).replace(/^\s+|\s+$/g, ''); | ||
return ('' + string).replace(/^\s+|\s+$/g, ''); | ||
}; | ||
@@ -1102,4 +1138,4 @@ | ||
var decorateString = function ( | ||
string, | ||
replacements | ||
string, | ||
replacements | ||
) { | ||
@@ -1117,3 +1153,3 @@ string = '' + string; | ||
var extractLetters = function ( | ||
string | ||
string | ||
) { | ||
@@ -1127,3 +1163,3 @@ return ('' + string).replace(/[^a-z]/ig, ''); | ||
var extractNumbers = function ( | ||
string | ||
string | ||
) { | ||
@@ -1137,9 +1173,9 @@ return ('' + string).replace(/[^0-9]/g, ''); | ||
var buildQueryString = function ( | ||
object | ||
object | ||
) { | ||
var queryParams = []; | ||
forIn(object, function(value, key) { | ||
queryParams.push(escape(key) + '=' + escape(value)); | ||
}); | ||
return queryParams.join('&'); | ||
var queryParams = []; | ||
forIn(object, function(value, key) { | ||
queryParams.push(escape(key) + '=' + escape(value)); | ||
}); | ||
return queryParams.join('&'); | ||
}; | ||
@@ -1151,3 +1187,3 @@ | ||
var getBrowserVersionOrZero = function ( | ||
browserName | ||
browserName | ||
) { | ||
@@ -1162,3 +1198,3 @@ var match = new RegExp(browserName + '[ /](\\d+(\\.\\d+)?)', 'i').exec(navigator.userAgent); | ||
var getHost = function () { | ||
return location.host; | ||
return location.host; | ||
}; | ||
@@ -1170,3 +1206,3 @@ | ||
var getBaseUrl = function () { | ||
return location.protocol + '//' + getHost(); | ||
return location.protocol + '//' + getHost(); | ||
}; | ||
@@ -1178,15 +1214,15 @@ | ||
var getQueryParams = function ( | ||
url | ||
url | ||
) { | ||
url = url || location.href; | ||
var query = url.substr(url.indexOf('?') + 1).split('#')[0]; | ||
var pairs = query.split('&'); | ||
query = {}; | ||
forEach(pairs, function (pair) { | ||
var eqPos = pair.indexOf('='); | ||
var name = pair.substr(0, eqPos); | ||
var value = pair.substr(eqPos + 1); | ||
query[name] = value; | ||
}); | ||
return query; | ||
url = url || location.href; | ||
var query = url.substr(url.indexOf('?') + 1).split('#')[0]; | ||
var pairs = query.split('&'); | ||
query = {}; | ||
forEach(pairs, function (pair) { | ||
var eqPos = pair.indexOf('='); | ||
var name = pair.substr(0, eqPos); | ||
var value = pair.substr(eqPos + 1); | ||
query[name] = value; | ||
}); | ||
return query; | ||
}; | ||
@@ -1198,7 +1234,7 @@ | ||
var getHashParams = function ( | ||
hash | ||
hash | ||
) { | ||
hash = (hash || location.hash).replace(/^#/, ''); | ||
return hash ? getQueryParams(hash) : {}; | ||
hash = (hash || location.hash).replace(/^#/, ''); | ||
return hash ? getQueryParams(hash) : {}; | ||
}; | ||
@@ -15,3 +15,3 @@ { | ||
], | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"main": "chug/chug.js", | ||
@@ -18,0 +18,0 @@ "homepage": "http://lighter.io/jymin", |
@@ -13,52 +13,52 @@ /** | ||
var getResponse = function ( | ||
url, // string*: The URL to request data from. | ||
data, // object: Data to post. The method is automagically "POST" if data is truey, otherwise "GET". | ||
onSuccess, // function: Callback to run on success. `onSuccess(response, request)`. | ||
onFailure, // function: Callback to run on failure. `onFailure(response, request)`. | ||
evalJson // boolean: Whether to evaluate the response as JSON. | ||
url, // string*: The URL to request data from. | ||
data, // object: Data to post. The method is automagically "POST" if data is truey, otherwise "GET". | ||
onSuccess, // function: Callback to run on success. `onSuccess(response, request)`. | ||
onFailure, // function: Callback to run on failure. `onFailure(response, request)`. | ||
evalJson // boolean: Whether to evaluate the response as JSON. | ||
) { | ||
// If the optional data argument is omitted, shuffle it out. | ||
if (typeof data == 'function') { | ||
evalJson = onFailure; | ||
onFailure = onSuccess; | ||
onSuccess = data; | ||
data = 0; | ||
} | ||
var request; | ||
if (window.XMLHttpRequest) { | ||
request = new XMLHttpRequest(); | ||
} else if (window.ActiveXObject) { | ||
request = new ActiveXObject('Microsoft.XMLHTTP'); | ||
} else { | ||
return false; | ||
} | ||
if (request) { | ||
request.onreadystatechange = function() { | ||
if (request.readyState == 4) { | ||
var isSuccess = (request.status == 200); | ||
var callback = isSuccess ? | ||
onSuccess || globalResponseSuccessHandler : | ||
onFailure || globalResponseFailureHandler; | ||
var response = request.responseText; | ||
if (isSuccess && evalJson) { | ||
try { | ||
// Trick Uglify into thinking there's no eval. | ||
var e = window.eval; | ||
e('eval.J=' + response); | ||
response = e.J; | ||
} | ||
catch (e) { | ||
log('ERROR: Could not parse JSON: "' + response + '"'); | ||
} | ||
} | ||
callback(response, request); | ||
} | ||
}; | ||
request.open(data ? 'POST' : 'GET', url, true); | ||
if (data) { | ||
request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | ||
} | ||
request.send(data || null); | ||
} | ||
return true; | ||
// If the optional data argument is omitted, shuffle it out. | ||
if (typeof data == 'function') { | ||
evalJson = onFailure; | ||
onFailure = onSuccess; | ||
onSuccess = data; | ||
data = 0; | ||
} | ||
var request; | ||
if (window.XMLHttpRequest) { | ||
request = new XMLHttpRequest(); | ||
} else if (window.ActiveXObject) { | ||
request = new ActiveXObject('Microsoft.XMLHTTP'); | ||
} else { | ||
return false; | ||
} | ||
if (request) { | ||
request.onreadystatechange = function() { | ||
if (request.readyState == 4) { | ||
var isSuccess = (request.status == 200); | ||
var callback = isSuccess ? | ||
onSuccess || globalResponseSuccessHandler : | ||
onFailure || globalResponseFailureHandler; | ||
var response = request.responseText; | ||
if (isSuccess && evalJson) { | ||
try { | ||
// Trick Uglify into thinking there's no eval. | ||
var e = window.eval; | ||
e('eval.J=' + response); | ||
response = e.J; | ||
} | ||
catch (e) { | ||
log('ERROR: Could not parse JSON: "' + response + '"'); | ||
} | ||
} | ||
callback(response, request); | ||
} | ||
}; | ||
request.open(data ? 'POST' : 'GET', url, true); | ||
if (data) { | ||
request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | ||
} | ||
request.send(data || null); | ||
} | ||
return true; | ||
}; | ||
@@ -71,8 +71,8 @@ | ||
var getJson = function ( | ||
url, // string*: The URL to request data from. | ||
onSuccess, // function: Callback to run on success. `onSuccess(response, request)`. | ||
onFailure // function: Callback to run on failure. `onFailure(response, request)`. | ||
url, // string*: The URL to request data from. | ||
onSuccess, // function: Callback to run on success. `onSuccess(response, request)`. | ||
onFailure // function: Callback to run on failure. `onFailure(response, request)`. | ||
) { | ||
return getResponse(url, onSuccess, onFailure, true); | ||
return getResponse(url, onSuccess, onFailure, true); | ||
}; | ||
@@ -8,8 +8,8 @@ var DEFAULT_ANIMATION_FRAME_COUNT = 40; | ||
var animate = function ( | ||
element, // string|DOMElement*: Element or ID of element to animate. | ||
styleTransitions, // object*: cssText values to animate through. | ||
onFinish, // function: Callback to execute when animation is complete. | ||
frameCount, // integer: Number of frames to animate through. (Default: 40) | ||
frameDelay, // integer: Number of milliseconds between frames. (Default: 20ms) | ||
frameIndex // integer: Index of the frame to start on. (Default: 0) | ||
element, // string|DOMElement*: Element or ID of element to animate. | ||
styleTransitions, // object*: cssText values to animate through. | ||
onFinish, // function: Callback to execute when animation is complete. | ||
frameCount, // integer: Number of frames to animate through. (Default: 40) | ||
frameDelay, // integer: Number of milliseconds between frames. (Default: 20ms) | ||
frameIndex // integer: Index of the frame to start on. (Default: 0) | ||
) { | ||
@@ -53,3 +53,3 @@ if (element = getElement(element)) { | ||
var stopAnimation = function ( | ||
element // string|DOMElement*: Element or ID of element to cancel the animation on. | ||
element // string|DOMElement*: Element or ID of element to cancel the animation on. | ||
) { | ||
@@ -56,0 +56,0 @@ if (element = getElement(element)) { |
@@ -5,4 +5,4 @@ /** | ||
var forEach = function ( | ||
array, // Array*: The array to iterate over. | ||
callback // function*: The function to call on each item. `callback(item, index, array)` | ||
array, // Array*: The array to iterate over. | ||
callback // function*: The function to call on each item. `callback(item, index, array)` | ||
) { | ||
@@ -23,4 +23,4 @@ if (array) { | ||
var forIn = function ( | ||
object, // object*: The object to iterate over. | ||
callback // function*: The function to call on each pair. `callback(value, key, object)` | ||
object, // object*: The object to iterate over. | ||
callback // function*: The function to call on each pair. `callback(value, key, object)` | ||
) { | ||
@@ -41,9 +41,9 @@ if (object) { | ||
var decorateObject = function ( | ||
object, // object*: The object to decorate. | ||
decorations // object*: The object to iterate over. | ||
object, // object*: The object to decorate. | ||
decorations // object*: The object to iterate over. | ||
) { | ||
if (object && decorations) { | ||
forIn(decorations, function (value, key) { | ||
object[key] = value; | ||
}); | ||
forIn(decorations, function (value, key) { | ||
object[key] = value; | ||
}); | ||
} | ||
@@ -50,0 +50,0 @@ return object; |
@@ -6,13 +6,13 @@ /** | ||
var getAllCookies = function () { | ||
var str = document.cookie; | ||
var decode = decodeURIComponent; | ||
var obj = {}; | ||
var pairs = str.split(/ *; */); | ||
var pair; | ||
if ('' == pairs[0]) return obj; | ||
for (var i = 0; i < pairs.length; ++i) { | ||
pair = pairs[i].split('='); | ||
obj[decode(pair[0])] = decode(pair[1]); | ||
} | ||
return obj; | ||
var str = document.cookie; | ||
var decode = decodeURIComponent; | ||
var obj = {}; | ||
var pairs = str.split(/ *; */); | ||
var pair; | ||
if ('' == pairs[0]) return obj; | ||
for (var i = 0; i < pairs.length; ++i) { | ||
pair = pairs[i].split('='); | ||
obj[decode(pair[0])] = decode(pair[1]); | ||
} | ||
return obj; | ||
}; | ||
@@ -25,5 +25,5 @@ | ||
var getCookie = function ( | ||
name // string*: Name of the cookie. | ||
name // string*: Name of the cookie. | ||
) { | ||
return getAllCookies()[name]; | ||
return getAllCookies()[name]; | ||
}; | ||
@@ -35,20 +35,20 @@ | ||
var setCookie = function ( | ||
name, // string*: Name of the cookie. | ||
value, // string*: Value to set. | ||
options // object: Name/value pairs for options including "maxage", "expires", "path", "domain" and "secure". | ||
name, // string*: Name of the cookie. | ||
value, // string*: Value to set. | ||
options // object: Name/value pairs for options including "maxage", "expires", "path", "domain" and "secure". | ||
) { | ||
options = options || {}; | ||
var encode = encodeURIComponent; | ||
var str = encode(name) + '=' + encode(value); | ||
if (null == value) { | ||
options.maxage = -1; | ||
} | ||
if (options.maxage) { | ||
options.expires = new Date(+new Date + options.maxage); | ||
} | ||
if (options.path) str += ';path=' + options.path; | ||
if (options.domain) str += ';domain=' + options.domain; | ||
if (options.expires) str += ';expires=' + options.expires.toUTCString(); | ||
if (options.secure) str += ';secure'; | ||
document.cookie = str; | ||
options = options || {}; | ||
var encode = encodeURIComponent; | ||
var str = encode(name) + '=' + encode(value); | ||
if (null == value) { | ||
options.maxage = -1; | ||
} | ||
if (options.maxage) { | ||
options.expires = new Date(+new Date + options.maxage); | ||
} | ||
if (options.path) str += ';path=' + options.path; | ||
if (options.domain) str += ';domain=' + options.domain; | ||
if (options.expires) str += ';expires=' + options.expires.toUTCString(); | ||
if (options.secure) str += ';secure'; | ||
document.cookie = str; | ||
}; | ||
@@ -60,6 +60,6 @@ | ||
var deleteCookie = function deleteCookie( | ||
name // string*: Name of the cookie. | ||
name // string*: Name of the cookie. | ||
) { | ||
setCookie(name, null); | ||
setCookie(name, null); | ||
}; | ||
@@ -6,7 +6,7 @@ /** | ||
var getTime = function ( | ||
date // Date: Date object. (Default: now) | ||
date // Date: Date object. (Default: now) | ||
) { | ||
date = date || new Date(); | ||
return date.getTime(); | ||
date = date || new Date(); | ||
return date.getTime(); | ||
}; | ||
@@ -0,0 +0,0 @@ /** |
@@ -5,51 +5,51 @@ /** | ||
var bind = function ( | ||
element, // DOMElement|string*: Element or ID of element to bind to. | ||
eventName, // string*: Name of event (e.g. "click", "mouseover", "keyup"). | ||
eventHandler, // function*: Function to run when the event is triggered. `eventHandler(element, event, target, customData)` | ||
customData, // object: Custom data to pass through to the event handler when it's triggered. | ||
multiBindCustomData | ||
element, // DOMElement|string*: Element or ID of element to bind to. | ||
eventName, // string*: Name of event (e.g. "click", "mouseover", "keyup"). | ||
eventHandler, // function*: Function to run when the event is triggered. `eventHandler(element, event, target, customData)` | ||
customData, // object: Custom data to pass through to the event handler when it's triggered. | ||
multiBindCustomData | ||
) { | ||
// Allow multiple events to be bound at once using a space-delimited string. | ||
if (containsString(eventName, ' ')) { | ||
forEach(eventName.split(' '), function (singleEventName) { | ||
bind(element, singleEventName, eventHandler, customData, multiBindCustomData); | ||
}); | ||
return; | ||
} | ||
// Allow multiple events to be bound at once using a space-delimited string. | ||
if (containsString(eventName, ' ')) { | ||
forEach(eventName.split(' '), function (singleEventName) { | ||
bind(element, singleEventName, eventHandler, customData, multiBindCustomData); | ||
}); | ||
return; | ||
} | ||
// Ensure that we have an element, not just an ID. | ||
if (element = getElement(element)) { | ||
// Ensure that we have an element, not just an ID. | ||
if (element = getElement(element)) { | ||
// Invoke the event handler with the event information and the target element. | ||
var callback = function(event) { | ||
// Fall back to window.event for IE. | ||
event = event || window.event; | ||
// Fall back to srcElement for IE. | ||
var target = event.target || event.srcElement; | ||
// Defeat Safari text node bug. | ||
if (target.nodeType == 3) { | ||
target = getParent(target); | ||
} | ||
var relatedTarget = event.relatedTarget || event.toElement; | ||
if (eventName == 'mouseout') { | ||
while (relatedTarget = getParent(relatedTarget)) { | ||
if (relatedTarget == target) { | ||
return; | ||
} | ||
} | ||
} | ||
return eventHandler(element, event, target, multiBindCustomData || customData); | ||
}; | ||
// Invoke the event handler with the event information and the target element. | ||
var callback = function(event) { | ||
// Fall back to window.event for IE. | ||
event = event || window.event; | ||
// Fall back to srcElement for IE. | ||
var target = event.target || event.srcElement; | ||
// Defeat Safari text node bug. | ||
if (target.nodeType == 3) { | ||
target = getParent(target); | ||
} | ||
var relatedTarget = event.relatedTarget || event.toElement; | ||
if (eventName == 'mouseout') { | ||
while (relatedTarget = getParent(relatedTarget)) { | ||
if (relatedTarget == target) { | ||
return; | ||
} | ||
} | ||
} | ||
return eventHandler(element, event, target, multiBindCustomData || customData); | ||
}; | ||
// Bind using whatever method we can use. | ||
if (element.addEventListener) { | ||
element.addEventListener(eventName, callback, true); | ||
} | ||
else if (element.attachEvent) { | ||
element.attachEvent('on' + eventName, callback); | ||
} | ||
else { | ||
element['on' + eventName] = callback; | ||
} | ||
} | ||
// Bind using whatever method we can use. | ||
if (element.addEventListener) { | ||
element.addEventListener(eventName, callback, true); | ||
} | ||
else if (element.attachEvent) { | ||
element.attachEvent('on' + eventName, callback); | ||
} | ||
else { | ||
element['on' + eventName] = callback; | ||
} | ||
} | ||
}; | ||
@@ -61,8 +61,8 @@ | ||
var stopEvent = function ( | ||
event // object*: Event to be canceled. | ||
event // object*: Event to be canceled. | ||
) { | ||
event.cancelBubble = true; | ||
if (event.stopPropagation) { | ||
event.stopPropagation(); | ||
} | ||
event.cancelBubble = true; | ||
if (event.stopPropagation) { | ||
event.stopPropagation(); | ||
} | ||
}; | ||
@@ -74,8 +74,8 @@ | ||
var bindFocusChange = function ( | ||
element, // DOMElement|string* | ||
eventHandler, | ||
customData | ||
element, // DOMElement|string* | ||
eventHandler, | ||
customData | ||
) { | ||
bind(element, 'focus', eventHandler, true, customData); | ||
bind(element, 'blur', eventHandler, false, customData); | ||
bind(element, 'focus', eventHandler, true, customData); | ||
bind(element, 'blur', eventHandler, false, customData); | ||
}; | ||
@@ -87,11 +87,11 @@ | ||
var bindHover = function ( | ||
element, | ||
eventHandler, | ||
customData | ||
element, | ||
eventHandler, | ||
customData | ||
) { | ||
var ieVersion = getBrowserVersionOrZero('msie'); | ||
var HOVER_OVER = 'mouse' + (ieVersion ? 'enter' : 'over'); | ||
var HOVER_OUT = 'mouse' + (ieVersion ? 'leave' : 'out'); | ||
bind(element, HOVER_OVER, eventHandler, true, customData); | ||
bind(element, HOVER_OUT, eventHandler, false, customData); | ||
var ieVersion = getBrowserVersionOrZero('msie'); | ||
var HOVER_OVER = 'mouse' + (ieVersion ? 'enter' : 'over'); | ||
var HOVER_OUT = 'mouse' + (ieVersion ? 'leave' : 'out'); | ||
bind(element, HOVER_OVER, eventHandler, true, customData); | ||
bind(element, HOVER_OUT, eventHandler, false, customData); | ||
}; | ||
@@ -131,9 +131,9 @@ | ||
var onHover = function ( | ||
element, | ||
tagAndClass, | ||
eventHandler, | ||
customData | ||
element, | ||
tagAndClass, | ||
eventHandler, | ||
customData | ||
) { | ||
on(element, tagAndClass, 'mouseover', eventHandler, true, customData); | ||
on(element, tagAndClass, 'mouseout', eventHandler, false, customData); | ||
on(element, tagAndClass, 'mouseover', eventHandler, true, customData); | ||
on(element, tagAndClass, 'mouseout', eventHandler, false, customData); | ||
}; | ||
@@ -145,7 +145,7 @@ | ||
var bindClick = function ( | ||
element, | ||
eventHandler, | ||
customData | ||
element, | ||
eventHandler, | ||
customData | ||
) { | ||
bind(element, 'click', eventHandler, customData); | ||
bind(element, 'click', eventHandler, customData); | ||
}; | ||
@@ -157,15 +157,15 @@ | ||
var bindWindowLoad = function ( | ||
callback, | ||
windowObject | ||
callback, | ||
windowObject | ||
) { | ||
// Default to the run after the window we're in. | ||
windowObject = windowObject || window; | ||
// If the window is already loaded, run the callback now. | ||
if (isLoaded(windowObject.document)) { | ||
callback(); | ||
} | ||
// Otherwise, defer the callback. | ||
else { | ||
bind(windowObject, 'load', callback); | ||
} | ||
// Default to the run after the window we're in. | ||
windowObject = windowObject || window; | ||
// If the window is already loaded, run the callback now. | ||
if (isLoaded(windowObject.document)) { | ||
callback(); | ||
} | ||
// Otherwise, defer the callback. | ||
else { | ||
bind(windowObject, 'load', callback); | ||
} | ||
}; | ||
@@ -178,9 +178,9 @@ | ||
var isLoaded = function ( | ||
object | ||
object | ||
) { | ||
var state = object.readyState; | ||
// In all browsers, documents will reach readyState=="complete". | ||
// In IE, scripts can reach readyState=="loaded" or readyState=="complete". | ||
// In non-IE browsers, we can bind to script.onload instead of checking script.readyState. | ||
return state == 'complete' || (object.tagName == 'script' && state == 'loaded'); | ||
var state = object.readyState; | ||
// In all browsers, documents will reach readyState=="complete". | ||
// In IE, scripts can reach readyState=="loaded" or readyState=="complete". | ||
// In non-IE browsers, we can bind to script.onload instead of checking script.readyState. | ||
return state == 'complete' || (object.tagName == 'script' && state == 'loaded'); | ||
}; | ||
@@ -192,8 +192,17 @@ | ||
var focusElement = function ( | ||
element | ||
element, | ||
delay | ||
) { | ||
element = getElement(element); | ||
if (element) { | ||
element.focus(); | ||
} | ||
var focus = function () { | ||
element = getElement(element); | ||
if (element) { | ||
element.focus(); | ||
} | ||
}; | ||
if (typeof delay == 'undefined') { | ||
focus(); | ||
} | ||
else { | ||
setTimeout(focus, delay); | ||
} | ||
}; | ||
@@ -205,11 +214,40 @@ | ||
var doOnce = function ( | ||
method, | ||
args, | ||
delay | ||
method, | ||
args, | ||
delay | ||
) { | ||
clearTimeout(method.t); | ||
method.t = setTimeout(function () { | ||
clearTimeout(method.t); | ||
method.call(args); | ||
}, delay || 9); | ||
clearTimeout(method.t); | ||
method.t = setTimeout(function () { | ||
clearTimeout(method.t); | ||
method.call(args); | ||
}, delay || 9); | ||
}; | ||
/** | ||
* Set or reset a timeout, and save it for possible cancellation. | ||
*/ | ||
var addTimeout = function ( | ||
elementOrString, | ||
callback, | ||
delay | ||
) { | ||
var isString = (typeof elementOrString == 'string'); | ||
var object = isString ? addTimeout : elementOrString; | ||
var key = isString ? elementOrString : 'T'; | ||
clearTimeout(object[key]); | ||
if (callback) { | ||
if (typeof delay == 'undefined') { | ||
delay = 9; | ||
} | ||
object[key] = setTimeout(callback, delay); | ||
} | ||
}; | ||
/** | ||
* Remove a timeout from an element or from the addTimeout method. | ||
*/ | ||
var removeTimeout = function ( | ||
elementOrString | ||
) { | ||
addTimeout(elementOrString, false); | ||
}; |
@@ -5,37 +5,36 @@ /** | ||
var valueOf = function ( | ||
input, | ||
value | ||
input, | ||
value | ||
) { | ||
input = getElement(input); | ||
var type = input.type; | ||
var isCheckbox = type == 'checkbox'; | ||
var isRadio = type == 'radio'; | ||
var isSelect = /select/.test(type); | ||
// TODO: Make this work for select boxes and other stuff too. | ||
if (typeof value == 'undefined') { | ||
value = input.value; | ||
if (isCheckbox) { | ||
return input.checked ? value : null; | ||
} | ||
else if (isSelect) { | ||
return input.options[input.selectedIndex].value; | ||
} | ||
} | ||
else { | ||
if (isCheckbox) { | ||
input.checked = value ? true : false; | ||
} | ||
else if (isSelect) { | ||
forEach(input.options, function (option, index) { | ||
if (option.value == value) { | ||
input.selectedIndex = index; | ||
} | ||
}); | ||
} | ||
else { | ||
input.value = value; | ||
} | ||
} | ||
return input.value; | ||
input = getElement(input); | ||
var type = input.type; | ||
var isCheckbox = type == 'checkbox'; | ||
var isRadio = type == 'radio'; | ||
var isSelect = /select/.test(type); | ||
if (typeof value == 'undefined') { | ||
value = input.value; | ||
if (isCheckbox) { | ||
return input.checked ? value : null; | ||
} | ||
else if (isSelect) { | ||
return input.options[input.selectedIndex].value; | ||
} | ||
} | ||
else { | ||
if (isCheckbox) { | ||
input.checked = value ? true : false; | ||
} | ||
else if (isSelect) { | ||
forEach(input.options, function (option, index) { | ||
if (option.value == value) { | ||
input.selectedIndex = index; | ||
} | ||
}); | ||
} | ||
else { | ||
input.value = value; | ||
} | ||
} | ||
return input.value; | ||
}; | ||
/** | ||
* Return a history object. | ||
* Return a history object. | ||
*/ | ||
var getHistory = function () { | ||
var history = window.history || {}; | ||
forEach(['push', 'replace'], function (key) { | ||
var fn = history[key + 'State']; | ||
history[key] = function (href) { | ||
if (fn) { | ||
fn.apply(history, [null, null, href]); | ||
} else { | ||
// TODO: Create a backward compatible history push. | ||
} | ||
}; | ||
}); | ||
return history; | ||
var history = window.history || {}; | ||
forEach(['push', 'replace'], function (key) { | ||
var fn = history[key + 'State']; | ||
history[key] = function (href) { | ||
if (fn) { | ||
fn.apply(history, [null, null, href]); | ||
} else { | ||
// TODO: Create a backward compatible history push. | ||
} | ||
}; | ||
}); | ||
return history; | ||
}; | ||
@@ -23,5 +23,5 @@ | ||
var pushHistory = function ( | ||
href | ||
href | ||
) { | ||
getHistory().push(href); | ||
getHistory().push(href); | ||
}; | ||
@@ -33,5 +33,5 @@ | ||
var replaceHistory = function ( | ||
href | ||
href | ||
) { | ||
getHistory().replace(href); | ||
getHistory().replace(href); | ||
}; | ||
@@ -43,6 +43,6 @@ | ||
var popHistory = function ( | ||
href | ||
href | ||
) { | ||
getHistory().back(); | ||
getHistory().back(); | ||
}; | ||
@@ -5,4 +5,4 @@ /** | ||
var log = function ( | ||
message, | ||
object | ||
message, | ||
object | ||
) { | ||
@@ -19,2 +19,1 @@ if (window.console && console.log) { | ||
}; | ||
/** | ||
* If the argument is numeric, return a number, otherwise return zero. | ||
* If the argument is numeric, return a number, otherwise return zero. | ||
* @param {Object} n | ||
*/ | ||
var forceNumber = function ( | ||
number, | ||
defaultNumber | ||
number, | ||
defaultNumber | ||
) { | ||
defaultNumber = defaultNumber || 0; | ||
number *= 1; | ||
return isNaN(number) ? defaultNumber : number; | ||
defaultNumber = defaultNumber || 0; | ||
number *= 1; | ||
return isNaN(number) ? defaultNumber : number; | ||
}; | ||
@@ -5,3 +5,3 @@ /** | ||
var isString = function ( | ||
object | ||
object | ||
) { | ||
@@ -15,4 +15,4 @@ return typeof object == 'string'; | ||
var containsString = function ( | ||
string, | ||
substring | ||
string, | ||
substring | ||
) { | ||
@@ -26,5 +26,5 @@ return ('' + string).indexOf(substring) > -1; | ||
var trimString = function ( | ||
string | ||
string | ||
) { | ||
return ('' + string).replace(/^\s+|\s+$/g, ''); | ||
return ('' + string).replace(/^\s+|\s+$/g, ''); | ||
}; | ||
@@ -36,4 +36,4 @@ | ||
var decorateString = function ( | ||
string, | ||
replacements | ||
string, | ||
replacements | ||
) { | ||
@@ -51,3 +51,3 @@ string = '' + string; | ||
var extractLetters = function ( | ||
string | ||
string | ||
) { | ||
@@ -61,3 +61,3 @@ return ('' + string).replace(/[^a-z]/ig, ''); | ||
var extractNumbers = function ( | ||
string | ||
string | ||
) { | ||
@@ -71,9 +71,9 @@ return ('' + string).replace(/[^0-9]/g, ''); | ||
var buildQueryString = function ( | ||
object | ||
object | ||
) { | ||
var queryParams = []; | ||
forIn(object, function(value, key) { | ||
queryParams.push(escape(key) + '=' + escape(value)); | ||
}); | ||
return queryParams.join('&'); | ||
var queryParams = []; | ||
forIn(object, function(value, key) { | ||
queryParams.push(escape(key) + '=' + escape(value)); | ||
}); | ||
return queryParams.join('&'); | ||
}; | ||
@@ -85,3 +85,3 @@ | ||
var getBrowserVersionOrZero = function ( | ||
browserName | ||
browserName | ||
) { | ||
@@ -88,0 +88,0 @@ var match = new RegExp(browserName + '[ /](\\d+(\\.\\d+)?)', 'i').exec(navigator.userAgent); |
@@ -5,3 +5,3 @@ /** | ||
var getHost = function () { | ||
return location.host; | ||
return location.host; | ||
}; | ||
@@ -13,3 +13,3 @@ | ||
var getBaseUrl = function () { | ||
return location.protocol + '//' + getHost(); | ||
return location.protocol + '//' + getHost(); | ||
}; | ||
@@ -21,15 +21,15 @@ | ||
var getQueryParams = function ( | ||
url | ||
url | ||
) { | ||
url = url || location.href; | ||
var query = url.substr(url.indexOf('?') + 1).split('#')[0]; | ||
var pairs = query.split('&'); | ||
query = {}; | ||
forEach(pairs, function (pair) { | ||
var eqPos = pair.indexOf('='); | ||
var name = pair.substr(0, eqPos); | ||
var value = pair.substr(eqPos + 1); | ||
query[name] = value; | ||
}); | ||
return query; | ||
url = url || location.href; | ||
var query = url.substr(url.indexOf('?') + 1).split('#')[0]; | ||
var pairs = query.split('&'); | ||
query = {}; | ||
forEach(pairs, function (pair) { | ||
var eqPos = pair.indexOf('='); | ||
var name = pair.substr(0, eqPos); | ||
var value = pair.substr(eqPos + 1); | ||
query[name] = value; | ||
}); | ||
return query; | ||
}; | ||
@@ -41,7 +41,7 @@ | ||
var getHashParams = function ( | ||
hash | ||
hash | ||
) { | ||
hash = (hash || location.hash).replace(/^#/, ''); | ||
return hash ? getQueryParams(hash) : {}; | ||
hash = (hash || location.hash).replace(/^#/, ''); | ||
return hash ? getQueryParams(hash) : {}; | ||
}; | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
70775
2416