Commit 91fff57b authored by Arthur Verschaeve's avatar Arthur Verschaeve

Migrate `lavaca_require` example to `todomvc-app-css`

Ref gh-1110
parent c5ddf214
node_modules/todomvc-app-css/*
!node_modules/todomvc-app-css/index.css
node_modules/todomvc-common/*
!node_modules/todomvc-common/base.js
!node_modules/todomvc-common/base.css
node_modules/dustjs-helpers/**
!node_modules/dustjs-helpers/dist/dust-helpers.js
node_modules/dustjs-linkedin/**
!node_modules/dustjs-linkedin/dist/dust-full.js
node_modules/mout/**
!node_modules/mout/src/**
node_modules/requirejs/**
!node_modules/requirejs/require.js
{
"name": "todomvc-lavaca_require",
"version": "0.0.0",
"dependencies": {
"todomvc-common": "~0.3.0",
"requirejs": "~2.1.6",
"dustjs-linkedin": "~1.1.1",
"dustjs-linkedin-helpers": "~1.1.1",
"jquery": "~2.0.3",
"mout": "~0.7.1"
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>Lavaca • TodoMVC</title> <title>Lavaca • TodoMVC</title>
<link rel="stylesheet" href="bower_components/todomvc-common/base.css"> <link rel="stylesheet" href="node_modules/todomvc-common/base.css">
<link rel="stylesheet" href="node_modules/todomvc-app-css/index.css">
</head> </head>
<body> <body>
<section id="todoapp"></section> <section id="todoapp"></section>
...@@ -12,8 +13,8 @@ ...@@ -12,8 +13,8 @@
<p>Created by <a href="https://github.com/mutualmobile/" data-external>Mutual Mobile</a></p> <p>Created by <a href="https://github.com/mutualmobile/" data-external>Mutual Mobile</a></p>
<p>Part of <a href="http://todomvc.com" data-external>TodoMVC</a></p> <p>Part of <a href="http://todomvc.com" data-external>TodoMVC</a></p>
</footer> </footer>
<script src="bower_components/todomvc-common/base.js"></script> <script src="node_modules/todomvc-common/base.js"></script>
<script src="bower_components/requirejs/require.js"></script> <script src="node_modules/requirejs/require.js"></script>
<script src="js/libs/lavaca.js"></script> <script src="js/libs/lavaca.js"></script>
<script src="js/app/boot.js"></script> <script src="js/app/boot.js"></script>
</body> </body>
......
require.config({ require.config({
baseUrl: 'js', baseUrl: 'js',
paths: { paths: {
$: '../bower_components/jquery/jquery', $: '../node_modules/jquery/dist/jquery',
jquery: '../bower_components/jquery/jquery', jquery: '../node_modules/jquery/dist/jquery',
mout: '../bower_components/mout/src', mout: '../node_modules/mout/src',
dust: '../bower_components/dustjs-linkedin/dist/dust-full-1.1.1', dust: '../node_modules/dustjs-linkedin/dist/dust-full',
'dust-helpers': '../bower_components/dustjs-linkedin-helpers/dist/dust-helpers-1.1.1', 'dust-helpers': '../node_modules/dustjs-helpers/dist/dust-helpers',
rdust: 'libs/require-dust', rdust: 'libs/require-dust',
lavaca: 'Lavaca', lavaca: 'Lavaca',
Lavaca: 'lavaca' Lavaca: 'lavaca'
...@@ -28,4 +28,4 @@ require.config({ ...@@ -28,4 +28,4 @@ require.config({
} }
} }
}); });
require(['app/app']); require(['app/app']);
\ No newline at end of file
// /*! dustjs-helpers - v1.6.1
// Dust-helpers - Additional functionality for dustjs-linkedin package v1.1.1 * https://github.com/linkedin/dustjs-helpers
// * Copyright (c) 2015 Aleksander Williams; Released under the MIT License */
// Copyright (c) 2012, LinkedIn (function(root, factory) {
// Released under the MIT License. if (typeof define === 'function' && define.amd && define.amd.dust === true) {
// define(['dust.core'], factory);
} else if (typeof exports === 'object') {
(function(dust){ module.exports = factory(require('dustjs-linkedin'));
} else {
// Note: all error conditions are logged to console and failed silently factory(root.dust);
}
/* make a safe version of console if it is not available }(this, function(dust) {
* currently supporting:
* _console.log // Use dust's built-in logging when available
* */ var _log = dust.log ? function(msg, level) {
var _console = (typeof console !== 'undefined')? console: { level = level || "INFO";
log: function(){ dust.log(msg, level);
/* a noop*/ } : function() {};
}
}; var _deprecatedCache = {};
function _deprecated(target) {
if(_deprecatedCache[target]) { return; }
_log("Deprecation warning: " + target + " is deprecated and will be removed in a future version of dustjs-helpers", "WARN");
_log("For help and a deprecation timeline, see https://github.com/linkedin/dustjs-helpers/wiki/Deprecated-Features#" + target.replace(/\W+/g, ""), "WARN");
_deprecatedCache[target] = true;
}
function isSelect(context) { function isSelect(context) {
var value = context.current(); return context.stack.tail &&
return typeof value === "object" && value.isSelect === true; typeof context.stack.tail.head.__select__ !== "undefined";
}
function getSelectState(context) {
return context.get('__select__');
}
function addSelectState(context, key) {
var head = context.stack.head,
newContext = context.rebase();
if(context.stack && context.stack.tail) {
newContext.stack = context.stack.tail;
}
return newContext
.push({ "__select__": {
isResolved: false,
isDefaulted: false,
isDeferredComplete: false,
deferreds: [],
key: key
}
})
.push(head, context.stack.index, context.stack.of);
} }
// Utility method : toString() equivalent for functions // Utility method : toString() equivalent for functions
function jsonFilter(key, value) { function jsonFilter(key, value) {
if (typeof value === "function") { if (typeof value === "function") {
return value.toString(); //to make sure all environments format functions the same way
return value.toString()
//remove all leading and trailing whitespace
.replace(/(^\s+|\s+$)/mg, '')
//remove new line characters
.replace(/\n/mg, '')
//replace , and 0 or more spaces with ", "
.replace(/,\s*/mg, ', ')
//insert space between ){
.replace(/\)\{/mg, ') {')
;
} }
return value; return value;
} }
...@@ -38,52 +78,55 @@ function filter(chunk, context, bodies, params, filterOp) { ...@@ -38,52 +78,55 @@ function filter(chunk, context, bodies, params, filterOp) {
var body = bodies.block, var body = bodies.block,
actualKey, actualKey,
expectedValue, expectedValue,
selectState,
filterOpType = params.filterOpType || ''; filterOpType = params.filterOpType || '';
// when @eq, @lt etc are used as standalone helpers, key is required and hence check for defined
if ( typeof params.key !== "undefined") { // Currently we first check for a key on the helper itself, then fall back to
// looking for a key on the {@select} that contains it. This is undocumented
// behavior that we may or may not support in the future. (If we stop supporting
// it, just switch the order of the test below to check the {@select} first.)
if (params.hasOwnProperty("key")) {
actualKey = dust.helpers.tap(params.key, chunk, context); actualKey = dust.helpers.tap(params.key, chunk, context);
} } else if (isSelect(context)) {
else if (isSelect(context)) { selectState = getSelectState(context);
actualKey = context.current().selectKey; actualKey = selectState.key;
// supports only one of the blocks in the select to be selected // Once one truth test in a select passes, short-circuit the rest of the tests
if (context.current().isResolved) { if (selectState.isResolved) {
filterOp = function() { return false; }; filterOp = function() { return false; };
} }
} } else {
else { _log("No key specified for filter in {@" + filterOpType + "}");
_console.log ("No key specified for filter in:" + filterOpType + " helper ");
return chunk; return chunk;
} }
expectedValue = dust.helpers.tap(params.value, chunk, context); expectedValue = dust.helpers.tap(params.value, chunk, context);
// coerce both the actualKey and expectedValue to the same type for equality and non-equality compares // coerce both the actualKey and expectedValue to the same type for equality and non-equality compares
if (filterOp(coerce(expectedValue, params.type, context), coerce(actualKey, params.type, context))) { if (filterOp(coerce(expectedValue, params.type, context), coerce(actualKey, params.type, context))) {
if (isSelect(context)) { if (isSelect(context)) {
context.current().isResolved = true; if(filterOpType === 'default') {
selectState.isDefaulted = true;
}
selectState.isResolved = true;
} }
// we want helpers without bodies to fail gracefully so check it first // Helpers without bodies are valid due to the use of {@any} blocks
if(body) { if(body) {
return chunk.render(body, context); return chunk.render(body, context);
} } else {
else {
_console.log( "Missing body block in the " + filterOpType + " helper ");
return chunk; return chunk;
} }
} } else if (bodies['else']) {
else if (bodies['else']) {
return chunk.render(bodies['else'], context); return chunk.render(bodies['else'], context);
} }
return chunk; return chunk;
} }
function coerce (value, type, context) { function coerce(value, type, context) {
if (value) { if (typeof value !== "undefined") {
switch (type || typeof(value)) { switch (type || typeof value) {
case 'number': return +value; case 'number': return +value;
case 'string': return String(value); case 'string': return String(value);
case 'boolean': { case 'boolean':
value = (value === 'false' ? false : value); value = (value === 'false' ? false : value);
return Boolean(value); return Boolean(value);
}
case 'date': return new Date(value); case 'date': return new Date(value);
case 'context': return context.get(value); case 'context': return context.get(value);
} }
...@@ -111,26 +154,34 @@ var helpers = { ...@@ -111,26 +154,34 @@ var helpers = {
dust render emits < and we return the partial output dust render emits < and we return the partial output
*/ */
"tap": function( input, chunk, context ){ "tap": function(input, chunk, context) {
// return given input if there is no dust reference to resolve // return given input if there is no dust reference to resolve
var output = input; // dust compiles a string/reference such as {foo} to a function
// dust compiles a string/reference such as {foo} to function, if (typeof input !== "function") {
if( typeof input === "function"){ return input;
// just a plain function (a.k.a anonymous functions) in the context, not a dust `body` function created by the dust compiler }
if( input.isFunction === true ){
output = input(); var dustBodyOutput = '',
} else { returnValue;
output = '';
chunk.tap(function(data){ //use chunk render to evaluate output. For simple functions result will be returned from render call,
output += data; //for dust body functions result will be output via callback function
return ''; returnValue = chunk.tap(function(data) {
}).render(input, context).untap(); dustBodyOutput += data;
if( output === '' ){ return '';
output = false; }).render(input, context);
}
} chunk.untap();
//assume it's a simple function call if return result is not a chunk
if (returnValue.constructor !== chunk.constructor) {
//use returnValue as a result of tap
return returnValue;
} else if (dustBodyOutput === '') {
return false;
} else {
return dustBodyOutput;
} }
return output;
}, },
"sep": function(chunk, context, bodies) { "sep": function(chunk, context, bodies) {
...@@ -138,22 +189,25 @@ var helpers = { ...@@ -138,22 +189,25 @@ var helpers = {
if (context.stack.index === context.stack.of - 1) { if (context.stack.index === context.stack.of - 1) {
return chunk; return chunk;
} }
if(body) { if (body) {
return bodies.block(chunk, context); return body(chunk, context);
} else {
return chunk;
} }
else { },
return chunk;
"first": function(chunk, context, bodies) {
if (context.stack.index === 0) {
return bodies.block(chunk, context);
} }
return chunk;
}, },
"idx": function(chunk, context, bodies) { "last": function(chunk, context, bodies) {
var body = bodies.block; if (context.stack.index === context.stack.of - 1) {
if(body) { return bodies.block(chunk, context);
return bodies.block(chunk, context.push(context.stack.index)); }
} return chunk;
else {
return chunk;
}
}, },
/** /**
...@@ -168,7 +222,7 @@ var helpers = { ...@@ -168,7 +222,7 @@ var helpers = {
to = p.to || 'output', to = p.to || 'output',
key = p.key || 'current', key = p.key || 'current',
dump; dump;
to = dust.helpers.tap(to, chunk, context), to = dust.helpers.tap(to, chunk, context);
key = dust.helpers.tap(key, chunk, context); key = dust.helpers.tap(key, chunk, context);
if (key === 'full') { if (key === 'full') {
dump = JSON.stringify(context.stack, jsonFilter, 2); dump = JSON.stringify(context.stack, jsonFilter, 2);
...@@ -177,10 +231,13 @@ var helpers = { ...@@ -177,10 +231,13 @@ var helpers = {
dump = JSON.stringify(context.stack.head, jsonFilter, 2); dump = JSON.stringify(context.stack.head, jsonFilter, 2);
} }
if (to === 'console') { if (to === 'console') {
_console.log(dump); _log(dump);
return chunk; return chunk;
} }
else { else {
// encode opening brackets when outputting to html
dump = dump.replace(/</g, '\\u003c');
return chunk.write(dump); return chunk.write(dump);
} }
}, },
...@@ -200,33 +257,6 @@ var helpers = { ...@@ -200,33 +257,6 @@ var helpers = {
cond argument should evaluate to a valid javascript expression cond argument should evaluate to a valid javascript expression
**/ **/
"if": function( chunk, context, bodies, params ){
var body = bodies.block,
skip = bodies['else'];
if( params && params.cond){
var cond = params.cond;
cond = dust.helpers.tap(cond, chunk, context);
// eval expressions with given dust references
if(eval(cond)){
if(body) {
return chunk.render( bodies.block, context );
}
else {
_console.log( "Missing body block in the if helper!" );
return chunk;
}
}
if(skip){
return chunk.render( bodies['else'], context );
}
}
// no condition
else {
_console.log( "No condition given in the if helper!" );
}
return chunk;
},
/** /**
* math helper * math helper
* @param key is the value to perform math against * @param key is the value to perform math against
...@@ -242,47 +272,50 @@ var helpers = { ...@@ -242,47 +272,50 @@ var helpers = {
// operand can be null for "abs", ceil and floor // operand can be null for "abs", ceil and floor
operand = params.operand, operand = params.operand,
round = params.round, round = params.round,
mathOut = null, mathOut = null;
operError = function(){_console.log("operand is required for this math method"); return null;};
key = dust.helpers.tap(key, chunk, context); key = parseFloat(dust.helpers.tap(key, chunk, context));
operand = dust.helpers.tap(operand, chunk, context); operand = parseFloat(dust.helpers.tap(operand, chunk, context));
// TODO: handle and tests for negatives and floats in all math operations // TODO: handle and tests for negatives and floats in all math operations
switch(method) { switch(method) {
case "mod": case "mod":
if(operand === 0 || operand === -0) { if(operand === 0 || operand === -0) {
_console.log("operand for divide operation is 0/-0: expect Nan!"); _log("Division by 0 in {@math} helper", "WARN");
} }
mathOut = parseFloat(key) % parseFloat(operand); mathOut = key % operand;
break; break;
case "add": case "add":
mathOut = parseFloat(key) + parseFloat(operand); mathOut = key + operand;
break; break;
case "subtract": case "subtract":
mathOut = parseFloat(key) - parseFloat(operand); mathOut = key - operand;
break; break;
case "multiply": case "multiply":
mathOut = parseFloat(key) * parseFloat(operand); mathOut = key * operand;
break; break;
case "divide": case "divide":
if(operand === 0 || operand === -0) { if(operand === 0 || operand === -0) {
_console.log("operand for divide operation is 0/-0: expect Nan/Infinity!"); _log("Division by 0 in {@math} helper", "WARN");
} }
mathOut = parseFloat(key) / parseFloat(operand); mathOut = key / operand;
break; break;
case "ceil": case "ceil":
mathOut = Math.ceil(parseFloat(key)); mathOut = Math.ceil(key);
break; break;
case "floor": case "floor":
mathOut = Math.floor(parseFloat(key)); mathOut = Math.floor(key);
break; break;
case "round": case "round":
mathOut = Math.round(parseFloat(key)); mathOut = Math.round(key);
break; break;
case "abs": case "abs":
mathOut = Math.abs(parseFloat(key)); mathOut = Math.abs(key);
break;
case "toint":
mathOut = parseInt(key, 10);
break; break;
default: default:
_console.log( "method passed is not supported" ); _log("{@math}: method " + method + " not supported");
} }
if (mathOut !== null){ if (mathOut !== null){
...@@ -292,7 +325,8 @@ var helpers = { ...@@ -292,7 +325,8 @@ var helpers = {
if (bodies && bodies.block) { if (bodies && bodies.block) {
// with bodies act like the select helper with mathOut as the key // with bodies act like the select helper with mathOut as the key
// like the select helper bodies['else'] is meaningless and is ignored // like the select helper bodies['else'] is meaningless and is ignored
return chunk.render(bodies.block, context.push({ isSelect: true, isResolved: false, selectKey: mathOut })); context = addSelectState(context, mathOut);
return chunk.render(bodies.block, context);
} else { } else {
// self closing math helper will return the calculated output // self closing math helper will return the calculated output
return chunk.write(mathOut); return chunk.write(mathOut);
...@@ -303,12 +337,12 @@ var helpers = { ...@@ -303,12 +337,12 @@ var helpers = {
} }
// no key parameter and no method // no key parameter and no method
else { else {
_console.log( "Key is a required parameter for math helper along with method/operand!" ); _log("Key is a required parameter for math helper along with method/operand!");
} }
return chunk; return chunk;
}, },
/** /**
select helperworks with one of the eq/gt/gte/lt/lte/default providing the functionality select helper works with one of the eq/ne/gt/gte/lt/lte/default providing the functionality
of branching conditions of branching conditions
@param key, ( required ) either a string literal value or a dust reference @param key, ( required ) either a string literal value or a dust reference
a string literal value, is enclosed in double quotes, e.g. key="foo" a string literal value, is enclosed in double quotes, e.g. key="foo"
...@@ -316,23 +350,28 @@ var helpers = { ...@@ -316,23 +350,28 @@ var helpers = {
@param type (optional), supported types are number, boolean, string, date, context, defaults to string @param type (optional), supported types are number, boolean, string, date, context, defaults to string
**/ **/
"select": function(chunk, context, bodies, params) { "select": function(chunk, context, bodies, params) {
var body = bodies.block; var body = bodies.block,
// key is required for processing, hence check for defined state, key, len, x;
if( params && typeof params.key !== "undefined"){
// returns given input as output, if the input is not a dust reference, else does a context lookup if (params.hasOwnProperty("key")) {
var key = dust.helpers.tap(params.key, chunk, context); key = dust.helpers.tap(params.key, chunk, context);
// bodies['else'] is meaningless and is ignored // bodies['else'] is meaningless and is ignored
if( body ) { if (body) {
return chunk.render(bodies.block, context.push({ isSelect: true, isResolved: false, selectKey: key })); context = addSelectState(context, key);
} state = getSelectState(context);
else { chunk = chunk.render(body, context);
_console.log( "Missing body block in the select helper "); // Resolve any deferred blocks (currently just {@any} blocks)
return chunk; if(state.deferreds.length) {
state.isDeferredComplete = true;
for(x=0, len=state.deferreds.length; x<len; x++) {
state.deferreds[x]();
}
}
} else {
_log("Missing body block in {@select}");
} }
} } else {
// no key _log("No key provided for {@select}", "WARN");
else {
_console.log( "No key given in the select helper!" );
} }
return chunk; return chunk;
}, },
...@@ -349,9 +388,7 @@ var helpers = { ...@@ -349,9 +388,7 @@ var helpers = {
Note : use type="number" when comparing numeric Note : use type="number" when comparing numeric
**/ **/
"eq": function(chunk, context, bodies, params) { "eq": function(chunk, context, bodies, params) {
if(params) { params.filterOpType = "eq";
params.filterOpType = "eq";
}
return filter(chunk, context, bodies, params, function(expected, actual) { return actual === expected; }); return filter(chunk, context, bodies, params, function(expected, actual) { return actual === expected; });
}, },
...@@ -367,11 +404,8 @@ var helpers = { ...@@ -367,11 +404,8 @@ var helpers = {
Note : use type="number" when comparing numeric Note : use type="number" when comparing numeric
**/ **/
"ne": function(chunk, context, bodies, params) { "ne": function(chunk, context, bodies, params) {
if(params) { params.filterOpType = "ne";
params.filterOpType = "ne"; return filter(chunk, context, bodies, params, function(expected, actual) { return actual !== expected; });
return filter(chunk, context, bodies, params, function(expected, actual) { return actual !== expected; });
}
return chunk;
}, },
/** /**
...@@ -386,10 +420,8 @@ var helpers = { ...@@ -386,10 +420,8 @@ var helpers = {
Note : use type="number" when comparing numeric Note : use type="number" when comparing numeric
**/ **/
"lt": function(chunk, context, bodies, params) { "lt": function(chunk, context, bodies, params) {
if(params) { params.filterOpType = "lt";
params.filterOpType = "lt"; return filter(chunk, context, bodies, params, function(expected, actual) { return actual < expected; });
return filter(chunk, context, bodies, params, function(expected, actual) { return actual < expected; });
}
}, },
/** /**
...@@ -404,14 +436,10 @@ var helpers = { ...@@ -404,14 +436,10 @@ var helpers = {
Note : use type="number" when comparing numeric Note : use type="number" when comparing numeric
**/ **/
"lte": function(chunk, context, bodies, params) { "lte": function(chunk, context, bodies, params) {
if(params) { params.filterOpType = "lte";
params.filterOpType = "lte"; return filter(chunk, context, bodies, params, function(expected, actual) { return actual <= expected; });
return filter(chunk, context, bodies, params, function(expected, actual) { return actual <= expected; });
}
return chunk;
}, },
/** /**
gt helper compares the given key is greater than the expected value gt helper compares the given key is greater than the expected value
It can be used standalone or in conjunction with select for multiple branching It can be used standalone or in conjunction with select for multiple branching
...@@ -424,12 +452,8 @@ var helpers = { ...@@ -424,12 +452,8 @@ var helpers = {
Note : use type="number" when comparing numeric Note : use type="number" when comparing numeric
**/ **/
"gt": function(chunk, context, bodies, params) { "gt": function(chunk, context, bodies, params) {
// if no params do no go further params.filterOpType = "gt";
if(params) { return filter(chunk, context, bodies, params, function(expected, actual) { return actual > expected; });
params.filterOpType = "gt";
return filter(chunk, context, bodies, params, function(expected, actual) { return actual > expected; });
}
return chunk;
}, },
/** /**
...@@ -444,21 +468,82 @@ var helpers = { ...@@ -444,21 +468,82 @@ var helpers = {
Note : use type="number" when comparing numeric Note : use type="number" when comparing numeric
**/ **/
"gte": function(chunk, context, bodies, params) { "gte": function(chunk, context, bodies, params) {
if(params) { params.filterOpType = "gte";
params.filterOpType = "gte"; return filter(chunk, context, bodies, params, function(expected, actual) { return actual >= expected; });
return filter(chunk, context, bodies, params, function(expected, actual) { return actual >= expected; }); },
}
/**
* {@any}
* Outputs as long as at least one truth test inside a {@select} has passed.
* Must be contained inside a {@select} block.
* The passing truth test can be before or after the {@any} block.
*/
"any": function(chunk, context, bodies, params) {
var selectState;
if(!isSelect(context)) {
_log("{@any} used outside of a {@select} block", "WARN");
} else {
selectState = getSelectState(context);
if(selectState.isDeferredComplete) {
_log("{@any} nested inside {@any} or {@none} block. It needs its own {@select} block", "WARN");
} else {
chunk = chunk.map(function(chunk) {
selectState.deferreds.push(function() {
if(selectState.isResolved && !selectState.isDefaulted) {
chunk = chunk.render(bodies.block, context);
}
chunk.end();
});
});
}
}
return chunk; return chunk;
}, },
// to be used in conjunction with the select helper /**
// TODO: fix the helper to do nothing when used standalone * {@none}
"default": function(chunk, context, bodies, params) { * Outputs if no truth tests inside a {@select} pass.
// does not require any params * Must be contained inside a {@select} block.
if(params) { * The position of the helper does not matter.
params.filterOpType = "default"; */
"none": function(chunk, context, bodies, params) {
var selectState;
if(!isSelect(context)) {
_log("{@none} used outside of a {@select} block", "WARN");
} else {
selectState = getSelectState(context);
if(selectState.isDeferredComplete) {
_log("{@none} nested inside {@any} or {@none} block. It needs its own {@select} block", "WARN");
} else {
chunk = chunk.map(function(chunk) {
selectState.deferreds.push(function() {
if(!selectState.isResolved) {
chunk = chunk.render(bodies.block, context);
}
chunk.end();
});
});
} }
return filter(chunk, context, bodies, params, function(expected, actual) { return true; }); }
return chunk;
},
/**
* {@default}
* Outputs if no truth test inside a {@select} has passed.
* Must be contained inside a {@select} block.
*/
"default": function(chunk, context, bodies, params) {
params.filterOpType = "default";
// Deprecated for removal in 1.7
_deprecated("{@default}");
if(!isSelect(context)) {
_log("{@default} used outside of a {@select} block", "WARN");
return chunk;
}
return filter(chunk, context, bodies, params, function() { return true; });
}, },
/** /**
...@@ -498,6 +583,10 @@ var helpers = { ...@@ -498,6 +583,10 @@ var helpers = {
}; };
dust.helpers = helpers; for(var key in helpers) {
dust.helpers[key] = helpers[key];
}
return dust;
})(typeof exports !== 'undefined' ? module.exports = require('dustjs-linkedin') : dust); }));
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
define(function(require){
//automatically generated, do not edit!
//run `node build` instead
return {
'append' : require('./array/append'),
'collect' : require('./array/collect'),
'combine' : require('./array/combine'),
'compact' : require('./array/compact'),
'contains' : require('./array/contains'),
'difference' : require('./array/difference'),
'every' : require('./array/every'),
'filter' : require('./array/filter'),
'find' : require('./array/find'),
'findIndex' : require('./array/findIndex'),
'flatten' : require('./array/flatten'),
'forEach' : require('./array/forEach'),
'indexOf' : require('./array/indexOf'),
'insert' : require('./array/insert'),
'intersection' : require('./array/intersection'),
'invoke' : require('./array/invoke'),
'join' : require('./array/join'),
'lastIndexOf' : require('./array/lastIndexOf'),
'map' : require('./array/map'),
'max' : require('./array/max'),
'min' : require('./array/min'),
'pick' : require('./array/pick'),
'pluck' : require('./array/pluck'),
'range' : require('./array/range'),
'reduce' : require('./array/reduce'),
'reduceRight' : require('./array/reduceRight'),
'reject' : require('./array/reject'),
'remove' : require('./array/remove'),
'removeAll' : require('./array/removeAll'),
'shuffle' : require('./array/shuffle'),
'some' : require('./array/some'),
'sort' : require('./array/sort'),
'split' : require('./array/split'),
'toLookup' : require('./array/toLookup'),
'union' : require('./array/union'),
'unique' : require('./array/unique'),
'xor' : require('./array/xor'),
'zip' : require('./array/zip')
};
});
define(function () {
/**
* Appends an array to the end of another.
* The first array will be modified.
*/
function append(arr1, arr2) {
if (arr2 == null) {
return arr1;
}
var pad = arr1.length,
i = -1,
len = arr2.length;
while (++i < len) {
arr1[pad + i] = arr2[i];
}
return arr1;
}
return append;
});
define(['./append', '../function/makeIterator_'], function (append, makeIterator) {
/**
* Maps the items in the array and concatenates the result arrays.
*/
function collect(arr, callback, thisObj){
callback = makeIterator(callback, thisObj);
var results = [];
if (arr == null) {
return results;
}
var i = -1, len = arr.length;
while (++i < len) {
var value = callback(arr[i], i, arr);
if (value != null) {
append(results, value);
}
}
return results;
}
return collect;
});
define(['./indexOf'], function (indexOf) {
/**
* Combines an array with all the items of another.
* Does not allow duplicates and is case and type sensitive.
*/
function combine(arr1, arr2) {
if (arr2 == null) {
return arr1;
}
var i = -1, len = arr2.length;
while (++i < len) {
if (indexOf(arr1, arr2[i]) === -1) {
arr1.push(arr2[i]);
}
}
return arr1;
}
return combine;
});
define(['./filter'], function (filter) {
/**
* Remove all null/undefined items from array.
*/
function compact(arr) {
return filter(arr, function(val){
return (val != null);
});
}
return compact;
});
define(['./indexOf'], function (indexOf) {
/**
* If array contains values.
*/
function contains(arr, val) {
return indexOf(arr, val) !== -1;
}
return contains;
});
define(['./unique', './filter', './some', './contains'], function (unique, filter, some, contains) {
/**
* Return a new Array with elements that aren't present in the other Arrays.
*/
function difference(arr) {
var arrs = Array.prototype.slice.call(arguments, 1),
result = filter(unique(arr), function(needle){
return !some(arrs, function(haystack){
return contains(haystack, needle);
});
});
return result;
}
return difference;
});
define(['../function/makeIterator_'], function (makeIterator) {
/**
* Array every
*/
function every(arr, callback, thisObj) {
callback = makeIterator(callback, thisObj);
var result = true;
if (arr == null) {
return result;
}
var i = -1, len = arr.length;
while (++i < len) {
// we iterate over sparse items since there is no way to make it
// work properly on IE 7-8. see #64
if (!callback(arr[i], i, arr) ) {
result = false;
break;
}
}
return result;
}
return every;
});
define(['../function/makeIterator_'], function (makeIterator) {
/**
* Array filter
*/
function filter(arr, callback, thisObj) {
callback = makeIterator(callback, thisObj);
var results = [];
if (arr == null) {
return results;
}
var i = -1, len = arr.length, value;
while (++i < len) {
value = arr[i];
if (callback(value, i, arr)) {
results.push(value);
}
}
return results;
}
return filter;
});
define(['./findIndex'], function (findIndex) {
/**
* Returns first item that matches criteria
*/
function find(arr, iterator, thisObj){
var idx = findIndex(arr, iterator, thisObj);
return idx >= 0? arr[idx] : void(0);
}
return find;
});
define(['../function/makeIterator_'], function (makeIterator) {
/**
* Returns the index of the first item that matches criteria
*/
function findIndex(arr, iterator, thisObj){
iterator = makeIterator(iterator, thisObj);
if (arr == null) {
return -1;
}
var i = -1, len = arr.length;
while (++i < len) {
if (iterator(arr[i], i, arr)) {
return i;
}
}
return -1;
}
return findIndex;
});
define(['../lang/isArray', './append'], function (isArray, append) {
/*
* Helper function to flatten to a destination array.
* Used to remove the need to create intermediate arrays while flattening.
*/
function flattenTo(arr, result, level) {
if (arr == null) {
return result;
} else if (level === 0) {
append(result, arr);
return result;
}
var value,
i = -1,
len = arr.length;
while (++i < len) {
value = arr[i];
if (isArray(value)) {
flattenTo(value, result, level - 1);
} else {
result.push(value);
}
}
return result;
}
/**
* Recursively flattens an array.
* A new array containing all the elements is returned.
* If `shallow` is true, it will only flatten one level.
*/
function flatten(arr, level) {
level = level == null? -1 : level;
return flattenTo(arr, [], level);
}
return flatten;
});
define(function () {
/**
* Array forEach
*/
function forEach(arr, callback, thisObj) {
if (arr == null) {
return;
}
var i = -1,
len = arr.length;
while (++i < len) {
// we iterate over sparse items since there is no way to make it
// work properly on IE 7-8. see #64
if ( callback.call(thisObj, arr[i], i, arr) === false ) {
break;
}
}
}
return forEach;
});
define(function () {
/**
* Array.indexOf
*/
function indexOf(arr, item, fromIndex) {
fromIndex = fromIndex || 0;
if (arr == null) {
return -1;
}
var len = arr.length,
i = fromIndex < 0 ? len + fromIndex : fromIndex;
while (i < len) {
// we iterate over sparse items since there is no way to make it
// work properly on IE 7-8. see #64
if (arr[i] === item) {
return i;
}
i++;
}
return -1;
}
return indexOf;
});
define(['./difference', '../lang/toArray'], function (difference, toArray) {
/**
* Insert item into array if not already present.
*/
function insert(arr, rest_items) {
var diff = difference(toArray(arguments).slice(1), arr);
if (diff.length) {
Array.prototype.push.apply(arr, diff);
}
return arr.length;
}
return insert;
});
define(['./unique', './filter', './every', './contains'], function (unique, filter, every, contains) {
/**
* Return a new Array with elements common to all Arrays.
* - based on underscore.js implementation
*/
function intersection(arr) {
var arrs = Array.prototype.slice.call(arguments, 1),
result = filter(unique(arr), function(needle){
return every(arrs, function(haystack){
return contains(haystack, needle);
});
});
return result;
}
return intersection;
});
define(function () {
/**
* Call `methodName` on each item of the array passing custom arguments if
* needed.
*/
function invoke(arr, methodName, var_args){
if (arr == null) {
return arr;
}
var args = Array.prototype.slice.call(arguments, 2);
var i = -1, len = arr.length, value;
while (++i < len) {
value = arr[i];
value[methodName].apply(value, args);
}
return arr;
}
return invoke;
});
define(['./filter'], function(filter) {
function isValidString(val) {
return (val != null && val !== '');
}
/**
* Joins strings with the specified separator inserted between each value.
* Null values and empty strings will be excluded.
*/
function join(items, separator) {
separator = separator || '';
return filter(items, isValidString).join(separator);
}
return join;
});
define(function () {
/**
* Array lastIndexOf
*/
function lastIndexOf(arr, item, fromIndex) {
if (arr == null) {
return -1;
}
var len = arr.length;
fromIndex = (fromIndex == null || fromIndex >= len)? len - 1 : fromIndex;
fromIndex = (fromIndex < 0)? len + fromIndex : fromIndex;
while (fromIndex >= 0) {
// we iterate over sparse items since there is no way to make it
// work properly on IE 7-8. see #64
if (arr[fromIndex] === item) {
return fromIndex;
}
fromIndex--;
}
return -1;
}
return lastIndexOf;
});
define(['../function/makeIterator_'], function (makeIterator) {
/**
* Array map
*/
function map(arr, callback, thisObj) {
callback = makeIterator(callback, thisObj);
var results = [];
if (arr == null){
return results;
}
var i = -1, len = arr.length;
while (++i < len) {
results[i] = callback(arr[i], i, arr);
}
return results;
}
return map;
});
define(['../function/makeIterator_'], function (makeIterator) {
/**
* Return maximum value inside array
*/
function max(arr, iterator, thisObj){
if (arr == null || !arr.length) {
return Infinity;
} else if (arr.length && !iterator) {
return Math.max.apply(Math, arr);
} else {
iterator = makeIterator(iterator, thisObj);
var result,
compare = -Infinity,
value,
temp;
var i = -1, len = arr.length;
while (++i < len) {
value = arr[i];
temp = iterator(value, i, arr);
if (temp > compare) {
compare = temp;
result = value;
}
}
return result;
}
}
return max;
});
define(['../function/makeIterator_'], function (makeIterator) {
/**
* Return minimum value inside array
*/
function min(arr, iterator, thisObj){
if (arr == null || !arr.length) {
return -Infinity;
} else if (arr.length && !iterator) {
return Math.min.apply(Math, arr);
} else {
iterator = makeIterator(iterator, thisObj);
var result,
compare = Infinity,
value,
temp;
var i = -1, len = arr.length;
while (++i < len) {
value = arr[i];
temp = iterator(value, i, arr);
if (temp < compare) {
compare = temp;
result = value;
}
}
return result;
}
}
return min;
});
define(['../random/randInt'], function (randInt) {
/**
* Remove random item(s) from the Array and return it.
* Returns an Array of items if [nItems] is provided or a single item if
* it isn't specified.
*/
function pick(arr, nItems){
if (nItems != null) {
var result = [];
if (nItems > 0 && arr && arr.length) {
nItems = nItems > arr.length? arr.length : nItems;
while (nItems--) {
result.push( pickOne(arr) );
}
}
return result;
}
return (arr && arr.length)? pickOne(arr) : void(0);
}
function pickOne(arr){
var idx = randInt(0, arr.length - 1);
return arr.splice(idx, 1)[0];
}
return pick;
});
define(['./map'], function (map) {
/**
* Extract a list of property values.
*/
function pluck(arr, propName){
return map(arr, propName);
}
return pluck;
});
define(['../math/countSteps'], function (countSteps) {
/**
* Returns an Array of numbers inside range.
*/
function range(start, stop, step) {
if (stop == null) {
stop = start;
start = 0;
}
step = step || 1;
var result = [],
nSteps = countSteps(stop - start, step),
i = start;
while (i <= stop) {
result.push(i);
i += step;
}
return result;
}
return range;
});
define(function () {
/**
* Array reduce
*/
function reduce(arr, fn, initVal) {
// check for args.length since initVal might be "undefined" see #gh-57
var hasInit = arguments.length > 2,
result = initVal;
if (arr == null || !arr.length) {
if (!hasInit) {
throw new Error('reduce of empty array with no initial value');
} else {
return initVal;
}
}
var i = -1, len = arr.length;
while (++i < len) {
if (!hasInit) {
result = arr[i];
hasInit = true;
} else {
result = fn(result, arr[i], i, arr);
}
}
return result;
}
return reduce;
});
define(function () {
/**
* Array reduceRight
*/
function reduceRight(arr, fn, initVal) {
// check for args.length since initVal might be "undefined" see #gh-57
var hasInit = arguments.length > 2;
if (arr == null || !arr.length) {
if (hasInit) {
return initVal;
} else {
throw new Error('reduce of empty array with no initial value');
}
}
var i = arr.length, result = initVal, value;
while (--i >= 0) {
// we iterate over sparse items since there is no way to make it
// work properly on IE 7-8. see #64
value = arr[i];
if (!hasInit) {
result = value;
hasInit = true;
} else {
result = fn(result, value, i, arr);
}
}
return result;
}
return reduceRight;
});
define(['../function/makeIterator_'], function(makeIterator) {
/**
* Array reject
*/
function reject(arr, callback, thisObj) {
callback = makeIterator(callback, thisObj);
var results = [];
if (arr == null) {
return results;
}
var i = -1, len = arr.length, value;
while (++i < len) {
value = arr[i];
if (!callback(value, i, arr)) {
results.push(value);
}
}
return results;
}
return reject;
});
define(['./indexOf'], function(indexOf){
/**
* Remove a single item from the array.
* (it won't remove duplicates, just a single item)
*/
function remove(arr, item){
var idx = indexOf(arr, item);
if (idx !== -1) arr.splice(idx, 1);
}
return remove;
});
define(['./indexOf'], function(indexOf){
/**
* Remove all instances of an item from array.
*/
function removeAll(arr, item){
var idx = indexOf(arr, item);
while (idx !== -1) {
arr.splice(idx, 1);
idx = indexOf(arr, item, idx);
}
}
return removeAll;
});
define(['../random/randInt'], function (randInt) {
/**
* Shuffle array items.
*/
function shuffle(arr) {
var results = [],
rnd;
if (arr == null) {
return results;
}
var i = -1, len = arr.length, value;
while (++i < len) {
if (!i) {
results[0] = arr[0];
} else {
rnd = randInt(0, i);
results[i] = results[rnd];
results[rnd] = arr[i];
}
}
return results;
}
return shuffle;
});
define(['../function/makeIterator_'], function (makeIterator) {
/**
* Array some
*/
function some(arr, callback, thisObj) {
callback = makeIterator(callback, thisObj);
var result = false;
if (arr == null) {
return result;
}
var i = -1, len = arr.length;
while (++i < len) {
// we iterate over sparse items since there is no way to make it
// work properly on IE 7-8. see #64
if ( callback(arr[i], i, arr) ) {
result = true;
break;
}
}
return result;
}
return some;
});
define(function () {
/**
* Merge sort (http://en.wikipedia.org/wiki/Merge_sort)
*/
function mergeSort(arr, compareFn) {
if (arr == null) {
return [];
} else if (arr.length < 2) {
return arr;
}
if (compareFn == null) {
compareFn = defaultCompare;
}
var mid, left, right;
mid = ~~(arr.length / 2);
left = mergeSort( arr.slice(0, mid), compareFn );
right = mergeSort( arr.slice(mid, arr.length), compareFn );
return merge(left, right, compareFn);
}
function defaultCompare(a, b) {
return a < b ? -1 : (a > b? 1 : 0);
}
function merge(left, right, compareFn) {
var result = [];
while (left.length && right.length) {
if (compareFn(left[0], right[0]) <= 0) {
// if 0 it should preserve same order (stable)
result.push(left.shift());
} else {
result.push(right.shift());
}
}
if (left.length) {
result.push.apply(result, left);
}
if (right.length) {
result.push.apply(result, right);
}
return result;
}
return mergeSort;
});
define(function() {
/**
* Split array into a fixed number of segments.
*/
function split(array, segments) {
segments = segments || 2;
var results = [];
if (array == null) {
return results;
}
var minLength = Math.floor(array.length / segments),
remainder = array.length % segments,
i = 0,
len = array.length,
segmentIndex = 0,
segmentLength;
while (i < len) {
segmentLength = minLength;
if (segmentIndex < remainder) {
segmentLength++;
}
results.push(array.slice(i, i + segmentLength));
segmentIndex++;
i += segmentLength;
}
return results;
}
return split;
});
define(['../lang/isFunction'], function (isFunction) {
/**
* Creates an object that holds a lookup for the objects in the array.
*/
function toLookup(arr, key) {
var result = {};
if (arr == null) {
return result;
}
var i = -1, len = arr.length, value;
if (isFunction(key)) {
while (++i < len) {
value = arr[i];
result[key(value)] = value;
}
} else {
while (++i < len) {
value = arr[i];
result[value[key]] = value;
}
}
return result;
}
return toLookup;
});
define(['./unique', './append'], function (unique, append) {
/**
* Concat multiple arrays and remove duplicates
*/
function union(arrs) {
var results = [];
var i = -1, len = arguments.length;
while (++i < len) {
append(results, arguments[i]);
}
return unique(results);
}
return union;
});
define(['./indexOf', './filter'], function(indexOf, filter){
/**
* @return {array} Array of unique items
*/
function unique(arr){
return filter(arr, isUnique);
}
function isUnique(item, i, arr){
return indexOf(arr, item, i+1) === -1;
}
return unique;
});
define(['./unique', './filter', './contains'], function (unique, filter, contains) {
/**
* Exclusive OR. Returns items that are present in a single array.
* - like ptyhon's `symmetric_difference`
*/
function xor(arr1, arr2) {
arr1 = unique(arr1);
arr2 = unique(arr2);
var a1 = filter(arr1, function(item){
return !contains(arr2, item);
}),
a2 = filter(arr2, function(item){
return !contains(arr1, item);
});
return a1.concat(a2);
}
return xor;
});
define(['./max', './map'], function (max, map) {
function getLength(arr) {
return arr == null ? 0 : arr.length;
}
/**
* Merges together the values of each of the arrays with the values at the
* corresponding position.
*/
function zip(arr){
var len = arr ? max(map(arguments, getLength)) : 0,
results = [],
i = -1;
while (++i < len) {
// jshint loopfunc: true
results.push(map(arguments, function(item) {
return item == null ? undefined : item[i];
}));
}
return results;
}
return zip;
});
define(function(require){
//automatically generated, do not edit!
//run `node build` instead
return {
'contains' : require('./collection/contains'),
'every' : require('./collection/every'),
'filter' : require('./collection/filter'),
'find' : require('./collection/find'),
'forEach' : require('./collection/forEach'),
'make_' : require('./collection/make_'),
'map' : require('./collection/map'),
'max' : require('./collection/max'),
'min' : require('./collection/min'),
'pluck' : require('./collection/pluck'),
'reduce' : require('./collection/reduce'),
'reject' : require('./collection/reject'),
'size' : require('./collection/size'),
'some' : require('./collection/some')
};
});
define(['./make_', '../array/contains', '../object/contains'], function (make, arrContains, objContains) {
/**
*/
return make(arrContains, objContains);
});
define(['./make_', '../array/every', '../object/every'], function (make, arrEvery, objEvery) {
/**
*/
return make(arrEvery, objEvery);
});
define(['./forEach', '../function/makeIterator_'], function (forEach, makeIterator) {
/**
* filter collection values, returns array.
*/
function filter(list, iterator, thisObj) {
iterator = makeIterator(iterator, thisObj);
var results = [];
if (!list) {
return results;
}
forEach(list, function(value, index, list) {
if (iterator(value, index, list)) {
results[results.length] = value;
}
});
return results;
}
return filter;
});
define(['./make_', '../array/find', '../object/find'], function(make, arrFind, objFind) {
/**
* Find value that returns true on iterator check.
*/
return make(arrFind, objFind);
});
define(['./make_', '../array/forEach', '../object/forOwn'], function (make, arrForEach, objForEach) {
/**
*/
return make(arrForEach, objForEach);
});
define(function(){
/**
* internal method used to create other collection modules.
*/
function makeCollectionMethod(arrMethod, objMethod, defaultReturn) {
return function(){
var args = Array.prototype.slice.call(arguments);
if (args[0] == null) {
return defaultReturn;
}
// array-like is treated as array
return (typeof args[0].length === 'number')? arrMethod.apply(null, args) : objMethod.apply(null, args);
};
}
return makeCollectionMethod;
});
define(['../lang/isObject', '../object/values', '../array/map', '../function/makeIterator_'], function (isObject, values, arrMap, makeIterator) {
/**
* Map collection values, returns Array.
*/
function map(list, callback, thisObj) {
callback = makeIterator(callback, thisObj);
// list.length to check array-like object, if not array-like
// we simply map all the object values
if( isObject(list) && list.length == null ){
list = values(list);
}
return arrMap(list, function (val, key, list) {
return callback(val, key, list);
});
}
return map;
});
define(['./make_', '../array/max', '../object/max'], function (make, arrMax, objMax) {
/**
* Get maximum value inside collection
*/
return make(arrMax, objMax);
});
define(['./make_', '../array/min', '../object/min'], function (make, arrMin, objMin) {
/**
* Get minimum value inside collection.
*/
return make(arrMin, objMin);
});
define(['./map'], function (map) {
/**
* Extract a list of property values.
*/
function pluck(list, key) {
return map(list, function(value) {
return value[key];
});
}
return pluck;
});
define(['./make_', '../array/reduce', '../object/reduce'], function (make, arrReduce, objReduce) {
/**
*/
return make(arrReduce, objReduce);
});
define(['./filter', '../function/makeIterator_'], function (filter, makeIterator) {
/**
* Inverse or collection/filter
*/
function reject(list, iterator, thisObj) {
iterator = makeIterator(iterator, thisObj);
return filter(list, function(value, index, list) {
return !iterator(value, index, list);
}, thisObj);
}
return reject;
});
define(['../lang/isArray', '../object/size'], function (isArray, objSize) {
/**
* Get collection size
*/
function size(list) {
if (!list) {
return 0;
}
if (isArray(list)) {
return list.length;
}
return objSize(list);
}
return size;
});
define(['./make_', '../array/some', '../object/some'], function (make, arrSome, objSome) {
/**
*/
return make(arrSome, objSome);
});
define(function(require){
//automatically generated, do not edit!
//run `node build` instead
return {
'dayOfTheYear' : require('./date/dayOfTheYear'),
'diff' : require('./date/diff'),
'i18n_' : require('./date/i18n_'),
'isLeapYear' : require('./date/isLeapYear'),
'isSame' : require('./date/isSame'),
'parseIso' : require('./date/parseIso'),
'startOf' : require('./date/startOf'),
'strftime' : require('./date/strftime'),
'timezoneAbbr' : require('./date/timezoneAbbr'),
'timezoneOffset' : require('./date/timezoneOffset'),
'totalDaysInMonth' : require('./date/totalDaysInMonth'),
'totalDaysInYear' : require('./date/totalDaysInYear'),
'weekOfTheYear' : require('./date/weekOfTheYear')
};
});
define(['../lang/isDate'], function (isDate) {
/**
* return the day of the year (1..366)
*/
function dayOfTheYear(date){
return (Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()) -
Date.UTC(date.getFullYear(), 0, 1)) / 86400000 + 1;
}
return dayOfTheYear;
});
define(['./totalDaysInMonth', './totalDaysInYear', '../time/convert'], function(totalDaysInMonth, totalDaysInYear, convert){
/**
* calculate the difference between dates (range)
*/
function diff(start, end, unitName){
// sort the dates to make it easier to process (specially year/month)
if (start > end) {
var swap = start;
start = end;
end = swap;
}
var output;
if (unitName === 'month') {
output = getMonthsDiff(start, end);
} else if (unitName === 'year'){
output = getYearsDiff(start, end);
} else if (unitName != null) {
if (unitName === 'day') {
// ignore timezone difference because of daylight savings time
start = toUtc(start);
end = toUtc(end);
}
output = convert(end - start, 'ms', unitName);
} else {
output = end - start;
}
return output;
}
function toUtc(d){
// we ignore timezone differences on purpose because of daylight
// savings time, otherwise it would return fractional days/weeks even
// if a full day elapsed. eg:
// Wed Feb 12 2014 00:00:00 GMT-0200 (BRST)
// Sun Feb 16 2014 00:00:00 GMT-0300 (BRT)
// diff should be 4 days and not 4.041666666666667
return Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(),
d.getHours(), d.getMinutes(), d.getSeconds(),
d.getMilliseconds());
}
function getMonthsDiff(start, end){
return getElapsedMonths(start, end) +
getElapsedYears(start, end) * 12 +
getFractionalMonth(start, end);
}
function getYearsDiff(start, end){
var elapsedYears = getElapsedYears(start, end);
return elapsedYears + getFractionalYear(start, end, elapsedYears);
}
function getElapsedMonths(start, end){
var monthDiff = end.getMonth() - start.getMonth();
if (monthDiff < 0) {
monthDiff += 12;
}
// less than a full month
if (start.getDate() > end.getDate()) {
monthDiff -= 1;
}
return monthDiff;
}
function getElapsedYears(start, end){
var yearDiff = end.getFullYear() - start.getFullYear();
// less than a full year
if (start.getMonth() > end.getMonth()) {
yearDiff -= 1;
}
return yearDiff;
}
function getFractionalMonth(start, end){
var fractionalDiff = 0;
var startDay = start.getDate();
var endDay = end.getDate();
if (startDay !== endDay) {
var startTotalDays = totalDaysInMonth(start);
var endTotalDays = totalDaysInMonth(end);
var totalDays;
var daysElapsed;
if (startDay > endDay) {
// eg: Jan 29 - Feb 27 (29 days elapsed but not a full month)
var baseDay = startTotalDays - startDay;
daysElapsed = endDay + baseDay;
// total days should be relative to 1st day of next month if
// startDay > endTotalDays
totalDays = (startDay > endTotalDays)?
endTotalDays + baseDay + 1 : startDay + baseDay;
} else {
// fractional is only based on endMonth eg: Jan 12 - Feb 18
// (6 fractional days, 28 days until next full month)
daysElapsed = endDay - startDay;
totalDays = endTotalDays;
}
fractionalDiff = daysElapsed / totalDays;
}
return fractionalDiff;
}
function getFractionalYear(start, end, elapsedYears){
var base = elapsedYears?
new Date(end.getFullYear(), start.getMonth(), start.getDate()) :
start;
var elapsedDays = diff(base, end, 'day');
return elapsedDays / totalDaysInYear(end);
}
return diff;
});
define(function(){
// de-DE (German)
return {
"am" : "",
"pm" : "",
"x": "%d/%m/%y",
"X": "%H:%M:%S",
"c": "%a %d %b %Y %H:%M:%S %Z",
"months" : [
"Januar",
"Februar",
"März",
"April",
"Mai",
"Juni",
"Juli",
"August",
"September",
"Oktober",
"November",
"Dezember"
],
"months_abbr" : [
"Jan",
"Febr",
"März",
"Apr",
"Mai",
"Juni",
"Juli",
"Aug",
"Sept",
"Okt",
"Nov",
"Dez"
],
"days" : [
"Sonntag",
"Montag",
"Dienstag",
"Mittwoch",
"Donnerstag",
"Freitag",
"Samstag"
],
"days_abbr" : [
"So",
"Mo",
"Di",
"Mi",
"Do",
"Fr",
"Sa"
]
};
});
define(function(){
// en-US (English, United States)
return {
"am" : "AM",
"pm" : "PM",
"x": "%m/%d/%y",
"X": "%H:%M:%S",
"c": "%a %d %b %Y %I:%M:%S %p %Z",
"months" : [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
],
"months_abbr" : [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
],
"days" : [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
],
"days_abbr" : [
"Sun",
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat"
]
};
});
define(function(){
// pt-BR (Brazillian Portuguese)
return {
"am" : "",
"pm" : "",
"x": "%d/%m/%y",
"X": "%H:%M:%S",
"c": "%a %d %b %Y %H:%M:%S %Z",
"months" : [
"Janeiro",
"Fevereiro",
"Março",
"Abril",
"Maio",
"Junho",
"Julho",
"Agosto",
"Setembro",
"Outubro",
"Novembro",
"Dezembro"
],
"months_abbr" : [
"Jan",
"Fev",
"Mar",
"Abr",
"Mai",
"Jun",
"Jul",
"Ago",
"Set",
"Out",
"Nov",
"Dez"
],
"days" : [
"Domingo",
"Segunda",
"Terça",
"Quarta",
"Quinta",
"Sexta",
"Sábado"
],
"days_abbr" : [
"Dom",
"Seg",
"Ter",
"Qua",
"Qui",
"Sex",
"Sáb"
]
};
});
define(['../object/mixIn', './i18n/en-US'], function(mixIn, enUS){
// we also use mixIn to make sure we don't affect the original locale
var activeLocale = mixIn({}, enUS, {
// we expose a "set" method to allow overriding the global locale
set : function(localeData){
mixIn(activeLocale, localeData);
}
});
return activeLocale;
});
define(['../lang/isDate'], function (isDate) {
/**
* checks if it's a leap year
*/
function isLeapYear(fullYear){
if (isDate(fullYear)) {
fullYear = fullYear.getFullYear();
}
return fullYear % 400 === 0 || (fullYear % 100 !== 0 && fullYear % 4 === 0);
}
return isLeapYear;
});
define(['./startOf'], function (startOf) {
/**
* Check if date is "same" with optional period
*/
function isSame(date1, date2, period){
if (period) {
date1 = startOf(date1, period);
date2 = startOf(date2, period);
}
return Number(date1) === Number(date2);
}
return isSame;
});
define(['../array/some'], function (some) {
var datePatterns = [
/^([0-9]{4})$/, // YYYY
/^([0-9]{4})-([0-9]{2})$/, // YYYY-MM (YYYYMM not allowed)
/^([0-9]{4})-?([0-9]{2})-?([0-9]{2})$/ // YYYY-MM-DD or YYYYMMDD
];
var ORD_DATE = /^([0-9]{4})-?([0-9]{3})$/; // YYYY-DDD
var timePatterns = [
/^([0-9]{2}(?:\.[0-9]*)?)$/, // HH.hh
/^([0-9]{2}):?([0-9]{2}(?:\.[0-9]*)?)$/, // HH:MM.mm
/^([0-9]{2}):?([0-9]{2}):?([0-9]{2}(\.[0-9]*)?)$/ // HH:MM:SS.ss
];
var DATE_TIME = /^(.+)T(.+)$/;
var TIME_ZONE = /^(.+)([+\-])([0-9]{2}):?([0-9]{2})$/;
function matchAll(str, patterns) {
var match;
var found = some(patterns, function(pattern) {
return !!(match = pattern.exec(str));
});
return found ? match : null;
}
function getDate(year, month, day) {
var date = new Date(Date.UTC(year, month, day));
// Explicitly set year to avoid Date.UTC making dates < 100 relative to
// 1900
date.setUTCFullYear(year);
var valid =
date.getUTCFullYear() === year &&
date.getUTCMonth() === month &&
date.getUTCDate() === day;
return valid ? +date : NaN;
}
function parseOrdinalDate(str) {
var match = ORD_DATE.exec(str);
if (match ) {
var year = +match[1],
day = +match[2],
date = new Date(Date.UTC(year, 0, day));
if (date.getUTCFullYear() === year) {
return +date;
}
}
return NaN;
}
function parseDate(str) {
var match, year, month, day;
match = matchAll(str, datePatterns);
if (match === null) {
// Ordinal dates are verified differently.
return parseOrdinalDate(str);
}
year = (match[1] === void 0) ? 0 : +match[1];
month = (match[2] === void 0) ? 0 : +match[2] - 1;
day = (match[3] === void 0) ? 1 : +match[3];
return getDate(year, month, day);
}
function getTime(hr, min, sec) {
var valid =
(hr < 24 && hr >= 0 &&
min < 60 && min >= 0 &&
sec < 60 && min >= 0) ||
(hr === 24 && min === 0 && sec === 0);
if (!valid) {
return NaN;
}
return ((hr * 60 + min) * 60 + sec) * 1000;
}
function parseOffset(str) {
var match;
if (str.charAt(str.length - 1) === 'Z') {
str = str.substring(0, str.length - 1);
} else {
match = TIME_ZONE.exec(str);
if (match) {
var hours = +match[3],
minutes = (match[4] === void 0) ? 0 : +match[4],
offset = getTime(hours, minutes, 0);
if (match[2] === '-') {
offset *= -1;
}
return { offset: offset, time: match[1] };
}
}
// No time zone specified, assume UTC
return { offset: 0, time: str };
}
function parseTime(str) {
var match;
var offset = parseOffset(str);
str = offset.time;
offset = offset.offset;
if (isNaN(offset)) {
return NaN;
}
match = matchAll(str, timePatterns);
if (match === null) {
return NaN;
}
var hours = (match[1] === void 0) ? 0 : +match[1],
minutes = (match[2] === void 0) ? 0 : +match[2],
seconds = (match[3] === void 0) ? 0 : +match[3];
return getTime(hours, minutes, seconds) - offset;
}
/**
* Parse an ISO8601 formatted date string, and return a Date object.
*/
function parseISO8601(str){
var match = DATE_TIME.exec(str);
if (!match) {
// No time specified
return parseDate(str);
}
return parseDate(match[1]) + parseTime(match[2]);
}
return parseISO8601;
});
define(['../lang/clone'], function (clone) {
/**
* get a new Date object representing start of period
*/
function startOf(date, period){
date = clone(date);
// intentionally removed "break" from switch since start of
// month/year/etc should also reset the following periods
switch (period) {
case 'year':
date.setMonth(0);
/* falls through */
case 'month':
date.setDate(1);
/* falls through */
case 'week':
case 'day':
date.setHours(0);
/* falls through */
case 'hour':
date.setMinutes(0);
/* falls through */
case 'minute':
date.setSeconds(0);
/* falls through */
case 'second':
date.setMilliseconds(0);
break;
default:
throw new Error('"'+ period +'" is not a valid period');
}
// week is the only case that should reset the weekDay and maybe even
// overflow to previous month
if (period === 'week') {
var weekDay = date.getDay();
var baseDate = date.getDate();
if (weekDay) {
if (weekDay >= baseDate) {
//start of the week is on previous month
date.setDate(0);
}
date.setDate(date.getDate() - date.getDay());
}
}
return date;
}
return startOf;
});
define(['../number/pad', './i18n_', './dayOfTheYear', './timezoneOffset', './timezoneAbbr', './weekOfTheYear'], function (pad, i18n, dayOfTheYear, timezoneOffset, timezoneAbbr, weekOfTheYear) {
var _combinations = {
'D': '%m/%d/%y',
'F': '%Y-%m-%d',
'r': '%I:%M:%S %p',
'R': '%H:%M',
'T': '%H:%M:%S',
'x': 'locale',
'X': 'locale',
'c': 'locale'
};
/**
* format date based on strftime format
*/
function strftime(date, format, localeData){
localeData = localeData || i18n;
var reToken = /%([a-z%])/gi;
function makeIterator(fn) {
return function(match, token){
return fn(date, token, localeData);
};
}
return format
.replace(reToken, makeIterator(expandCombinations))
.replace(reToken, makeIterator(convertToken));
}
function expandCombinations(date, token, l10n){
if (token in _combinations) {
var expanded = _combinations[token];
return expanded === 'locale'? l10n[token] : expanded;
} else {
return '%'+ token;
}
}
function convertToken(date, token, l10n){
switch (token){
case 'a':
return l10n.days_abbr[date.getDay()];
case 'A':
return l10n.days[date.getDay()];
case 'h':
case 'b':
return l10n.months_abbr[date.getMonth()];
case 'B':
return l10n.months[date.getMonth()];
case 'C':
return pad(Math.floor(date.getFullYear() / 100), 2);
case 'd':
return pad(date.getDate(), 2);
case 'e':
return pad(date.getDate(), 2, ' ');
case 'H':
return pad(date.getHours(), 2);
case 'I':
return pad(date.getHours() % 12, 2);
case 'j':
return pad(dayOfTheYear(date), 3);
case 'L':
return pad(date.getMilliseconds(), 3);
case 'm':
return pad(date.getMonth() + 1, 2);
case 'M':
return pad(date.getMinutes(), 2);
case 'n':
return '\n';
case 'p':
return date.getHours() >= 12? l10n.pm : l10n.am;
case 'P':
return convertToken(date, 'p', l10n).toLowerCase();
case 's':
return date.getTime() / 1000;
case 'S':
return pad(date.getSeconds(), 2);
case 't':
return '\t';
case 'u':
var day = date.getDay();
return day === 0? 7 : day;
case 'U':
return pad(weekOfTheYear(date), 2);
case 'w':
return date.getDay();
case 'W':
return pad(weekOfTheYear(date, 1), 2);
case 'y':
return pad(date.getFullYear() % 100, 2);
case 'Y':
return pad(date.getFullYear(), 4);
case 'z':
return timezoneOffset(date);
case 'Z':
return timezoneAbbr(date);
case '%':
return '%';
default:
// keep unrecognized tokens
return '%'+ token;
}
}
return strftime;
});
define(['./timezoneOffset'], function(timezoneOffset) {
/**
* Abbreviated time zone name or similar information.
*/
function timezoneAbbr(date){
// Date.toString gives different results depending on the
// browser/system so we fallback to timezone offset
// chrome: 'Mon Apr 08 2013 09:02:04 GMT-0300 (BRT)'
// IE: 'Mon Apr 8 09:02:04 UTC-0300 2013'
var tz = /\(([A-Z]{3,4})\)/.exec(date.toString());
return tz? tz[1] : timezoneOffset(date);
}
return timezoneAbbr;
});
define(['../number/pad'], function (pad) {
/**
* time zone as hour and minute offset from UTC (e.g. +0900)
*/
function timezoneOffset(date){
var offset = date.getTimezoneOffset();
var abs = Math.abs(offset);
var h = pad(Math.floor(abs / 60), 2);
var m = pad(abs % 60, 2);
return (offset > 0? '-' : '+') + h + m;
}
return timezoneOffset;
});
define(['../lang/isDate', './isLeapYear'], function (isDate, isLeapYear) {
var DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
/**
* returns the total amount of days in the month (considering leap years)
*/
function totalDaysInMonth(fullYear, monthIndex){
if (isDate(fullYear)) {
var date = fullYear;
year = date.getFullYear();
monthIndex = date.getMonth();
}
if (monthIndex === 1 && isLeapYear(fullYear)) {
return 29;
} else {
return DAYS_IN_MONTH[monthIndex];
}
}
return totalDaysInMonth;
});
define(['./isLeapYear'], function (isLeapYear) {
/**
* return the amount of days in the year following the gregorian calendar
* and leap years
*/
function totalDaysInYear(fullYear){
return isLeapYear(fullYear)? 366 : 365;
}
return totalDaysInYear;
});
define(['./dayOfTheYear'], function (dayOfTheYear) {
/**
* Return the week of the year based on given firstDayOfWeek
*/
function weekOfTheYear(date, firstDayOfWeek){
firstDayOfWeek = firstDayOfWeek == null? 0 : firstDayOfWeek;
var doy = dayOfTheYear(date);
var dow = (7 + date.getDay() - firstDayOfWeek) % 7;
var relativeWeekDay = 6 - firstDayOfWeek - dow;
return Math.floor((doy + relativeWeekDay) / 7);
}
return weekOfTheYear;
});
define(function(require){
//automatically generated, do not edit!
//run `node build` instead
return {
'bind' : require('./function/bind'),
'compose' : require('./function/compose'),
'debounce' : require('./function/debounce'),
'func' : require('./function/func'),
'makeIterator_' : require('./function/makeIterator_'),
'partial' : require('./function/partial'),
'prop' : require('./function/prop'),
'series' : require('./function/series'),
'throttle' : require('./function/throttle'),
'timeout' : require('./function/timeout'),
'times' : require('./function/times')
};
});
define(function(){
function slice(arr, offset){
return Array.prototype.slice.call(arr, offset || 0);
}
/**
* Return a function that will execute in the given context, optionally adding any additional supplied parameters to the beginning of the arguments collection.
* @param {Function} fn Function.
* @param {object} context Execution context.
* @param {rest} args Arguments (0...n arguments).
* @return {Function} Wrapped Function.
*/
function bind(fn, context, args){
var argsArr = slice(arguments, 2); //curried args
return function(){
return fn.apply(context, argsArr.concat(slice(arguments)));
};
}
return bind;
});
define(function () {
/**
* Returns a function that composes multiple functions, passing results to
* each other.
*/
function compose() {
var fns = arguments;
return function(arg){
// only cares about the first argument since the chain can only
// deal with a single return value anyway. It should start from
// the last fn.
var n = fns.length;
while (n--) {
arg = fns[n].call(this, arg);
}
return arg;
};
}
return compose;
});
define(function () {
/**
* Debounce callback execution
*/
function debounce(fn, threshold, isAsap){
var timeout, result;
function debounced(){
var args = arguments, context = this;
function delayed(){
if (! isAsap) {
result = fn.apply(context, args);
}
timeout = null;
}
if (timeout) {
clearTimeout(timeout);
} else if (isAsap) {
result = fn.apply(context, args);
}
timeout = setTimeout(delayed, threshold);
return result;
}
debounced.cancel = function(){
clearTimeout(timeout);
};
return debounced;
}
return debounce;
});
define(function () {
/**
* Returns a function that call a method on the passed object
*/
function func(name){
return function(obj){
return obj[name]();
};
}
return func;
});
...@@ -7,22 +7,19 @@ define(['./prop', '../object/deepMatches'], function(prop, deepMatches) { ...@@ -7,22 +7,19 @@ define(['./prop', '../object/deepMatches'], function(prop, deepMatches) {
*/ */
function makeIterator(src, thisObj){ function makeIterator(src, thisObj){
switch(typeof src) { switch(typeof src) {
case 'function':
// function is the first to improve perf (most common case)
return (typeof thisObj !== 'undefined')? function(val, i, arr){
return src.call(thisObj, val, i, arr);
} : src;
case 'object': case 'object':
// typeof null == "object" // typeof null == "object"
return (src != null)? function(val, key, target){ return (src != null)? function(val){
return deepMatches(val, src); return deepMatches(val, src);
} : src; } : src;
case 'string': case 'string':
case 'number': case 'number':
return prop(src); return prop(src);
case 'function':
if (typeof thisObj === 'undefined') {
return src;
} else {
return function(val, i, arr){
return src.call(thisObj, val, i, arr);
};
}
default: default:
return src; return src;
} }
......
define(function () {
function slice(arr, offset){
return Array.prototype.slice.call(arr, offset || 0);
}
/**
* Creates a partially applied function.
*/
function partial(fn, var_args){
var argsArr = slice(arguments, 1); //curried args
return function(){
return fn.apply(this, argsArr.concat(slice(arguments)));
};
}
return partial;
});
define(function () {
/**
* Returns a function that will execute a list of functions in sequence
* passing the same arguments to each one. (useful for batch processing
* items during a forEach loop)
*/
function series(){
var fns = arguments;
return function(){
var i = 0,
n = fns.length;
while (i < n) {
fns[i].apply(this, arguments);
i += 1;
}
};
}
return series;
});
define(['../time/now'], function (now) {
/**
*/
function throttle(fn, delay){
var context, timeout, result, args,
cur, diff, prev = 0;
function delayed(){
prev = now();
timeout = null;
result = fn.apply(context, args);
}
function throttled(){
context = this;
args = arguments;
cur = now();
diff = delay - (cur - prev);
if (diff <= 0) {
clearTimeout(timeout);
prev = cur;
result = fn.apply(context, args);
} else if (! timeout) {
timeout = setTimeout(delayed, diff);
}
return result;
}
throttled.cancel = function(){
clearTimeout(timeout);
};
return throttled;
}
return throttle;
});
define(function () {
function slice(arr, offset){
return Array.prototype.slice.call(arr, offset || 0);
}
/**
* Delays the call of a function within a given context.
*/
function timeout(fn, millis, context){
var args = slice(arguments, 3);
return setTimeout(function() {
fn.apply(context, args);
}, millis);
}
return timeout;
});
define(function () {
/**
* Iterates over a callback a set amount of times
*/
function times(n, callback, thisObj){
var i = -1;
while (++i < n) {
if ( callback.call(thisObj, i) === false ) {
break;
}
}
}
return times;
});
/**@license
* mout v0.7.1 | http://moutjs.com | MIT license
*/
define(function(require){
//automatically generated, do not edit!
//run `node build` instead
return {
'VERSION' : '0.7.1',
'array' : require('./array'),
'collection' : require('./collection'),
'date' : require('./date'),
'function' : require('./function'),
'lang' : require('./lang'),
'math' : require('./math'),
'number' : require('./number'),
'object' : require('./object'),
'queryString' : require('./queryString'),
'random' : require('./random'),
'string' : require('./string'),
'time' : require('./time'),
'fn' : require('./function')
};
});
define(function(require){
//automatically generated, do not edit!
//run `node build` instead
return {
'clone' : require('./lang/clone'),
'createObject' : require('./lang/createObject'),
'ctorApply' : require('./lang/ctorApply'),
'deepClone' : require('./lang/deepClone'),
'defaults' : require('./lang/defaults'),
'inheritPrototype' : require('./lang/inheritPrototype'),
'is' : require('./lang/is'),
'isArguments' : require('./lang/isArguments'),
'isArray' : require('./lang/isArray'),
'isBoolean' : require('./lang/isBoolean'),
'isDate' : require('./lang/isDate'),
'isEmpty' : require('./lang/isEmpty'),
'isFinite' : require('./lang/isFinite'),
'isFunction' : require('./lang/isFunction'),
'isInteger' : require('./lang/isInteger'),
'isKind' : require('./lang/isKind'),
'isNaN' : require('./lang/isNaN'),
'isNull' : require('./lang/isNull'),
'isNumber' : require('./lang/isNumber'),
'isObject' : require('./lang/isObject'),
'isPlainObject' : require('./lang/isPlainObject'),
'isRegExp' : require('./lang/isRegExp'),
'isString' : require('./lang/isString'),
'isUndefined' : require('./lang/isUndefined'),
'isnt' : require('./lang/isnt'),
'kindOf' : require('./lang/kindOf'),
'toArray' : require('./lang/toArray'),
'toNumber' : require('./lang/toNumber'),
'toString' : require('./lang/toString')
};
});
define(['../object/mixIn'], function(mixIn){
/**
* Create Object using prototypal inheritance and setting custom properties.
* - Mix between Douglas Crockford Prototypal Inheritance <http://javascript.crockford.com/prototypal.html> and the EcmaScript 5 `Object.create()` method.
* @param {object} parent Parent Object.
* @param {object} [props] Object properties.
* @return {object} Created object.
*/
function createObject(parent, props){
function F(){}
F.prototype = parent;
return mixIn(new F(), props);
}
return createObject;
});
define(function () {
function F(){}
/**
* Do fn.apply on a constructor.
*/
function ctorApply(ctor, args) {
F.prototype = ctor.prototype;
var instance = new F();
ctor.apply(instance, args);
return instance;
}
return ctorApply;
});
...@@ -42,3 +42,4 @@ define(['./clone', '../object/forOwn', './kindOf', './isPlainObject'], function ...@@ -42,3 +42,4 @@ define(['./clone', '../object/forOwn', './kindOf', './isPlainObject'], function
return deepClone; return deepClone;
}); });
define(['./toArray', '../array/find'], function (toArray, find) {
/**
* Return first non void argument
*/
function defaults(var_args){
return find(toArray(arguments), nonVoid);
}
function nonVoid(val){
return val != null;
}
return defaults;
});
define(['./createObject'], function(createObject){
/**
* Inherit prototype from another Object.
* - inspired by Nicholas Zackas <http://nczonline.net> Solution
* @param {object} child Child object
* @param {object} parent Parent Object
*/
function inheritPrototype(child, parent){
var p = createObject(parent.prototype);
p.constructor = child;
child.prototype = p;
child.super_ = parent;
}
return inheritPrototype;
});
define(function () {
/**
* Check if both arguments are egal.
*/
function is(x, y){
// implementation borrowed from harmony:egal spec
if (x === y) {
// 0 === -0, but they are not identical
return x !== 0 || 1 / x === 1 / y;
}
// NaN !== NaN, but they are identical.
// NaNs are the only non-reflexive value, i.e., if x !== x,
// then x is a NaN.
// isNaN is broken: it converts its argument to number, so
// isNaN("foo") => true
return x !== x && y !== y;
}
return is;
});
define(['./isKind'], function (isKind) {
/**
*/
var isArgs = isKind(arguments, 'Arguments')?
function(val){
return isKind(val, 'Arguments');
} :
function(val){
// Arguments is an Object on IE7
return !!(val && Object.prototype.hasOwnProperty.call(val, 'callee'));
};
return isArgs;
});
define(['./isKind'], function (isKind) {
/**
*/
function isBoolean(val) {
return isKind(val, 'Boolean');
}
return isBoolean;
});
define(['./isKind'], function (isKind) {
/**
*/
function isDate(val) {
return isKind(val, 'Date');
}
return isDate;
});
define(['../object/forOwn', './isArray'], function (forOwn, isArray) {
function isEmpty(val){
if (val == null) {
// typeof null == 'object' so we check it first
return false;
} else if ( typeof val === 'string' || isArray(val) ) {
return !val.length;
} else if ( typeof val === 'object' || typeof val === 'function' ) {
var result = true;
forOwn(val, function(){
result = false;
return false; // break loop
});
return result;
} else {
return false;
}
}
return isEmpty;
});
define(['./isNumber'], function (isNumber) {
var global = this;
/**
* Check if value is finite
*/
function isFinite(val){
var is = false;
if (typeof val === 'string' && val !== '') {
is = global.isFinite( parseFloat(val) );
} else if (isNumber(val)){
// need to use isNumber because of Number constructor
is = global.isFinite( val );
}
return is;
}
return isFinite;
});
define(['./isKind'], function (isKind) {
/**
*/
function isFunction(val) {
return isKind(val, 'Function');
}
return isFunction;
});
define(['./isNumber'], function (isNumber) {
/**
* Check if value is an integer
*/
function isInteger(val){
return isNumber(val) && (val % 1 === 0);
}
return isInteger;
});
define(['./isNumber'], function (isNumber) {
/**
* Check if value is NaN for realz
*/
function isNaN(val){
// based on the fact that NaN !== NaN
// need to check if it's a number to avoid conflicts with host objects
// also need to coerce ToNumber to avoid edge case `new Number(NaN)`
// jshint eqeqeq: false
return !isNumber(val) || val != +val;
}
return isNaN;
});
define(function () {
/**
*/
function isNull(val){
return val === null;
}
return isNull;
});
define(['./isKind'], function (isKind) {
/**
*/
function isNumber(val) {
return isKind(val, 'Number');
}
return isNumber;
});
...@@ -4,9 +4,8 @@ define(function () { ...@@ -4,9 +4,8 @@ define(function () {
* Checks if the value is created by the `Object` constructor. * Checks if the value is created by the `Object` constructor.
*/ */
function isPlainObject(value) { function isPlainObject(value) {
return (!!value return (!!value && typeof value === 'object' &&
&& typeof value === 'object' value.constructor === Object);
&& value.constructor === Object);
} }
return isPlainObject; return isPlainObject;
......
define(['./isKind'], function (isKind) {
/**
*/
function isRegExp(val) {
return isKind(val, 'RegExp');
}
return isRegExp;
});
define(['./isKind'], function (isKind) {
/**
*/
function isString(val) {
return isKind(val, 'String');
}
return isString;
});
define(function () {
var UNDEF;
/**
*/
function isUndef(val){
return val === UNDEF;
}
return isUndef;
});
define(['./is'], function (is) {
/**
* Check if both values are not identical/egal
*/
function isnt(x, y){
return !is(x, y);
}
return isnt;
});
define(['./kindOf'], function (kindOf) {
var _win = this;
/**
* Convert array-like object into array
*/
function toArray(val){
var ret = [],
kind = kindOf(val),
n;
if (val != null) {
if ( val.length == null || kind === 'String' || kind === 'Function' || kind === 'RegExp' || val === _win ) {
//string, regexp, function have .length but user probably just want
//to wrap value into an array..
ret[ret.length] = val;
} else {
//window returns true on isObject in IE7 and may have length
//property. `typeof NodeList` returns `function` on Safari so
//we can't use it (#58)
n = val.length;
while (n--) {
ret[n] = val[n];
}
}
}
return ret;
}
return toArray;
});
define(['./isArray'], function (isArray) {
/**
* covert value into number if numeric
*/
function toNumber(val){
// numberic values should come first because of -0
if (typeof val === 'number') return val;
// we want all falsy values (besides -0) to return zero to avoid
// headaches
if (!val) return 0;
if (typeof val === 'string') return parseFloat(val);
// arrays are edge cases. `Number([4]) === 4`
if (isArray(val)) return NaN;
return Number(val);
}
return toNumber;
});
define(function () {
/**
* Typecast a value to a String, using an empty string value for null or
* undefined.
*/
function toString(val){
return val == null ? '' : val.toString();
}
return toString;
});
define(function(require){
//automatically generated, do not edit!
//run `node build` instead
return {
'ceil' : require('./math/ceil'),
'clamp' : require('./math/clamp'),
'countSteps' : require('./math/countSteps'),
'floor' : require('./math/floor'),
'inRange' : require('./math/inRange'),
'isNear' : require('./math/isNear'),
'lerp' : require('./math/lerp'),
'loop' : require('./math/loop'),
'map' : require('./math/map'),
'norm' : require('./math/norm'),
'round' : require('./math/round')
};
});
define(function(){
/**
* Round value up with a custom radix.
*/
function ceil(val, step){
step = Math.abs(step || 1);
return Math.ceil(val / step) * step;
}
return ceil;
});
define(function(){
/**
* Clamps value inside range.
*/
function clamp(val, min, max){
return val < min? min : (val > max? max : val);
}
return clamp;
});
define(function(){
/**
* Count number of full steps.
*/
function countSteps(val, step, overflow){
val = Math.floor(val / step);
if (overflow) {
return val % overflow;
}
return val;
}
return countSteps;
});
define(function(){
/**
* Floor value to full steps.
*/
function floor(val, step){
step = Math.abs(step || 1);
return Math.floor(val / step) * step;
}
return floor;
});
define(function(){
/**
* Checks if value is inside the range.
*/
function inRange(val, min, max, threshold){
threshold = threshold || 0;
return (val + threshold >= min && val - threshold <= max);
}
return inRange;
});
define(function(){
/**
* Check if value is close to target.
*/
function isNear(val, target, threshold){
return (Math.abs(val - target) <= threshold);
}
return isNear;
});
define(function(){
/**
* Linear interpolation.
* IMPORTANT:will return `Infinity` if numbers overflow Number.MAX_VALUE
*/
function lerp(ratio, start, end){
return start + (end - start) * ratio;
}
return lerp;
});
define(function(){
/**
* Loops value inside range.
*/
function loop(val, min, max){
return val < min? max : (val > max? min : val);
}
return loop;
});
define(['./lerp', './norm'], function(lerp, norm){
/**
* Maps a number from one scale to another.
* @example map(3, 0, 4, -1, 1) -> 0.5
*/
function map(val, min1, max1, min2, max2){
return lerp( norm(val, min1, max1), min2, max2 );
}
return map;
});
define(function(){
/**
* Gets normalized ratio of value inside range.
*/
function norm(val, min, max){
return (val - min) / (max - min);
}
return norm;
});
define(function () {
/**
* Round number to a specific radix
*/
function round(value, radix){
radix = radix || 1; // default round 1
return Math.round(value / radix) * radix;
}
return round;
});
define(function(require){
//automatically generated, do not edit!
//run `node build` instead
return {
'MAX_INT' : require('./number/MAX_INT'),
'MAX_UINT' : require('./number/MAX_UINT'),
'MIN_INT' : require('./number/MIN_INT'),
'abbreviate' : require('./number/abbreviate'),
'currencyFormat' : require('./number/currencyFormat'),
'enforcePrecision' : require('./number/enforcePrecision'),
'pad' : require('./number/pad'),
'rol' : require('./number/rol'),
'ror' : require('./number/ror'),
'sign' : require('./number/sign'),
'toInt' : require('./number/toInt'),
'toUInt' : require('./number/toUInt'),
'toUInt31' : require('./number/toUInt31')
};
});
/**
* @constant Maximum 32-bit signed integer value. (2^31 - 1)
*/
define(function(){
return 2147483647;
});
/**
* @constant Maximum 32-bit unsigned integet value (2^32 - 1)
*/
define(function(){
return 4294967295;
});
/**
* @constant Minimum 32-bit signed integer value (-2^31).
*/
define(function(){
return -2147483648;
});
define(['./enforcePrecision'], function (enforcePrecision) {
var _defaultDict = {
thousand : 'K',
million : 'M',
billion : 'B'
};
/**
* Abbreviate number if bigger than 1000. (eg: 2.5K, 17.5M, 3.4B, ...)
*/
function abbreviateNumber(val, nDecimals, dict){
nDecimals = nDecimals != null? nDecimals : 1;
dict = dict || _defaultDict;
val = enforcePrecision(val, nDecimals);
var str, mod;
if (val < 1000000) {
mod = enforcePrecision(val / 1000, nDecimals);
// might overflow to next scale during rounding
str = mod < 1000? mod + dict.thousand : 1 + dict.million;
} else if (val < 1000000000) {
mod = enforcePrecision(val / 1000000, nDecimals);
str = mod < 1000? mod + dict.million : 1 + dict.billion;
} else {
str = enforcePrecision(val / 1000000000, nDecimals) + dict.billion;
}
return str;
}
return abbreviateNumber;
});
define(['../lang/toNumber'], function (toNumber) {
/**
* Converts number into currency format
*/
function currencyFormat(val, nDecimalDigits, decimalSeparator, thousandsSeparator) {
val = toNumber(val);
nDecimalDigits = nDecimalDigits == null? 2 : nDecimalDigits;
decimalSeparator = decimalSeparator == null? '.' : decimalSeparator;
thousandsSeparator = thousandsSeparator == null? ',' : thousandsSeparator;
//can't use enforce precision since it returns a number and we are
//doing a RegExp over the string
var fixed = val.toFixed(nDecimalDigits),
//separate begin [$1], middle [$2] and decimal digits [$4]
parts = new RegExp('^(-?\\d{1,3})((?:\\d{3})+)(\\.(\\d{'+ nDecimalDigits +'}))?$').exec( fixed );
if(parts){ //val >= 1000 || val <= -1000
return parts[1] + parts[2].replace(/\d{3}/g, thousandsSeparator + '$&') + (parts[4] ? decimalSeparator + parts[4] : '');
}else{
return fixed.replace('.', decimalSeparator);
}
}
return currencyFormat;
});
define(['../lang/toNumber'], function(toNumber){
/**
* Enforce a specific amount of decimal digits and also fix floating
* point rounding issues.
*/
function enforcePrecision(val, nDecimalDigits){
val = toNumber(val);
var pow = Math.pow(10, nDecimalDigits);
return +(Math.round(val * pow) / pow).toFixed(nDecimalDigits);
}
return enforcePrecision;
});
define(['../string/lpad', '../lang/toNumber'], function(lpad, toNumber){
/**
* Add padding zeros if n.length < minLength.
*/
function pad(n, minLength, char){
n = toNumber(n);
return lpad(''+ n, minLength, char || '0');
}
return pad;
});
define(function(){
/**
* Bitwise circular shift left
* http://en.wikipedia.org/wiki/Circular_shift
*/
function rol(val, shift){
return (val << shift) | (val >> (32 - shift));
}
return rol;
});
define(function(){
/**
* Bitwise circular shift right
* http://en.wikipedia.org/wiki/Circular_shift
*/
function ror(val, shift){
return (val >> shift) | (val << (32 - shift));
}
return ror;
});
define(['../lang/toNumber'], function (toNumber) {
/**
* Get sign of the value.
*/
function sign(val) {
var num = toNumber(val);
if (num === 0) return num; // +0 and +0 === 0
if (isNaN(num)) return num; // NaN
return num < 0? -1 : 1;
}
return sign;
});
define(function(){
/**
* "Convert" value into an 32-bit integer.
* Works like `Math.floor` if val > 0 and `Math.ceil` if val < 0.
* IMPORTANT: val will wrap at 2^31 and -2^31.
* Perf tests: http://jsperf.com/vs-vs-parseint-bitwise-operators/7
*/
function toInt(val){
// we do not use lang/toNumber because of perf and also because it
// doesn't break the functionality
return ~~val;
}
return toInt;
});
define(function () {
/**
* "Convert" value into a 32-bit unsigned integer.
* IMPORTANT: Value will wrap at 2^32.
*/
function toUInt(val){
// we do not use lang/toNumber because of perf and also because it
// doesn't break the functionality
return val >>> 0;
}
return toUInt;
});
define(['./MAX_INT'], function(MAX_INT){
/**
* "Convert" value into an 31-bit unsigned integer (since 1 bit is used for sign).
* IMPORTANT: value wil wrap at 2^31, if negative will return 0.
*/
function toUInt31(val){
// we do not use lang/toNumber because of perf and also because it
// doesn't break the functionality
return (val <= 0)? 0 : (val > MAX_INT? ~~(val % (MAX_INT + 1)) : ~~val);
}
return toUInt31;
});
define(function(require){
//automatically generated, do not edit!
//run `node build` instead
return {
'bindAll' : require('./object/bindAll'),
'contains' : require('./object/contains'),
'deepEquals' : require('./object/deepEquals'),
'deepFillIn' : require('./object/deepFillIn'),
'deepMatches' : require('./object/deepMatches'),
'deepMixIn' : require('./object/deepMixIn'),
'equals' : require('./object/equals'),
'every' : require('./object/every'),
'fillIn' : require('./object/fillIn'),
'filter' : require('./object/filter'),
'find' : require('./object/find'),
'forIn' : require('./object/forIn'),
'forOwn' : require('./object/forOwn'),
'functions' : require('./object/functions'),
'get' : require('./object/get'),
'has' : require('./object/has'),
'hasOwn' : require('./object/hasOwn'),
'keys' : require('./object/keys'),
'map' : require('./object/map'),
'matches' : require('./object/matches'),
'max' : require('./object/max'),
'merge' : require('./object/merge'),
'min' : require('./object/min'),
'mixIn' : require('./object/mixIn'),
'namespace' : require('./object/namespace'),
'pick' : require('./object/pick'),
'pluck' : require('./object/pluck'),
'reduce' : require('./object/reduce'),
'reject' : require('./object/reject'),
'set' : require('./object/set'),
'size' : require('./object/size'),
'some' : require('./object/some'),
'unset' : require('./object/unset'),
'values' : require('./object/values')
};
});
define(['./functions', '../function/bind', '../array/forEach'], function (functions, bind, forEach) {
/**
* Binds methods of the object to be run in it's own context.
*/
function bindAll(obj, rest_methodNames){
var keys = arguments.length > 1?
Array.prototype.slice.call(arguments, 1) : functions(obj);
forEach(keys, function(key){
obj[key] = bind(obj[key], obj);
});
}
return bindAll;
});
define(['./some'], function (some) {
/**
* Check if object contains value
*/
function contains(obj, needle) {
return some(obj, function(val) {
return (val === needle);
});
}
return contains;
});
define(['../lang/isObject', './equals'], function (isObject, equals) {
function defaultCompare(a, b) {
return a === b;
}
/**
* Recursively checks for same properties and values.
*/
function deepEquals(a, b, callback){
callback = callback || defaultCompare;
if (!isObject(a) || !isObject(b)) {
return callback(a, b);
}
function compare(a, b){
return deepEquals(a, b, callback);
}
return equals(a, b, compare);
}
return deepEquals;
});
define(['./forOwn', '../lang/isPlainObject'], function (forOwn, isPlainObject) {
/**
* Deeply copy missing properties in the target from the defaults.
*/
function deepFillIn(target, defaults){
var i = 0,
n = arguments.length,
obj;
while(++i < n) {
obj = arguments[i];
if (obj) {
// jshint loopfunc: true
forOwn(obj, function(newValue, key) {
var curValue = target[key];
if (curValue == null) {
target[key] = newValue;
} else if (isPlainObject(curValue) &&
isPlainObject(newValue)) {
deepFillIn(curValue, newValue);
}
});
}
}
return target;
}
return deepFillIn;
});
define(['../array/forEach', './forOwn'], function (forEach, forOwn) {
/**
* Copy missing properties in the obj from the defaults.
*/
function fillIn(obj, var_defaults){
forEach(Array.prototype.slice.call(arguments, 1), function(base){
forOwn(base, function(val, key){
if (obj[key] == null) {
obj[key] = val;
}
});
});
return obj;
}
return fillIn;
});
define(['./forOwn', '../function/makeIterator_'], function(forOwn, makeIterator) {
/**
* Creates a new object with all the properties where the callback returns
* true.
*/
function filterValues(obj, callback, thisObj) {
callback = makeIterator(callback, thisObj);
var output = {};
forOwn(obj, function(value, key, obj) {
if (callback(value, key, obj)) {
output[key] = value;
}
});
return output;
}
return filterValues;
});
define(['./some', '../function/makeIterator_'], function(some, makeIterator) {
/**
* Returns first item that matches criteria
*/
function find(obj, callback, thisObj) {
callback = makeIterator(callback, thisObj);
var result;
some(obj, function(value, key, obj) {
if (callback(value, key, obj)) {
result = value;
return true; //break
}
});
return result;
}
return find;
});
define(['./forIn'], function (forIn) {
/**
* return a list of all enumerable properties that have function values
*/
function functions(obj){
var keys = [];
forIn(obj, function(val, key){
if (typeof val === 'function'){
keys.push(key);
}
});
return keys.sort();
}
return functions;
});
define(function () {
/**
* get "nested" object property
*/
function get(obj, prop){
var parts = prop.split('.'),
last = parts.pop();
while (prop = parts.shift()) {
obj = obj[prop];
if (typeof obj !== 'object' || !obj) return;
}
return obj[last];
}
return get;
});
define(['./get'], function (get) {
var UNDEF;
/**
* Check if object has nested property.
*/
function has(obj, prop){
return get(obj, prop) !== UNDEF;
}
return has;
});
define(['./forOwn'], function (forOwn) {
/**
* Get object keys
*/
var keys = Object.keys || function (obj) {
var keys = [];
forOwn(obj, function(val, key){
keys.push(key);
});
return keys;
};
return keys;
});
define(['./forOwn', '../function/makeIterator_'], function(forOwn, makeIterator) {
/**
* Creates a new object where all the values are the result of calling
* `callback`.
*/
function mapValues(obj, callback, thisObj) {
callback = makeIterator(callback, thisObj);
var output = {};
forOwn(obj, function(val, key, obj) {
output[key] = callback(val, key, obj);
});
return output;
}
return mapValues;
});
define(['./forOwn'], function (forOwn) {
/**
* checks if a object contains all given properties/values
*/
function matches(target, props){
// can't use "object/every" because of circular dependency
var result = true;
forOwn(props, function(val, key){
if (target[key] !== val) {
// break loop at first difference
return (result = false);
}
});
return result;
}
return matches;
});
define(['../array/max', './values'], function(arrMax, values) {
/**
* Returns maximum value inside object.
*/
function max(obj, compareFn) {
return arrMax(values(obj), compareFn);
}
return max;
});
define(['../array/min', './values'], function(arrMin, values) {
/**
* Returns minimum value inside object.
*/
function min(obj, iterator) {
return arrMin(values(obj), iterator);
}
return min;
});
define(['../array/forEach'], function (forEach) {
/**
* Create nested object if non-existent
*/
function namespace(obj, path){
if (!path) return obj;
forEach(path.split('.'), function(key){
if (!obj[key]) {
obj[key] = {};
}
obj = obj[key];
});
return obj;
}
return namespace;
});
define(function(){
/**
* Return a copy of the object, filtered to only have values for the whitelisted keys.
*/
function pick(obj, var_keys){
var keys = typeof arguments[1] !== 'string'? arguments[1] : Array.prototype.slice.call(arguments, 1),
out = {},
i = 0, key;
while (key = keys[i++]) {
out[key] = obj[key];
}
return out;
}
return pick;
});
define(['./map', '../function/prop'], function (map, prop) {
/**
* Extract a list of property values.
*/
function pluck(obj, propName){
return map(obj, prop(propName));
}
return pluck;
});
define(['./forOwn', './size'], function(forOwn, size) {
/**
* Object reduce
*/
function reduce(obj, callback, memo, thisObj) {
var initial = arguments.length > 2;
if (!size(obj) && !initial) {
throw new Error('reduce of empty object with no initial value');
}
forOwn(obj, function(value, key, list) {
if (!initial) {
memo = value;
initial = true;
}
else {
memo = callback.call(thisObj, memo, value, key, list);
}
});
return memo;
}
return reduce;
});
define(['./filter', '../function/makeIterator_'], function (filter, makeIterator) {
/**
* Object reject
*/
function reject(obj, callback, thisObj) {
callback = makeIterator(callback, thisObj);
return filter(obj, function(value, index, obj) {
return !callback(value, index, obj);
}, thisObj);
}
return reject;
});
define(['./namespace'], function (namespace) {
/**
* set "nested" object property
*/
function set(obj, prop, val){
var parts = (/^(.+)\.(.+)$/).exec(prop);
if (parts){
namespace(obj, parts[1])[parts[2]] = val;
} else {
obj[prop] = val;
}
}
return set;
});
define(['./forOwn'], function (forOwn) {
/**
* Get object size
*/
function size(obj) {
var count = 0;
forOwn(obj, function(){
count++;
});
return count;
}
return size;
});
define(['./forOwn', '../function/makeIterator_'], function(forOwn, makeIterator) {
/**
* Object some
*/
function some(obj, callback, thisObj) {
callback = makeIterator(callback, thisObj);
var result = false;
forOwn(obj, function(val, key) {
if (callback(val, key, obj)) {
result = true;
return false; // break
}
});
return result;
}
return some;
});
define(['./has'], function (has) {
/**
* Unset object property.
*/
function unset(obj, prop){
if (has(obj, prop)) {
var parts = prop.split('.'),
last = parts.pop();
while (prop = parts.shift()) {
obj = obj[prop];
}
return (delete obj[last]);
} else {
// if property doesn't exist treat as deleted
return true;
}
}
return unset;
});
define(['./forOwn'], function (forOwn) {
/**
* Get object values
*/
function values(obj) {
var vals = [];
forOwn(obj, function(val, key){
vals.push(val);
});
return vals;
}
return values;
});
define(function(require){
//automatically generated, do not edit!
//run `node build` instead
return {
'contains' : require('./queryString/contains'),
'decode' : require('./queryString/decode'),
'encode' : require('./queryString/encode'),
'getParam' : require('./queryString/getParam'),
'getQuery' : require('./queryString/getQuery'),
'parse' : require('./queryString/parse'),
'setParam' : require('./queryString/setParam')
};
});
define(['./getQuery'], function (getQuery) {
/**
* Checks if query string contains parameter.
*/
function contains(url, paramName) {
var regex = new RegExp('(\\?|&)'+ paramName +'=', 'g'); //matches `?param=` or `&param=`
return regex.test(getQuery(url));
}
return contains;
});
define(['../string/typecast', '../lang/isString', '../lang/isArray', '../object/hasOwn'], function (typecast, isString, isArray, hasOwn) {
/**
* Decode query string into an object of keys => vals.
*/
function decode(queryStr, shouldTypecast) {
var queryArr = (queryStr || '').replace('?', '').split('&'),
count = -1,
length = queryArr.length,
obj = {},
item, pValue, pName, toSet;
while (++count < length) {
item = queryArr[count].split('=');
pName = item[0];
if (!pName || !pName.length){
continue;
}
pValue = shouldTypecast === false ? item[1] : typecast(item[1]);
toSet = isString(pValue) ? decodeURIComponent(pValue) : pValue;
if (hasOwn(obj,pName)){
if(isArray(obj[pName])){
obj[pName].push(toSet);
} else {
obj[pName] = [obj[pName],toSet];
}
} else {
obj[pName] = toSet;
}
}
return obj;
}
return decode;
});
define(['../object/forOwn','../lang/isArray','../array/forEach'], function (forOwn,isArray,forEach) {
/**
* Encode object into a query string.
*/
function encode(obj){
var query = [],
arrValues, reg;
forOwn(obj, function (val, key) {
if (isArray(val)) {
arrValues = key + '=';
reg = new RegExp('&'+key+'+=$');
forEach(val, function (aValue) {
arrValues += encodeURIComponent(aValue) + '&' + key + '=';
});
query.push(arrValues.replace(reg, ''));
} else {
query.push(key + '=' + encodeURIComponent(val));
}
});
return (query.length) ? '?' + query.join('&') : '';
}
return encode;
});
define(['../string/typecast', './getQuery'], function (typecast, getQuery) {
/**
* Get query parameter value.
*/
function getParam(url, param, shouldTypecast){
var regexp = new RegExp('(\\?|&)'+ param + '=([^&]*)'), //matches `?param=value` or `&param=value`, value = $2
result = regexp.exec( getQuery(url) ),
val = (result && result[2])? result[2] : null;
return shouldTypecast === false? val : typecast(val);
}
return getParam;
});
define(function () {
/**
* Gets full query as string with all special chars decoded.
*/
function getQuery(url) {
url = url.replace(/#.*/, ''); //removes hash (to avoid getting hash query)
var queryString = /\?[a-zA-Z0-9\=\&\%\$\-\_\.\+\!\*\'\(\)\,]+/.exec(url); //valid chars according to: http://www.ietf.org/rfc/rfc1738.txt
return (queryString)? decodeURIComponent(queryString[0]) : '';
}
return getQuery;
});
define(['./decode', './getQuery'], function (decode, getQuery) {
/**
* Get query string, parses and decodes it.
*/
function parse(url, shouldTypecast) {
return decode(getQuery(url), shouldTypecast);
}
return parse;
});
define(function () {
/**
* Set query string parameter value
*/
function setParam(url, paramName, value){
url = url || '';
var re = new RegExp('(\\?|&)'+ paramName +'=[^&]*' );
var param = paramName +'='+ encodeURIComponent( value );
if ( re.test(url) ) {
return url.replace(re, '$1'+ param);
} else {
if (url.indexOf('?') === -1) {
url += '?';
}
if (url.indexOf('=') !== -1) {
url += '&';
}
return url + param;
}
}
return setParam;
});
define(function(require){
//automatically generated, do not edit!
//run `node build` instead
return {
'choice' : require('./random/choice'),
'guid' : require('./random/guid'),
'rand' : require('./random/rand'),
'randBit' : require('./random/randBit'),
'randHex' : require('./random/randHex'),
'randInt' : require('./random/randInt'),
'randSign' : require('./random/randSign'),
'random' : require('./random/random')
};
});
define(['./randInt', '../lang/isArray'], function (randInt, isArray) {
/**
* Returns a random element from the supplied arguments
* or from the array (if single argument is an array).
*/
function choice(items) {
var target = (arguments.length === 1 && isArray(items))? items : arguments;
return target[ randInt(0, target.length - 1) ];
}
return choice;
});
define(['./randHex', './choice'], function (randHex, choice) {
/**
* Returns pseudo-random guid (UUID v4)
* IMPORTANT: it's not totally "safe" since randHex/choice uses Math.random
* by default and sequences can be predicted in some cases. See the
* "random/random" documentation for more info about it and how to replace
* the default PRNG.
*/
function guid() {
return (
randHex(8)+'-'+
randHex(4)+'-'+
// v4 UUID always contain "4" at this position to specify it was
// randomly generated
'4' + randHex(3) +'-'+
// v4 UUID always contain chars [a,b,8,9] at this position
choice(8, 9, 'a', 'b') + randHex(3)+'-'+
randHex(12)
);
}
return guid;
});
define(['./random', '../number/MIN_INT', '../number/MAX_INT'], function(random, MIN_INT, MAX_INT){
/**
* Returns random number inside range
*/
function rand(min, max){
min = min == null? MIN_INT : min;
max = max == null? MAX_INT : max;
return min + (max - min) * random();
}
return rand;
});
define(['./random'], function (random) {
/**
* Returns random bit (0 or 1)
*/
function randomBit() {
return random() > 0.5? 1 : 0;
}
return randomBit;
});
define(['./choice'], function (choice) {
var _chars = '0123456789abcdef'.split('');
/**
* Returns a random hexadecimal string
*/
function randHex(size){
size = size && size > 0? size : 6;
var str = '';
while (size--) {
str += choice(_chars);
}
return str;
}
return randHex;
});
define(['../number/MIN_INT', '../number/MAX_INT', './rand'], function(MIN_INT, MAX_INT, rand){
/**
* Gets random integer inside range or snap to min/max values.
*/
function randInt(min, max){
min = min == null? MIN_INT : ~~min;
max = max == null? MAX_INT : ~~max;
// can't be max + 0.5 otherwise it will round up if `rand`
// returns `max` causing it to overflow range.
// -0.5 and + 0.49 are required to avoid bias caused by rounding
return Math.round( rand(min - 0.5, max + 0.499999999999) );
}
return randInt;
});
define(['./random'], function (random) {
/**
* Returns random sign (-1 or 1)
*/
function randomSign() {
return random() > 0.5? 1 : -1;
}
return randomSign;
});
define(function () {
/**
* Just a wrapper to Math.random. No methods inside mout/random should call
* Math.random() directly so we can inject the pseudo-random number
* generator if needed (ie. in case we need a seeded random or a better
* algorithm than the native one)
*/
function random(){
return random.get();
}
// we expose the method so it can be swapped if needed
random.get = Math.random;
return random;
});
define(function(require){
//automatically generated, do not edit!
//run `node build` instead
return {
'WHITE_SPACES' : require('./string/WHITE_SPACES'),
'camelCase' : require('./string/camelCase'),
'contains' : require('./string/contains'),
'crop' : require('./string/crop'),
'endsWith' : require('./string/endsWith'),
'escapeHtml' : require('./string/escapeHtml'),
'escapeRegExp' : require('./string/escapeRegExp'),
'escapeUnicode' : require('./string/escapeUnicode'),
'hyphenate' : require('./string/hyphenate'),
'insert' : require('./string/insert'),
'interpolate' : require('./string/interpolate'),
'lowerCase' : require('./string/lowerCase'),
'lpad' : require('./string/lpad'),
'ltrim' : require('./string/ltrim'),
'makePath' : require('./string/makePath'),
'normalizeLineBreaks' : require('./string/normalizeLineBreaks'),
'pascalCase' : require('./string/pascalCase'),
'properCase' : require('./string/properCase'),
'removeNonASCII' : require('./string/removeNonASCII'),
'removeNonWord' : require('./string/removeNonWord'),
'repeat' : require('./string/repeat'),
'replace' : require('./string/replace'),
'replaceAccents' : require('./string/replaceAccents'),
'rpad' : require('./string/rpad'),
'rtrim' : require('./string/rtrim'),
'sentenceCase' : require('./string/sentenceCase'),
'slugify' : require('./string/slugify'),
'startsWith' : require('./string/startsWith'),
'stripHtmlTags' : require('./string/stripHtmlTags'),
'trim' : require('./string/trim'),
'truncate' : require('./string/truncate'),
'typecast' : require('./string/typecast'),
'unCamelCase' : require('./string/unCamelCase'),
'underscore' : require('./string/underscore'),
'unescapeHtml' : require('./string/unescapeHtml'),
'unescapeUnicode' : require('./string/unescapeUnicode'),
'unhyphenate' : require('./string/unhyphenate'),
'upperCase' : require('./string/upperCase')
};
});
define(function() {
/**
* Contains all Unicode white-spaces. Taken from
* http://en.wikipedia.org/wiki/Whitespace_character.
*/
return [
' ', '\n', '\r', '\t', '\f', '\v', '\u00A0', '\u1680', '\u180E',
'\u2000', '\u2001', '\u2002', '\u2003', '\u2004', '\u2005', '\u2006',
'\u2007', '\u2008', '\u2009', '\u200A', '\u2028', '\u2029', '\u202F',
'\u205F', '\u3000'
];
});
define(['../lang/toString', './replaceAccents', './removeNonWord', './upperCase', './lowerCase'], function(toString, replaceAccents, removeNonWord, upperCase, lowerCase){
/**
* Convert string to camelCase text.
*/
function camelCase(str){
str = toString(str);
str = replaceAccents(str);
str = removeNonWord(str)
.replace(/[\-_]/g, ' ') //convert all hyphens and underscores to spaces
.replace(/\s[a-z]/g, upperCase) //convert first char of each word to UPPERCASE
.replace(/\s+/g, '') //remove spaces
.replace(/^[A-Z]/g, lowerCase); //convert first char to lowercase
return str;
}
return camelCase;
});
define(['../lang/toString'], function(toString) {
/**
* Searches for a given substring
*/
function contains(str, substring, fromIndex){
str = toString(str);
substring = toString(substring);
return str.indexOf(substring, fromIndex) !== -1;
}
return contains;
});
define(['../lang/toString', './truncate'], function (toString, truncate) {
/**
* Truncate string at full words.
*/
function crop(str, maxChars, append) {
str = toString(str);
return truncate(str, maxChars, append, true);
}
return crop;
});
define(['../lang/toString'], function(toString) {
/**
* Checks if string ends with specified suffix.
*/
function endsWith(str, suffix) {
str = toString(str);
suffix = toString(suffix);
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
return endsWith;
});
define(['../lang/toString'], function(toString) {
/**
* Escapes a string for insertion into HTML.
*/
function escapeHtml(str){
str = toString(str)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/'/g, '&#39;')
.replace(/"/g, '&quot;');
return str;
}
return escapeHtml;
});
define(['../lang/toString'], function(toString) {
var ESCAPE_CHARS = /[\\.+*?\^$\[\](){}\/'#]/g;
/**
* Escape RegExp string chars.
*/
function escapeRegExp(str) {
str = toString(str);
return str.replace(ESCAPE_CHARS,'\\$&');
}
return escapeRegExp;
});
define(['../lang/toString'], function(toString) {
/**
* Escape string into unicode sequences
*/
function escapeUnicode(str, shouldEscapePrintable){
str = toString(str);
return str.replace(/[\s\S]/g, function(ch){
// skip printable ASCII chars if we should not escape them
if (!shouldEscapePrintable && (/[\x20-\x7E]/).test(ch)) {
return ch;
}
// we use "000" and slice(-4) for brevity, need to pad zeros,
// unicode escape always have 4 chars after "\u"
return '\\u'+ ('000'+ ch.charCodeAt(0).toString(16)).slice(-4);
});
}
return escapeUnicode;
});
define(['../lang/toString', './slugify', './unCamelCase'], function(toString, slugify, unCamelCase){
/**
* Replaces spaces with hyphens, split camelCase text, remove non-word chars, remove accents and convert to lower case.
*/
function hyphenate(str){
str = toString(str);
str = unCamelCase(str);
return slugify(str, "-");
}
return hyphenate;
});
define(['../math/clamp', '../lang/toString'], function (clamp, toString) {
/**
* Inserts a string at a given index.
*/
function insert(string, index, partial){
string = toString(string);
if (index < 0) {
index = string.length + index;
}
index = clamp(index, 0, string.length);
return string.substr(0, index) + partial + string.substr(index);
}
return insert;
});
define(['../lang/toString'], function(toString) {
var stache = /\{\{(\w+)\}\}/g; //mustache-like
/**
* String interpolation
*/
function interpolate(template, replacements, syntax){
template = toString(template);
var replaceFn = function(match, prop){
return (prop in replacements)? toString(replacements[prop]) : '';
};
return template.replace(syntax || stache, replaceFn);
}
return interpolate;
});
define(['../lang/toString'], function(toString){
/**
* "Safer" String.toLowerCase()
*/
function lowerCase(str){
str = toString(str);
return str.toLowerCase();
}
return lowerCase;
});
define(['../lang/toString', './repeat'], function(toString, repeat) {
/**
* Pad string with `char` if its' length is smaller than `minLen`
*/
function lpad(str, minLen, ch) {
str = toString(str);
ch = ch || ' ';
return (str.length < minLen) ?
repeat(ch, minLen - str.length) + str : str;
}
return lpad;
});
define(['../lang/toString', './WHITE_SPACES'], function(toString, WHITE_SPACES){
/**
* Remove chars from beginning of string.
*/
function ltrim(str, chars) {
str = toString(str);
chars = chars || WHITE_SPACES;
var start = 0,
len = str.length,
charLen = chars.length,
found = true,
i, c;
while (found && start < len) {
found = false;
i = -1;
c = str.charAt(start);
while (++i < charLen) {
if (c === chars[i]) {
found = true;
start++;
break;
}
}
}
return (start >= len) ? '' : str.substr(start, len);
}
return ltrim;
});
define(['../array/join'], function(join){
/**
* Group arguments as path segments, if any of the args is `null` or an
* empty string it will be ignored from resulting path.
*/
function makePath(var_args){
var result = join(Array.prototype.slice.call(arguments), '/');
// need to disconsider duplicate '/' after protocol (eg: 'http://')
return result.replace(/([^:\/]|^)\/{2,}/g, '$1/');
}
return makePath;
});
define(['../lang/toString'], function (toString) {
/**
* Convert line-breaks from DOS/MAC to a single standard (UNIX by default)
*/
function normalizeLineBreaks(str, lineEnd) {
str = toString(str);
lineEnd = lineEnd || '\n';
return str
.replace(/\r\n/g, lineEnd) // DOS
.replace(/\r/g, lineEnd) // Mac
.replace(/\n/g, lineEnd); // Unix
}
return normalizeLineBreaks;
});
define(['../lang/toString', './camelCase', './upperCase'], function(toString, camelCase, upperCase){
/**
* camelCase + UPPERCASE first char
*/
function pascalCase(str){
str = toString(str);
return camelCase(str).replace(/^[a-z]/, upperCase);
}
return pascalCase;
});
define(['../lang/toString', './lowerCase', './upperCase'], function(toString, lowerCase, upperCase){
/**
* UPPERCASE first char of each word.
*/
function properCase(str){
str = toString(str);
return lowerCase(str).replace(/^\w|\s\w/g, upperCase);
}
return properCase;
});
define(['../lang/toString'], function(toString){
/**
* Remove non-printable ASCII chars
*/
function removeNonASCII(str){
str = toString(str);
// Matches non-printable ASCII chars -
// http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters
return str.replace(/[^\x20-\x7E]/g, '');
}
return removeNonASCII;
});
define(['../lang/toString'], function(toString){
/**
* Remove non-word chars.
*/
function removeNonWord(str){
str = toString(str);
return str.replace(/[^0-9a-zA-Z\xC0-\xFF \-_]/g, '');
}
return removeNonWord;
});
define(['../lang/toString'], function(toString){
/**
* Repeat string n times
*/
function repeat(str, n){
str = toString(str);
return (new Array(n + 1)).join(str);
}
return repeat;
});
define(['../lang/toString', '../lang/toArray'], function (toString, toArray) {
/**
* Replace string(s) with the replacement(s) in the source.
*/
function replace(str, search, replacements) {
str = toString(str);
search = toArray(search);
replacements = toArray(replacements);
var searchLength = search.length,
replacementsLength = replacements.length;
if (replacementsLength !== 1 && searchLength !== replacementsLength) {
throw new Error('Unequal number of searches and replacements');
}
var i = -1;
while (++i < searchLength) {
// Use the first replacement for all searches if only one
// replacement is provided
str = str.replace(
search[i],
replacements[(replacementsLength === 1) ? 0 : i]);
}
return str;
}
return replace;
});
define(['../lang/toString'], function(toString){
/**
* Replaces all accented chars with regular ones
*/
function replaceAccents(str){
str = toString(str);
// verifies if the String has accents and replace them
if (str.search(/[\xC0-\xFF]/g) > -1) {
str = str
.replace(/[\xC0-\xC5]/g, "A")
.replace(/[\xC6]/g, "AE")
.replace(/[\xC7]/g, "C")
.replace(/[\xC8-\xCB]/g, "E")
.replace(/[\xCC-\xCF]/g, "I")
.replace(/[\xD0]/g, "D")
.replace(/[\xD1]/g, "N")
.replace(/[\xD2-\xD6\xD8]/g, "O")
.replace(/[\xD9-\xDC]/g, "U")
.replace(/[\xDD]/g, "Y")
.replace(/[\xDE]/g, "P")
.replace(/[\xE0-\xE5]/g, "a")
.replace(/[\xE6]/g, "ae")
.replace(/[\xE7]/g, "c")
.replace(/[\xE8-\xEB]/g, "e")
.replace(/[\xEC-\xEF]/g, "i")
.replace(/[\xF1]/g, "n")
.replace(/[\xF2-\xF6\xF8]/g, "o")
.replace(/[\xF9-\xFC]/g, "u")
.replace(/[\xFE]/g, "p")
.replace(/[\xFD\xFF]/g, "y");
}
return str;
}
return replaceAccents;
});
define(['../lang/toString', './repeat'], function (toString, repeat) {
/**
* Pad string with `char` if its' length is smaller than `minLen`
*/
function rpad(str, minLen, ch) {
str = toString(str);
ch = ch || ' ';
return (str.length < minLen)? str + repeat(ch, minLen - str.length) : str;
}
return rpad;
});
define(['../lang/toString', './WHITE_SPACES'], function(toString, WHITE_SPACES){
/**
* Remove chars from end of string.
*/
function rtrim(str, chars) {
str = toString(str);
chars = chars || WHITE_SPACES;
var end = str.length - 1,
charLen = chars.length,
found = true,
i, c;
while (found && end >= 0) {
found = false;
i = -1;
c = str.charAt(end);
while (++i < charLen) {
if (c === chars[i]) {
found = true;
end--;
break;
}
}
}
return (end >= 0) ? str.substring(0, end + 1) : '';
}
return rtrim;
});
define(['../lang/toString', './lowerCase', './upperCase'], function(toString, lowerCase, upperCase){
/**
* UPPERCASE first char of each sentence and lowercase other chars.
*/
function sentenceCase(str){
str = toString(str);
// Replace first char of each sentence (new line or after '.\s+') to
// UPPERCASE
return lowerCase(str).replace(/(^\w)|\.\s+(\w)/gm, upperCase);
}
return sentenceCase;
});
define(['../lang/toString', './replaceAccents', './removeNonWord', './trim'], function(toString, replaceAccents, removeNonWord, trim){
/**
* Convert to lower case, remove accents, remove non-word chars and
* replace spaces with the specified delimeter.
* Does not split camelCase text.
*/
function slugify(str, delimeter){
str = toString(str);
if (delimeter == null) {
delimeter = "-";
}
str = replaceAccents(str);
str = removeNonWord(str);
str = trim(str) //should come after removeNonWord
.replace(/ +/g, delimeter) //replace spaces with delimeter
.toLowerCase();
return str;
}
return slugify;
});
define(['../lang/toString'], function (toString) {
/**
* Checks if string starts with specified prefix.
*/
function startsWith(str, prefix) {
str = toString(str);
prefix = toString(prefix);
return str.indexOf(prefix) === 0;
}
return startsWith;
});
define(['../lang/toString'], function(toString){
/**
* Remove HTML tags from string.
*/
function stripHtmlTags(str){
str = toString(str);
return str.replace(/<[^>]*>/g, '');
}
return stripHtmlTags;
});
define(['../lang/toString', './WHITE_SPACES', './ltrim', './rtrim'], function(toString, WHITE_SPACES, ltrim, rtrim){
/**
* Remove white-spaces from beginning and end of string.
*/
function trim(str, chars) {
str = toString(str);
chars = chars || WHITE_SPACES;
return ltrim(rtrim(str, chars), chars);
}
return trim;
});
define(['../lang/toString', './trim'], function(toString, trim){
/**
* Limit number of chars.
*/
function truncate(str, maxChars, append, onlyFullWords){
str = toString(str);
append = append || '...';
maxChars = onlyFullWords? maxChars + 1 : maxChars;
str = trim(str);
if(str.length <= maxChars){
return str;
}
str = str.substr(0, maxChars - append.length);
//crop at last space or remove trailing whitespace
str = onlyFullWords? str.substr(0, str.lastIndexOf(' ')) : trim(str);
return str + append;
}
return truncate;
});
define(function () {
var UNDEF;
/**
* Parses string and convert it into a native value.
*/
function typecast(val) {
var r;
if ( val === null || val === 'null' ) {
r = null;
} else if ( val === 'true' ) {
r = true;
} else if ( val === 'false' ) {
r = false;
} else if ( val === UNDEF || val === 'undefined' ) {
r = UNDEF;
} else if ( val === '' || isNaN(val) ) {
//isNaN('') returns false
r = val;
} else {
//parseFloat(null || '') returns NaN
r = parseFloat(val);
}
return r;
}
return typecast;
});
define(['../lang/toString'], function(toString){
var CAMEL_CASE_BORDER = /([a-z\xE0-\xFF])([A-Z\xC0\xDF])/g;
/**
* Add space between camelCase text.
*/
function unCamelCase(str, delimiter){
if (delimiter == null) {
delimiter = ' ';
}
function join(str, c1, c2) {
return c1 + delimiter + c2;
}
str = toString(str);
str = str.replace(CAMEL_CASE_BORDER, join);
str = str.toLowerCase(); //add space between camelCase text
return str;
}
return unCamelCase;
});
define(['../lang/toString', './slugify', './unCamelCase'], function(toString, slugify, unCamelCase){
/**
* Replaces spaces with underscores, split camelCase text, remove non-word chars, remove accents and convert to lower case.
*/
function underscore(str){
str = toString(str);
str = unCamelCase(str);
return slugify(str, "_");
}
return underscore;
});
define(['../lang/toString'], function (toString) {
/**
* Unescapes HTML special chars
*/
function unescapeHtml(str){
str = toString(str)
.replace(/&amp;/g , '&')
.replace(/&lt;/g , '<')
.replace(/&gt;/g , '>')
.replace(/&#39;/g , "'")
.replace(/&quot;/g, '"');
return str;
}
return unescapeHtml;
});
define(['../lang/toString'], function(toString) {
/**
* Unescape unicode char sequences
*/
function unescapeUnicode(str){
str = toString(str);
return str.replace(/\\u[0-9a-f]{4}/g, function(ch){
var code = parseInt(ch.slice(2), 16);
return String.fromCharCode(code);
});
}
return unescapeUnicode;
});
define(['../lang/toString'], function(toString){
/**
* Replaces hyphens with spaces. (only hyphens between word chars)
*/
function unhyphenate(str){
str = toString(str);
return str.replace(/(\w)(-)(\w)/g, '$1 $3');
}
return unhyphenate;
});
define(['../lang/toString'], function(toString){
/**
* "Safer" String.toUpperCase()
*/
function upperCase(str){
str = toString(str);
return str.toUpperCase();
}
return upperCase;
});
define(function(require){
//automatically generated, do not edit!
//run `node build` instead
return {
'convert' : require('./time/convert'),
'now' : require('./time/now'),
'parseMs' : require('./time/parseMs'),
'toTimeString' : require('./time/toTimeString')
};
});
define(function () {
/**
* convert time into another unit
*/
function convert(val, sourceUnitName, destinationUnitName){
destinationUnitName = destinationUnitName || 'ms';
return (val * getUnit(sourceUnitName)) / getUnit(destinationUnitName);
}
//TODO: maybe extract to a separate module
function getUnit(unitName){
switch(unitName){
case 'ms':
case 'millisecond':
return 1;
case 's':
case 'second':
return 1000;
case 'm':
case 'minute':
return 60000;
case 'h':
case 'hour':
return 3600000;
case 'd':
case 'day':
return 86400000;
case 'w':
case 'week':
return 604800000;
default:
throw new Error('"'+ unitName + '" is not a valid unit');
}
}
return convert;
});
define(function () {
/**
* Get current time in miliseconds
*/
var now = (typeof Date.now === 'function')? Date.now : function(){
return +(new Date());
};
return now;
});
define(['../math/countSteps'], function(countSteps){
/**
* Parse timestamp into an object.
*/
function parseMs(ms){
return {
milliseconds : countSteps(ms, 1, 1000),
seconds : countSteps(ms, 1000, 60),
minutes : countSteps(ms, 60000, 60),
hours : countSteps(ms, 3600000, 24),
days : countSteps(ms, 86400000)
};
}
return parseMs;
});
define(['../math/countSteps', '../number/pad'], function(countSteps, pad){
var HOUR = 3600000,
MINUTE = 60000,
SECOND = 1000;
/**
* Format timestamp into a time string.
*/
function toTimeString(ms){
var h = ms < HOUR ? 0 : countSteps(ms, HOUR),
m = ms < MINUTE ? 0 : countSteps(ms, MINUTE, 60),
s = ms < SECOND ? 0 : countSteps(ms, SECOND, 60),
str = '';
str += h? h + ':' : '';
str += pad(m, 2) + ':';
str += pad(s, 2);
return str;
}
return toTimeString;
});
/** vim: et:ts=4:sw=4:sts=4 /** vim: et:ts=4:sw=4:sts=4
* @license RequireJS 2.1.8 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved. * @license RequireJS 2.1.16 Copyright (c) 2010-2015, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license. * Available via the MIT or new BSD license.
* see: http://github.com/jrburke/requirejs for details * see: http://github.com/jrburke/requirejs for details
*/ */
...@@ -12,7 +12,7 @@ var requirejs, require, define; ...@@ -12,7 +12,7 @@ var requirejs, require, define;
(function (global) { (function (global) {
var req, s, head, baseElement, dataMain, src, var req, s, head, baseElement, dataMain, src,
interactiveScript, currentlyAddingScript, mainScript, subPath, interactiveScript, currentlyAddingScript, mainScript, subPath,
version = '2.1.8', version = '2.1.16',
commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg, commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g, cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,
jsSuffixRegExp = /\.js$/, jsSuffixRegExp = /\.js$/,
...@@ -22,7 +22,7 @@ var requirejs, require, define; ...@@ -22,7 +22,7 @@ var requirejs, require, define;
hasOwn = op.hasOwnProperty, hasOwn = op.hasOwnProperty,
ap = Array.prototype, ap = Array.prototype,
apsp = ap.splice, apsp = ap.splice,
isBrowser = !!(typeof window !== 'undefined' && navigator && window.document), isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document),
isWebWorker = !isBrowser && typeof importScripts !== 'undefined', isWebWorker = !isBrowser && typeof importScripts !== 'undefined',
//PS3 indicates loaded and complete, but need to wait for complete //PS3 indicates loaded and complete, but need to wait for complete
//specifically. Sequence is 'loading', 'loaded', execution, //specifically. Sequence is 'loading', 'loaded', execution,
...@@ -108,7 +108,10 @@ var requirejs, require, define; ...@@ -108,7 +108,10 @@ var requirejs, require, define;
if (source) { if (source) {
eachProp(source, function (value, prop) { eachProp(source, function (value, prop) {
if (force || !hasProp(target, prop)) { if (force || !hasProp(target, prop)) {
if (deepStringMixin && typeof value !== 'string') { if (deepStringMixin && typeof value === 'object' && value &&
!isArray(value) && !isFunction(value) &&
!(value instanceof RegExp)) {
if (!target[prop]) { if (!target[prop]) {
target[prop] = {}; target[prop] = {};
} }
...@@ -138,7 +141,7 @@ var requirejs, require, define; ...@@ -138,7 +141,7 @@ var requirejs, require, define;
throw err; throw err;
} }
//Allow getting a global that expressed in //Allow getting a global that is expressed in
//dot notation, like 'a.b.c'. //dot notation, like 'a.b.c'.
function getGlobal(value) { function getGlobal(value) {
if (!value) { if (!value) {
...@@ -177,7 +180,7 @@ var requirejs, require, define; ...@@ -177,7 +180,7 @@ var requirejs, require, define;
if (typeof requirejs !== 'undefined') { if (typeof requirejs !== 'undefined') {
if (isFunction(requirejs)) { if (isFunction(requirejs)) {
//Do not overwrite and existing requirejs instance. //Do not overwrite an existing requirejs instance.
return; return;
} }
cfg = requirejs; cfg = requirejs;
...@@ -201,6 +204,7 @@ var requirejs, require, define; ...@@ -201,6 +204,7 @@ var requirejs, require, define;
waitSeconds: 7, waitSeconds: 7,
baseUrl: './', baseUrl: './',
paths: {}, paths: {},
bundles: {},
pkgs: {}, pkgs: {},
shim: {}, shim: {},
config: {} config: {}
...@@ -214,6 +218,7 @@ var requirejs, require, define; ...@@ -214,6 +218,7 @@ var requirejs, require, define;
defQueue = [], defQueue = [],
defined = {}, defined = {},
urlFetched = {}, urlFetched = {},
bundlesMap = {},
requireCounter = 1, requireCounter = 1,
unnormalizedCounter = 1; unnormalizedCounter = 1;
...@@ -228,20 +233,19 @@ var requirejs, require, define; ...@@ -228,20 +233,19 @@ var requirejs, require, define;
*/ */
function trimDots(ary) { function trimDots(ary) {
var i, part; var i, part;
for (i = 0; ary[i]; i += 1) { for (i = 0; i < ary.length; i++) {
part = ary[i]; part = ary[i];
if (part === '.') { if (part === '.') {
ary.splice(i, 1); ary.splice(i, 1);
i -= 1; i -= 1;
} else if (part === '..') { } else if (part === '..') {
if (i === 1 && (ary[2] === '..' || ary[0] === '..')) { // If at the start, or previous value is still ..,
//End of the line. Keep at least one non-dot // keep them so that when converted to a path it may
//path segment at the front so it can be mapped // still work when converted to a path, even though
//correctly to disk. Otherwise, there is likely // as an ID it is less than ideal. In larger point
//no path mapping for a path starting with '..'. // releases, may be better to just kick out an error.
//This can still fail, but catches the most reasonable if (i === 0 || (i == 1 && ary[2] === '..') || ary[i - 1] === '..') {
//uses of .. continue;
break;
} else if (i > 0) { } else if (i > 0) {
ary.splice(i - 1, 2); ary.splice(i - 1, 2);
i -= 2; i -= 2;
...@@ -261,54 +265,45 @@ var requirejs, require, define; ...@@ -261,54 +265,45 @@ var requirejs, require, define;
* @returns {String} normalized name * @returns {String} normalized name
*/ */
function normalize(name, baseName, applyMap) { function normalize(name, baseName, applyMap) {
var pkgName, pkgConfig, mapValue, nameParts, i, j, nameSegment, var pkgMain, mapValue, nameParts, i, j, nameSegment, lastIndex,
foundMap, foundI, foundStarMap, starI, foundMap, foundI, foundStarMap, starI, normalizedBaseParts,
baseParts = baseName && baseName.split('/'), baseParts = (baseName && baseName.split('/')),
normalizedBaseParts = baseParts,
map = config.map, map = config.map,
starMap = map && map['*']; starMap = map && map['*'];
//Adjust any relative paths. //Adjust any relative paths.
if (name && name.charAt(0) === '.') { if (name) {
//If have a base name, try to normalize against it, name = name.split('/');
//otherwise, assume it is a top-level require that will lastIndex = name.length - 1;
//be relative to baseUrl in the end.
if (baseName) { // If wanting node ID compatibility, strip .js from end
if (getOwn(config.pkgs, baseName)) { // of IDs. Have to do this here, and not in nameToUrl
//If the baseName is a package name, then just treat it as one // because node allows either .js or non .js to map
//name to concat the name with. // to same file.
normalizedBaseParts = baseParts = [baseName]; if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
} else { name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
//Convert baseName to array, and lop off the last part, }
//so that . matches that 'directory' and not name of the baseName's
//module. For instance, baseName of 'one/two/three', maps to
//'one/two/three.js', but we want the directory, 'one/two' for
//this normalization.
normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
}
name = normalizedBaseParts.concat(name.split('/'));
trimDots(name);
//Some use of packages may use a . path to reference the // Starts with a '.' so need the baseName
//'main' module name, so normalize for that. if (name[0].charAt(0) === '.' && baseParts) {
pkgConfig = getOwn(config.pkgs, (pkgName = name[0])); //Convert baseName to array, and lop off the last part,
name = name.join('/'); //so that . matches that 'directory' and not name of the baseName's
if (pkgConfig && name === pkgName + '/' + pkgConfig.main) { //module. For instance, baseName of 'one/two/three', maps to
name = pkgName; //'one/two/three.js', but we want the directory, 'one/two' for
} //this normalization.
} else if (name.indexOf('./') === 0) { normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
// No baseName, so this is ID is resolved relative name = normalizedBaseParts.concat(name);
// to baseUrl, pull off the leading dot.
name = name.substring(2);
} }
trimDots(name);
name = name.join('/');
} }
//Apply map config if available. //Apply map config if available.
if (applyMap && map && (baseParts || starMap)) { if (applyMap && map && (baseParts || starMap)) {
nameParts = name.split('/'); nameParts = name.split('/');
for (i = nameParts.length; i > 0; i -= 1) { outerLoop: for (i = nameParts.length; i > 0; i -= 1) {
nameSegment = nameParts.slice(0, i).join('/'); nameSegment = nameParts.slice(0, i).join('/');
if (baseParts) { if (baseParts) {
...@@ -325,16 +320,12 @@ var requirejs, require, define; ...@@ -325,16 +320,12 @@ var requirejs, require, define;
//Match, update name to the new value. //Match, update name to the new value.
foundMap = mapValue; foundMap = mapValue;
foundI = i; foundI = i;
break; break outerLoop;
} }
} }
} }
} }
if (foundMap) {
break;
}
//Check for a star map match, but just hold on to it, //Check for a star map match, but just hold on to it,
//if there is a shorter segment match later in a matching //if there is a shorter segment match later in a matching
//config, then favor over this star map. //config, then favor over this star map.
...@@ -355,7 +346,11 @@ var requirejs, require, define; ...@@ -355,7 +346,11 @@ var requirejs, require, define;
} }
} }
return name; // If the name points to a package's name, use
// the package main instead.
pkgMain = getOwn(config.pkgs, name);
return pkgMain ? pkgMain : name;
} }
function removeScript(name) { function removeScript(name) {
...@@ -373,12 +368,17 @@ var requirejs, require, define; ...@@ -373,12 +368,17 @@ var requirejs, require, define;
function hasPathFallback(id) { function hasPathFallback(id) {
var pathConfig = getOwn(config.paths, id); var pathConfig = getOwn(config.paths, id);
if (pathConfig && isArray(pathConfig) && pathConfig.length > 1) { if (pathConfig && isArray(pathConfig) && pathConfig.length > 1) {
removeScript(id);
//Pop off the first array value, since it failed, and //Pop off the first array value, since it failed, and
//retry //retry
pathConfig.shift(); pathConfig.shift();
context.require.undef(id); context.require.undef(id);
context.require([id]);
//Custom require that does not do map translation, since
//ID is "absolute", already mapped/resolved.
context.makeRequire(null, {
skipMap: true
})([id]);
return true; return true;
} }
} }
...@@ -444,7 +444,16 @@ var requirejs, require, define; ...@@ -444,7 +444,16 @@ var requirejs, require, define;
return normalize(name, parentName, applyMap); return normalize(name, parentName, applyMap);
}); });
} else { } else {
normalizedName = normalize(name, parentName, applyMap); // If nested plugin references, then do not try to
// normalize, as it will not normalize correctly. This
// places a restriction on resourceIds, and the longer
// term solution is not to normalize until plugins are
// loaded and all normalizations to allow for async
// loading of a loader plugin. But for now, fixes the
// common uses. Details in #1131
normalizedName = name.indexOf('!') === -1 ?
normalize(name, parentName, applyMap) :
name;
} }
} else { } else {
//A regular module. //A regular module.
...@@ -549,7 +558,7 @@ var requirejs, require, define; ...@@ -549,7 +558,7 @@ var requirejs, require, define;
//local var ref to defQueue, so cannot just reassign the one //local var ref to defQueue, so cannot just reassign the one
//on context. //on context.
apsp.apply(defQueue, apsp.apply(defQueue,
[defQueue.length - 1, 0].concat(globalDefQueue)); [defQueue.length, 0].concat(globalDefQueue));
globalDefQueue = []; globalDefQueue = [];
} }
} }
...@@ -566,7 +575,7 @@ var requirejs, require, define; ...@@ -566,7 +575,7 @@ var requirejs, require, define;
mod.usingExports = true; mod.usingExports = true;
if (mod.map.isDefine) { if (mod.map.isDefine) {
if (mod.exports) { if (mod.exports) {
return mod.exports; return (defined[mod.map.id] = mod.exports);
} else { } else {
return (mod.exports = defined[mod.map.id] = {}); return (mod.exports = defined[mod.map.id] = {});
} }
...@@ -580,15 +589,9 @@ var requirejs, require, define; ...@@ -580,15 +589,9 @@ var requirejs, require, define;
id: mod.map.id, id: mod.map.id,
uri: mod.map.url, uri: mod.map.url,
config: function () { config: function () {
var c, return getOwn(config.config, mod.map.id) || {};
pkg = getOwn(config.pkgs, mod.map.id);
// For packages, only support config targeted
// at the main module.
c = pkg ? getOwn(config.config, mod.map.id + '/' + pkg.main) :
getOwn(config.config, mod.map.id);
return c || {};
}, },
exports: defined[mod.map.id] exports: mod.exports || (mod.exports = {})
}); });
} }
} }
...@@ -629,7 +632,7 @@ var requirejs, require, define; ...@@ -629,7 +632,7 @@ var requirejs, require, define;
} }
function checkLoaded() { function checkLoaded() {
var map, modId, err, usingPathFallback, var err, usingPathFallback,
waitInterval = config.waitSeconds * 1000, waitInterval = config.waitSeconds * 1000,
//It is possible to disable the wait interval by using waitSeconds of 0. //It is possible to disable the wait interval by using waitSeconds of 0.
expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(), expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(),
...@@ -647,8 +650,8 @@ var requirejs, require, define; ...@@ -647,8 +650,8 @@ var requirejs, require, define;
//Figure out the state of all the modules. //Figure out the state of all the modules.
eachProp(enabledRegistry, function (mod) { eachProp(enabledRegistry, function (mod) {
map = mod.map; var map = mod.map,
modId = map.id; modId = map.id;
//Skip things that are not enabled or in error state. //Skip things that are not enabled or in error state.
if (!mod.enabled) { if (!mod.enabled) {
...@@ -871,17 +874,14 @@ var requirejs, require, define; ...@@ -871,17 +874,14 @@ var requirejs, require, define;
exports = context.execCb(id, factory, depExports, exports); exports = context.execCb(id, factory, depExports, exports);
} }
if (this.map.isDefine) { // Favor return value over exports. If node/cjs in play,
//If setting exports via 'module' is in play, // then will not have a return value anyway. Favor
//favor that over return value and exports. After that, // module.exports assignment over exports object.
//favor a non-undefined return value over exports use. if (this.map.isDefine && exports === undefined) {
cjsModule = this.module; cjsModule = this.module;
if (cjsModule && if (cjsModule) {
cjsModule.exports !== undefined &&
//Make sure it is not already the exports value
cjsModule.exports !== this.exports) {
exports = cjsModule.exports; exports = cjsModule.exports;
} else if (exports === undefined && this.usingExports) { } else if (this.usingExports) {
//exports already set the defined value. //exports already set the defined value.
exports = this.exports; exports = this.exports;
} }
...@@ -941,6 +941,7 @@ var requirejs, require, define; ...@@ -941,6 +941,7 @@ var requirejs, require, define;
on(pluginMap, 'defined', bind(this, function (plugin) { on(pluginMap, 'defined', bind(this, function (plugin) {
var load, normalizedMap, normalizedMod, var load, normalizedMap, normalizedMod,
bundleId = getOwn(bundlesMap, this.map.id),
name = this.map.name, name = this.map.name,
parentName = this.map.parentMap ? this.map.parentMap.name : null, parentName = this.map.parentMap ? this.map.parentMap.name : null,
localRequire = context.makeRequire(map.parentMap, { localRequire = context.makeRequire(map.parentMap, {
...@@ -986,6 +987,14 @@ var requirejs, require, define; ...@@ -986,6 +987,14 @@ var requirejs, require, define;
return; return;
} }
//If a paths config, then just load that file instead to
//resolve the plugin, as it is built into that paths layer.
if (bundleId) {
this.map.url = context.nameToUrl(bundleId);
this.load();
return;
}
load = bind(this, function (value) { load = bind(this, function (value) {
this.init([], function () { return value; }, null, { this.init([], function () { return value; }, null, {
enabled: true enabled: true
...@@ -1114,6 +1123,13 @@ var requirejs, require, define; ...@@ -1114,6 +1123,13 @@ var requirejs, require, define;
if (this.errback) { if (this.errback) {
on(depMap, 'error', bind(this, this.errback)); on(depMap, 'error', bind(this, this.errback));
} else if (this.events.error) {
// No direct errback on this module, but something
// else is listening for errors, so be sure to
// propagate the error correctly.
on(depMap, 'error', bind(this, function(err) {
this.emit('error', err);
}));
} }
} }
...@@ -1250,31 +1266,38 @@ var requirejs, require, define; ...@@ -1250,31 +1266,38 @@ var requirejs, require, define;
} }
} }
//Save off the paths and packages since they require special processing, //Save off the paths since they require special processing,
//they are additive. //they are additive.
var pkgs = config.pkgs, var shim = config.shim,
shim = config.shim,
objs = { objs = {
paths: true, paths: true,
bundles: true,
config: true, config: true,
map: true map: true
}; };
eachProp(cfg, function (value, prop) { eachProp(cfg, function (value, prop) {
if (objs[prop]) { if (objs[prop]) {
if (prop === 'map') { if (!config[prop]) {
if (!config.map) { config[prop] = {};
config.map = {};
}
mixin(config[prop], value, true, true);
} else {
mixin(config[prop], value, true);
} }
mixin(config[prop], value, true, true);
} else { } else {
config[prop] = value; config[prop] = value;
} }
}); });
//Reverse map the bundles
if (cfg.bundles) {
eachProp(cfg.bundles, function (value, prop) {
each(value, function (v) {
if (v !== prop) {
bundlesMap[v] = prop;
}
});
});
}
//Merge shim //Merge shim
if (cfg.shim) { if (cfg.shim) {
eachProp(cfg.shim, function (value, id) { eachProp(cfg.shim, function (value, id) {
...@@ -1295,29 +1318,25 @@ var requirejs, require, define; ...@@ -1295,29 +1318,25 @@ var requirejs, require, define;
//Adjust packages if necessary. //Adjust packages if necessary.
if (cfg.packages) { if (cfg.packages) {
each(cfg.packages, function (pkgObj) { each(cfg.packages, function (pkgObj) {
var location; var location, name;
pkgObj = typeof pkgObj === 'string' ? { name: pkgObj } : pkgObj; pkgObj = typeof pkgObj === 'string' ? { name: pkgObj } : pkgObj;
name = pkgObj.name;
location = pkgObj.location; location = pkgObj.location;
if (location) {
config.paths[name] = pkgObj.location;
}
//Create a brand new object on pkgs, since currentPackages can //Save pointer to main module ID for pkg name.
//be passed in again, and config.pkgs is the internal transformed //Remove leading dot in main, so main paths are normalized,
//state for all package configs. //and remove any trailing .js, since different package
pkgs[pkgObj.name] = { //envs have different conventions: some use a module name,
name: pkgObj.name, //some use a file name.
location: location || pkgObj.name, config.pkgs[name] = pkgObj.name + '/' + (pkgObj.main || 'main')
//Remove leading dot in main, so main paths are normalized, .replace(currDirRegExp, '')
//and remove any trailing .js, since different package .replace(jsSuffixRegExp, '');
//envs have different conventions: some use a module name,
//some use a file name.
main: (pkgObj.main || 'main')
.replace(currDirRegExp, '')
.replace(jsSuffixRegExp, '')
};
}); });
//Done with modifications, assing packages back to context config
config.pkgs = pkgs;
} }
//If there are any "waiting to execute" modules in the registry, //If there are any "waiting to execute" modules in the registry,
...@@ -1464,10 +1483,21 @@ var requirejs, require, define; ...@@ -1464,10 +1483,21 @@ var requirejs, require, define;
var map = makeModuleMap(id, relMap, true), var map = makeModuleMap(id, relMap, true),
mod = getOwn(registry, id); mod = getOwn(registry, id);
removeScript(id);
delete defined[id]; delete defined[id];
delete urlFetched[map.url]; delete urlFetched[map.url];
delete undefEvents[id]; delete undefEvents[id];
//Clean queued defines too. Go backwards
//in array so that the splices do not
//mess up the iteration.
eachReverse(defQueue, function(args, i) {
if(args[0] === id) {
defQueue.splice(i, 1);
}
});
if (mod) { if (mod) {
//Hold on to listeners in case the //Hold on to listeners in case the
//module will be attempted to be reloaded //module will be attempted to be reloaded
...@@ -1487,7 +1517,7 @@ var requirejs, require, define; ...@@ -1487,7 +1517,7 @@ var requirejs, require, define;
/** /**
* Called to enable a module if it is still in the registry * Called to enable a module if it is still in the registry
* awaiting enablement. A second arg, parent, the parent module, * awaiting enablement. A second arg, parent, the parent module,
* is passed in for context, when this method is overriden by * is passed in for context, when this method is overridden by
* the optimizer. Not shown here to keep code compact. * the optimizer. Not shown here to keep code compact.
*/ */
enable: function (depMap) { enable: function (depMap) {
...@@ -1561,8 +1591,19 @@ var requirejs, require, define; ...@@ -1561,8 +1591,19 @@ var requirejs, require, define;
* internal API, not a public one. Use toUrl for the public API. * internal API, not a public one. Use toUrl for the public API.
*/ */
nameToUrl: function (moduleName, ext, skipExt) { nameToUrl: function (moduleName, ext, skipExt) {
var paths, pkgs, pkg, pkgPath, syms, i, parentModule, url, var paths, syms, i, parentModule, url,
parentPath; parentPath, bundleId,
pkgMain = getOwn(config.pkgs, moduleName);
if (pkgMain) {
moduleName = pkgMain;
}
bundleId = getOwn(bundlesMap, moduleName);
if (bundleId) {
return context.nameToUrl(bundleId, ext, skipExt);
}
//If a colon is in the URL, it indicates a protocol is used and it is just //If a colon is in the URL, it indicates a protocol is used and it is just
//an URL to a file, or if it starts with a slash, contains a query arg (i.e. ?) //an URL to a file, or if it starts with a slash, contains a query arg (i.e. ?)
...@@ -1576,7 +1617,6 @@ var requirejs, require, define; ...@@ -1576,7 +1617,6 @@ var requirejs, require, define;
} else { } else {
//A module that needs to be converted to a path. //A module that needs to be converted to a path.
paths = config.paths; paths = config.paths;
pkgs = config.pkgs;
syms = moduleName.split('/'); syms = moduleName.split('/');
//For each module name segment, see if there is a path //For each module name segment, see if there is a path
...@@ -1584,7 +1624,7 @@ var requirejs, require, define; ...@@ -1584,7 +1624,7 @@ var requirejs, require, define;
//and work up from it. //and work up from it.
for (i = syms.length; i > 0; i -= 1) { for (i = syms.length; i > 0; i -= 1) {
parentModule = syms.slice(0, i).join('/'); parentModule = syms.slice(0, i).join('/');
pkg = getOwn(pkgs, parentModule);
parentPath = getOwn(paths, parentModule); parentPath = getOwn(paths, parentModule);
if (parentPath) { if (parentPath) {
//If an array, it means there are a few choices, //If an array, it means there are a few choices,
...@@ -1594,22 +1634,12 @@ var requirejs, require, define; ...@@ -1594,22 +1634,12 @@ var requirejs, require, define;
} }
syms.splice(0, i, parentPath); syms.splice(0, i, parentPath);
break; break;
} else if (pkg) {
//If module name is just the package name, then looking
//for the main module.
if (moduleName === pkg.name) {
pkgPath = pkg.location + '/' + pkg.main;
} else {
pkgPath = pkg.location;
}
syms.splice(0, i, pkgPath);
break;
} }
} }
//Join the path parts together, then figure out if baseUrl is needed. //Join the path parts together, then figure out if baseUrl is needed.
url = syms.join('/'); url = syms.join('/');
url += (ext || (/\?/.test(url) || skipExt ? '' : '.js')); url += (ext || (/^data\:|\?/.test(url) || skipExt ? '' : '.js'));
url = (url.charAt(0) === '/' || url.match(/^[\w\+\.\-]+:/) ? '' : config.baseUrl) + url; url = (url.charAt(0) === '/' || url.match(/^[\w\+\.\-]+:/) ? '' : config.baseUrl) + url;
} }
...@@ -1918,7 +1948,7 @@ var requirejs, require, define; ...@@ -1918,7 +1948,7 @@ var requirejs, require, define;
} }
//Look for a data-main script attribute, which could also adjust the baseUrl. //Look for a data-main script attribute, which could also adjust the baseUrl.
if (isBrowser) { if (isBrowser && !cfg.skipDataMain) {
//Figure out baseUrl. Get it from the script tag with require.js in it. //Figure out baseUrl. Get it from the script tag with require.js in it.
eachReverse(scripts(), function (script) { eachReverse(scripts(), function (script) {
//Set the 'head' where we can append children by //Set the 'head' where we can append children by
......
...@@ -12,104 +12,77 @@ button { ...@@ -12,104 +12,77 @@ button {
font-size: 100%; font-size: 100%;
vertical-align: baseline; vertical-align: baseline;
font-family: inherit; font-family: inherit;
font-weight: inherit;
color: inherit; color: inherit;
-webkit-appearance: none; -webkit-appearance: none;
-ms-appearance: none;
-o-appearance: none;
appearance: none; appearance: none;
-webkit-font-smoothing: antialiased;
-moz-font-smoothing: antialiased;
font-smoothing: antialiased;
} }
body { body {
font: 14px 'Helvetica Neue', Helvetica, Arial, sans-serif; font: 14px 'Helvetica Neue', Helvetica, Arial, sans-serif;
line-height: 1.4em; line-height: 1.4em;
background: #eaeaea url('bg.png'); background: #f5f5f5;
color: #4d4d4d; color: #4d4d4d;
width: 550px; min-width: 230px;
max-width: 550px;
margin: 0 auto; margin: 0 auto;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-font-smoothing: antialiased; -moz-font-smoothing: antialiased;
-ms-font-smoothing: antialiased;
-o-font-smoothing: antialiased;
font-smoothing: antialiased; font-smoothing: antialiased;
font-weight: 300;
} }
button, button,
input[type="checkbox"] { input[type="checkbox"] {
outline: none; outline: none;
}
.hidden {
display: none;
} }
#todoapp { #todoapp {
background: #fff; background: #fff;
background: rgba(255, 255, 255, 0.9);
margin: 130px 0 40px 0; margin: 130px 0 40px 0;
border: 1px solid #ccc;
position: relative; position: relative;
border-top-left-radius: 2px; box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2),
border-top-right-radius: 2px; 0 25px 50px 0 rgba(0, 0, 0, 0.1);
box-shadow: 0 2px 6px 0 rgba(0, 0, 0, 0.2),
0 25px 50px 0 rgba(0, 0, 0, 0.15);
}
#todoapp:before {
content: '';
border-left: 1px solid #f5d6d6;
border-right: 1px solid #f5d6d6;
width: 2px;
position: absolute;
top: 0;
left: 40px;
height: 100%;
} }
#todoapp input::-webkit-input-placeholder { #todoapp input::-webkit-input-placeholder {
font-style: italic; font-style: italic;
font-weight: 300;
color: #e6e6e6;
} }
#todoapp input::-moz-placeholder { #todoapp input::-moz-placeholder {
font-style: italic; font-style: italic;
color: #a9a9a9; font-weight: 300;
color: #e6e6e6;
}
#todoapp input::input-placeholder {
font-style: italic;
font-weight: 300;
color: #e6e6e6;
} }
#todoapp h1 { #todoapp h1 {
position: absolute; position: absolute;
top: -120px; top: -155px;
width: 100%; width: 100%;
font-size: 70px; font-size: 100px;
font-weight: bold; font-weight: 100;
text-align: center; text-align: center;
color: #b3b3b3; color: rgba(175, 47, 47, 0.15);
color: rgba(255, 255, 255, 0.3);
text-shadow: -1px -1px rgba(0, 0, 0, 0.2);
-webkit-text-rendering: optimizeLegibility; -webkit-text-rendering: optimizeLegibility;
-moz-text-rendering: optimizeLegibility; -moz-text-rendering: optimizeLegibility;
-ms-text-rendering: optimizeLegibility;
-o-text-rendering: optimizeLegibility;
text-rendering: optimizeLegibility; text-rendering: optimizeLegibility;
} }
#header {
padding-top: 15px;
border-radius: inherit;
}
#header:before {
content: '';
position: absolute;
top: 0;
right: 0;
left: 0;
height: 15px;
z-index: 2;
border-bottom: 1px solid #6c615c;
background: #8d7d77;
background: -webkit-gradient(linear, left top, left bottom, from(rgba(132, 110, 100, 0.8)),to(rgba(101, 84, 76, 0.8)));
background: -webkit-linear-gradient(top, rgba(132, 110, 100, 0.8), rgba(101, 84, 76, 0.8));
background: linear-gradient(top, rgba(132, 110, 100, 0.8), rgba(101, 84, 76, 0.8));
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,StartColorStr='#9d8b83', EndColorStr='#847670');
border-top-left-radius: 1px;
border-top-right-radius: 1px;
}
#new-todo, #new-todo,
.edit { .edit {
position: relative; position: relative;
...@@ -117,6 +90,7 @@ input[type="checkbox"] { ...@@ -117,6 +90,7 @@ input[type="checkbox"] {
width: 100%; width: 100%;
font-size: 24px; font-size: 24px;
font-family: inherit; font-family: inherit;
font-weight: inherit;
line-height: 1.4em; line-height: 1.4em;
border: 0; border: 0;
outline: none; outline: none;
...@@ -124,29 +98,23 @@ input[type="checkbox"] { ...@@ -124,29 +98,23 @@ input[type="checkbox"] {
padding: 6px; padding: 6px;
border: 1px solid #999; border: 1px solid #999;
box-shadow: inset 0 -1px 5px 0 rgba(0, 0, 0, 0.2); box-shadow: inset 0 -1px 5px 0 rgba(0, 0, 0, 0.2);
-moz-box-sizing: border-box;
-ms-box-sizing: border-box;
-o-box-sizing: border-box;
box-sizing: border-box; box-sizing: border-box;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-font-smoothing: antialiased; -moz-font-smoothing: antialiased;
-ms-font-smoothing: antialiased;
-o-font-smoothing: antialiased;
font-smoothing: antialiased; font-smoothing: antialiased;
} }
#new-todo { #new-todo {
padding: 16px 16px 16px 60px; padding: 16px 16px 16px 60px;
border: none; border: none;
background: rgba(0, 0, 0, 0.02); background: rgba(0, 0, 0, 0.003);
z-index: 2; box-shadow: inset 0 -2px 1px rgba(0,0,0,0.03);
box-shadow: none;
} }
#main { #main {
position: relative; position: relative;
z-index: 2; z-index: 2;
border-top: 1px dotted #adadad; border-top: 1px solid #e6e6e6;
} }
label[for='toggle-all'] { label[for='toggle-all'] {
...@@ -155,19 +123,19 @@ label[for='toggle-all'] { ...@@ -155,19 +123,19 @@ label[for='toggle-all'] {
#toggle-all { #toggle-all {
position: absolute; position: absolute;
top: -42px; top: -55px;
left: -4px; left: -12px;
width: 40px; width: 60px;
height: 34px;
text-align: center; text-align: center;
/* Mobile Safari */ border: none; /* Mobile Safari */
border: none;
} }
#toggle-all:before { #toggle-all:before {
content: '»'; content: '';
font-size: 28px; font-size: 22px;
color: #d9d9d9; color: #e6e6e6;
padding: 0 25px 7px; padding: 10px 27px 10px 27px;
} }
#toggle-all:checked:before { #toggle-all:checked:before {
...@@ -183,7 +151,7 @@ label[for='toggle-all'] { ...@@ -183,7 +151,7 @@ label[for='toggle-all'] {
#todo-list li { #todo-list li {
position: relative; position: relative;
font-size: 24px; font-size: 24px;
border-bottom: 1px dotted #ccc; border-bottom: 1px solid #ededed;
} }
#todo-list li:last-child { #todo-list li:last-child {
...@@ -215,28 +183,17 @@ label[for='toggle-all'] { ...@@ -215,28 +183,17 @@ label[for='toggle-all'] {
top: 0; top: 0;
bottom: 0; bottom: 0;
margin: auto 0; margin: auto 0;
/* Mobile Safari */ border: none; /* Mobile Safari */
border: none;
-webkit-appearance: none; -webkit-appearance: none;
-ms-appearance: none;
-o-appearance: none;
appearance: none; appearance: none;
} }
#todo-list li .toggle:after { #todo-list li .toggle:after {
content: '✔'; content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="-10 -18 100 135"><circle cx="50" cy="50" r="50" fill="none" stroke="#ededed" stroke-width="3"/></svg>');
/* 40 + a couple of pixels visual adjustment */
line-height: 43px;
font-size: 20px;
color: #d9d9d9;
text-shadow: 0 -1px 0 #bfbfbf;
} }
#todo-list li .toggle:checked:after { #todo-list li .toggle:checked:after {
color: #85ada7; content: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="-10 -18 100 135"><circle cx="50" cy="50" r="50" fill="none" stroke="#bddad5" stroke-width="3"/><path fill="#5dc2af" d="M72 25L42 71 27 56l-4 4 20 20 34-52z"/></svg>');
text-shadow: 0 1px 0 #669991;
bottom: 1px;
position: relative;
} }
#todo-list li label { #todo-list li label {
...@@ -246,12 +203,11 @@ label[for='toggle-all'] { ...@@ -246,12 +203,11 @@ label[for='toggle-all'] {
margin-left: 45px; margin-left: 45px;
display: block; display: block;
line-height: 1.2; line-height: 1.2;
-webkit-transition: color 0.4s;
transition: color 0.4s; transition: color 0.4s;
} }
#todo-list li.completed label { #todo-list li.completed label {
color: #a9a9a9; color: #d9d9d9;
text-decoration: line-through; text-decoration: line-through;
} }
...@@ -264,21 +220,18 @@ label[for='toggle-all'] { ...@@ -264,21 +220,18 @@ label[for='toggle-all'] {
width: 40px; width: 40px;
height: 40px; height: 40px;
margin: auto 0; margin: auto 0;
font-size: 22px; font-size: 30px;
color: #a88a8a; color: #cc9a9a;
-webkit-transition: all 0.2s; margin-bottom: 11px;
transition: all 0.2s; transition: color 0.2s ease-out;
} }
#todo-list li .destroy:hover { #todo-list li .destroy:hover {
text-shadow: 0 0 1px #000, color: #af5b5e;
0 0 10px rgba(199, 107, 107, 0.8);
-webkit-transform: scale(1.3);
transform: scale(1.3);
} }
#todo-list li .destroy:after { #todo-list li .destroy:after {
content: ''; content: '×';
} }
#todo-list li:hover .destroy { #todo-list li:hover .destroy {
...@@ -295,29 +248,25 @@ label[for='toggle-all'] { ...@@ -295,29 +248,25 @@ label[for='toggle-all'] {
#footer { #footer {
color: #777; color: #777;
padding: 0 15px; padding: 10px 15px;
position: absolute;
right: 0;
bottom: -31px;
left: 0;
height: 20px; height: 20px;
z-index: 1;
text-align: center; text-align: center;
border-top: 1px solid #e6e6e6;
} }
#footer:before { #footer:before {
content: ''; content: '';
position: absolute; position: absolute;
right: 0; right: 0;
bottom: 31px; bottom: 0;
left: 0; left: 0;
height: 50px; height: 50px;
z-index: -1; overflow: hidden;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.3), box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2),
0 6px 0 -3px rgba(255, 255, 255, 0.8), 0 8px 0 -3px #f6f6f6,
0 7px 1px -3px rgba(0, 0, 0, 0.3), 0 9px 1px -3px rgba(0, 0, 0, 0.2),
0 43px 0 -6px rgba(255, 255, 255, 0.8), 0 16px 0 -6px #f6f6f6,
0 44px 2px -6px rgba(0, 0, 0, 0.2); 0 17px 2px -6px rgba(0, 0, 0, 0.2);
} }
#todo-count { #todo-count {
...@@ -325,6 +274,10 @@ label[for='toggle-all'] { ...@@ -325,6 +274,10 @@ label[for='toggle-all'] {
text-align: left; text-align: left;
} }
#todo-count strong {
font-weight: 300;
}
#filters { #filters {
margin: 0; margin: 0;
padding: 0; padding: 0;
...@@ -339,49 +292,73 @@ label[for='toggle-all'] { ...@@ -339,49 +292,73 @@ label[for='toggle-all'] {
} }
#filters li a { #filters li a {
color: #83756f; color: inherit;
margin: 2px; margin: 3px;
padding: 3px 7px;
text-decoration: none; text-decoration: none;
border: 1px solid transparent;
border-radius: 3px;
}
#filters li a.selected,
#filters li a:hover {
border-color: rgba(175, 47, 47, 0.1);
} }
#filters li a.selected { #filters li a.selected {
font-weight: bold; border-color: rgba(175, 47, 47, 0.2);
} }
#clear-completed { #clear-completed,
html #clear-completed:active {
float: right; float: right;
position: relative; position: relative;
line-height: 20px; line-height: 20px;
text-decoration: none; text-decoration: none;
background: rgba(0, 0, 0, 0.1); cursor: pointer;
font-size: 11px; visibility: hidden;
padding: 0 10px; position: relative;
border-radius: 3px; }
box-shadow: 0 -1px 0 0 rgba(0, 0, 0, 0.2);
#clear-completed::after {
visibility: visible;
content: 'Clear completed';
position: absolute;
top: 0;
right: 0;
white-space: nowrap;
} }
#clear-completed:hover { #clear-completed:hover::after {
background: rgba(0, 0, 0, 0.15); text-decoration: underline;
box-shadow: 0 -1px 0 0 rgba(0, 0, 0, 0.3);
} }
#info { #info {
margin: 65px auto 0; margin: 65px auto 0;
color: #a6a6a6; color: #bfbfbf;
font-size: 12px; font-size: 10px;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7); text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
text-align: center; text-align: center;
} }
#info p {
line-height: 1;
}
#info a { #info a {
color: inherit; color: inherit;
text-decoration: none;
font-weight: 400;
}
#info a:hover {
text-decoration: underline;
} }
/* /*
Hack to remove background from Mobile Safari. Hack to remove background from Mobile Safari.
Can't use it globally since it destroys checkboxes in Firefox and Opera Can't use it globally since it destroys checkboxes in Firefox
*/ */
@media screen and (-webkit-min-device-pixel-ratio:0) { @media screen and (-webkit-min-device-pixel-ratio:0) {
#toggle-all, #toggle-all,
#todo-list li .toggle { #todo-list li .toggle {
...@@ -393,10 +370,6 @@ label[for='toggle-all'] { ...@@ -393,10 +370,6 @@ label[for='toggle-all'] {
} }
#toggle-all { #toggle-all {
top: -56px;
left: -15px;
width: 65px;
height: 41px;
-webkit-transform: rotate(90deg); -webkit-transform: rotate(90deg);
transform: rotate(90deg); transform: rotate(90deg);
-webkit-appearance: none; -webkit-appearance: none;
...@@ -404,151 +377,12 @@ label[for='toggle-all'] { ...@@ -404,151 +377,12 @@ label[for='toggle-all'] {
} }
} }
.hidden { @media (max-width: 430px) {
display: none; #footer {
} height: 50px;
hr {
margin: 20px 0;
border: 0;
border-top: 1px dashed #C5C5C5;
border-bottom: 1px dashed #F7F7F7;
}
.learn a {
font-weight: normal;
text-decoration: none;
color: #b83f45;
}
.learn a:hover {
text-decoration: underline;
color: #787e7e;
}
.learn h3,
.learn h4,
.learn h5 {
margin: 10px 0;
font-weight: 500;
line-height: 1.2;
color: #000;
}
.learn h3 {
font-size: 24px;
}
.learn h4 {
font-size: 18px;
}
.learn h5 {
margin-bottom: 0;
font-size: 14px;
}
.learn ul {
padding: 0;
margin: 0 0 30px 25px;
}
.learn li {
line-height: 20px;
}
.learn p {
font-size: 15px;
font-weight: 300;
line-height: 1.3;
margin-top: 0;
margin-bottom: 0;
}
.quote {
border: none;
margin: 20px 0 60px 0;
}
.quote p {
font-style: italic;
}
.quote p:before {
content: '“';
font-size: 50px;
opacity: .15;
position: absolute;
top: -20px;
left: 3px;
}
.quote p:after {
content: '”';
font-size: 50px;
opacity: .15;
position: absolute;
bottom: -42px;
right: 3px;
}
.quote footer {
position: absolute;
bottom: -40px;
right: 0;
}
.quote footer img {
border-radius: 3px;
}
.quote footer a {
margin-left: 5px;
vertical-align: middle;
}
.speech-bubble {
position: relative;
padding: 10px;
background: rgba(0, 0, 0, .04);
border-radius: 5px;
}
.speech-bubble:after {
content: '';
position: absolute;
top: 100%;
right: 30px;
border: 13px solid transparent;
border-top-color: rgba(0, 0, 0, .04);
}
.learn-bar > .learn {
position: absolute;
width: 272px;
top: 8px;
left: -300px;
padding: 10px;
border-radius: 5px;
background-color: rgba(255, 255, 255, .6);
-webkit-transition-property: left;
transition-property: left;
-webkit-transition-duration: 500ms;
transition-duration: 500ms;
}
@media (min-width: 899px) {
.learn-bar {
width: auto;
margin: 0 0 0 300px;
}
.learn-bar > .learn {
left: 8px;
} }
.learn-bar #todoapp { #filters {
width: 550px; bottom: 10px;
margin: 130px auto 40px auto;
} }
} }
hr {
margin: 20px 0;
border: 0;
border-top: 1px dashed #c5c5c5;
border-bottom: 1px dashed #f7f7f7;
}
.learn a {
font-weight: normal;
text-decoration: none;
color: #b83f45;
}
.learn a:hover {
text-decoration: underline;
color: #787e7e;
}
.learn h3,
.learn h4,
.learn h5 {
margin: 10px 0;
font-weight: 500;
line-height: 1.2;
color: #000;
}
.learn h3 {
font-size: 24px;
}
.learn h4 {
font-size: 18px;
}
.learn h5 {
margin-bottom: 0;
font-size: 14px;
}
.learn ul {
padding: 0;
margin: 0 0 30px 25px;
}
.learn li {
line-height: 20px;
}
.learn p {
font-size: 15px;
font-weight: 300;
line-height: 1.3;
margin-top: 0;
margin-bottom: 0;
}
#issue-count {
display: none;
}
.quote {
border: none;
margin: 20px 0 60px 0;
}
.quote p {
font-style: italic;
}
.quote p:before {
content: '“';
font-size: 50px;
opacity: .15;
position: absolute;
top: -20px;
left: 3px;
}
.quote p:after {
content: '”';
font-size: 50px;
opacity: .15;
position: absolute;
bottom: -42px;
right: 3px;
}
.quote footer {
position: absolute;
bottom: -40px;
right: 0;
}
.quote footer img {
border-radius: 3px;
}
.quote footer a {
margin-left: 5px;
vertical-align: middle;
}
.speech-bubble {
position: relative;
padding: 10px;
background: rgba(0, 0, 0, .04);
border-radius: 5px;
}
.speech-bubble:after {
content: '';
position: absolute;
top: 100%;
right: 30px;
border: 13px solid transparent;
border-top-color: rgba(0, 0, 0, .04);
}
.learn-bar > .learn {
position: absolute;
width: 272px;
top: 8px;
left: -300px;
padding: 10px;
border-radius: 5px;
background-color: rgba(255, 255, 255, .6);
transition-property: left;
transition-duration: 500ms;
}
@media (min-width: 899px) {
.learn-bar {
width: auto;
padding-left: 300px;
}
.learn-bar > .learn {
left: 8px;
}
}
/* global _ */
(function () { (function () {
'use strict'; 'use strict';
/* jshint ignore:start */
// Underscore's Template Module // Underscore's Template Module
// Courtesy of underscorejs.org // Courtesy of underscorejs.org
var _ = (function (_) { var _ = (function (_) {
...@@ -114,6 +116,7 @@ ...@@ -114,6 +116,7 @@
if (location.hostname === 'todomvc.com') { if (location.hostname === 'todomvc.com') {
window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script')); window._gaq = [['_setAccount','UA-31081062-1'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//www.google-analytics.com/ga.js';s.parentNode.insertBefore(g,s)}(document,'script'));
} }
/* jshint ignore:end */
function redirect() { function redirect() {
if (location.hostname === 'tastejs.github.io') { if (location.hostname === 'tastejs.github.io') {
...@@ -175,13 +178,17 @@ ...@@ -175,13 +178,17 @@
if (learnJSON.backend) { if (learnJSON.backend) {
this.frameworkJSON = learnJSON.backend; this.frameworkJSON = learnJSON.backend;
this.frameworkJSON.issueLabel = framework;
this.append({ this.append({
backend: true backend: true
}); });
} else if (learnJSON[framework]) { } else if (learnJSON[framework]) {
this.frameworkJSON = learnJSON[framework]; this.frameworkJSON = learnJSON[framework];
this.frameworkJSON.issueLabel = framework;
this.append(); this.append();
} }
this.fetchIssueCount();
} }
Learn.prototype.append = function (opts) { Learn.prototype.append = function (opts) {
...@@ -212,6 +219,26 @@ ...@@ -212,6 +219,26 @@
document.body.insertAdjacentHTML('afterBegin', aside.outerHTML); document.body.insertAdjacentHTML('afterBegin', aside.outerHTML);
}; };
Learn.prototype.fetchIssueCount = function () {
var issueLink = document.getElementById('issue-count-link');
if (issueLink) {
var url = issueLink.href.replace('https://github.com', 'https://api.github.com/repos');
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onload = function (e) {
var parsedResponse = JSON.parse(e.target.responseText);
if (parsedResponse instanceof Array) {
var count = parsedResponse.length
if (count !== 0) {
issueLink.innerHTML = 'This app has ' + count + ' open issues';
document.getElementById('issue-count').style.display = 'inline';
}
}
};
xhr.send();
}
};
redirect(); redirect();
getFile('learn.json', Learn); getFile('learn.json', Learn);
})(); })();
{
"private": true,
"dependencies": {
"todomvc-common": "^1.0.1",
"todomvc-app-css": "^1.0.1",
"requirejs": "^2.1.6",
"dustjs-linkedin": "^2.5.0",
"dustjs-helpers": "^1.1.1",
"jquery": "^2.0.3",
"mout": "^0.7.1"
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment