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 @@
<head>
<meta charset="utf-8">
<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>
<body>
<section id="todoapp"></section>
......@@ -12,8 +13,8 @@
<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>
</footer>
<script src="bower_components/todomvc-common/base.js"></script>
<script src="bower_components/requirejs/require.js"></script>
<script src="node_modules/todomvc-common/base.js"></script>
<script src="node_modules/requirejs/require.js"></script>
<script src="js/libs/lavaca.js"></script>
<script src="js/app/boot.js"></script>
</body>
......
require.config({
baseUrl: 'js',
paths: {
$: '../bower_components/jquery/jquery',
jquery: '../bower_components/jquery/jquery',
mout: '../bower_components/mout/src',
dust: '../bower_components/dustjs-linkedin/dist/dust-full-1.1.1',
'dust-helpers': '../bower_components/dustjs-linkedin-helpers/dist/dust-helpers-1.1.1',
$: '../node_modules/jquery/dist/jquery',
jquery: '../node_modules/jquery/dist/jquery',
mout: '../node_modules/mout/src',
dust: '../node_modules/dustjs-linkedin/dist/dust-full',
'dust-helpers': '../node_modules/dustjs-helpers/dist/dust-helpers',
rdust: 'libs/require-dust',
lavaca: 'Lavaca',
Lavaca: 'lavaca'
......
//
// Dust-helpers - Additional functionality for dustjs-linkedin package v1.1.1
//
// Copyright (c) 2012, LinkedIn
// Released under the MIT License.
//
/*! dustjs-helpers - v1.6.1
* https://github.com/linkedin/dustjs-helpers
* Copyright (c) 2015 Aleksander Williams; Released under the MIT License */
(function(root, factory) {
if (typeof define === 'function' && define.amd && define.amd.dust === true) {
define(['dust.core'], factory);
} else if (typeof exports === 'object') {
module.exports = factory(require('dustjs-linkedin'));
} else {
factory(root.dust);
}
}(this, function(dust) {
// Use dust's built-in logging when available
var _log = dust.log ? function(msg, level) {
level = level || "INFO";
dust.log(msg, level);
} : 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(dust){
function isSelect(context) {
return context.stack.tail &&
typeof context.stack.tail.head.__select__ !== "undefined";
}
// Note: all error conditions are logged to console and failed silently
function getSelectState(context) {
return context.get('__select__');
}
function addSelectState(context, key) {
var head = context.stack.head,
newContext = context.rebase();
/* make a safe version of console if it is not available
* currently supporting:
* _console.log
* */
var _console = (typeof console !== 'undefined')? console: {
log: function(){
/* a noop*/
if(context.stack && context.stack.tail) {
newContext.stack = context.stack.tail;
}
};
function isSelect(context) {
var value = context.current();
return typeof value === "object" && value.isSelect === true;
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
function jsonFilter(key, value) {
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;
}
......@@ -38,52 +78,55 @@ function filter(chunk, context, bodies, params, filterOp) {
var body = bodies.block,
actualKey,
expectedValue,
selectState,
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);
}
else if (isSelect(context)) {
actualKey = context.current().selectKey;
// supports only one of the blocks in the select to be selected
if (context.current().isResolved) {
} else if (isSelect(context)) {
selectState = getSelectState(context);
actualKey = selectState.key;
// Once one truth test in a select passes, short-circuit the rest of the tests
if (selectState.isResolved) {
filterOp = function() { return false; };
}
}
else {
_console.log ("No key specified for filter in:" + filterOpType + " helper ");
} else {
_log("No key specified for filter in {@" + filterOpType + "}");
return chunk;
}
expectedValue = dust.helpers.tap(params.value, chunk, context);
// 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 (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) {
return chunk.render(body, context);
}
else {
_console.log( "Missing body block in the " + filterOpType + " helper ");
} else {
return chunk;
}
}
else if (bodies['else']) {
} else if (bodies['else']) {
return chunk.render(bodies['else'], context);
}
return chunk;
}
function coerce (value, type, context) {
if (value) {
switch (type || typeof(value)) {
function coerce(value, type, context) {
if (typeof value !== "undefined") {
switch (type || typeof value) {
case 'number': return +value;
case 'string': return String(value);
case 'boolean': {
case 'boolean':
value = (value === 'false' ? false : value);
return Boolean(value);
}
case 'date': return new Date(value);
case 'context': return context.get(value);
}
......@@ -111,26 +154,34 @@ var helpers = {
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
var output = input;
// dust compiles a string/reference such as {foo} to function,
if( typeof input === "function"){
// 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();
} else {
output = '';
chunk.tap(function(data){
output += data;
return '';
}).render(input, context).untap();
if( output === '' ){
output = false;
}
// dust compiles a string/reference such as {foo} to a function
if (typeof input !== "function") {
return input;
}
var dustBodyOutput = '',
returnValue;
//use chunk render to evaluate output. For simple functions result will be returned from render call,
//for dust body functions result will be output via callback function
returnValue = chunk.tap(function(data) {
dustBodyOutput += data;
return '';
}).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) {
......@@ -138,22 +189,25 @@ var helpers = {
if (context.stack.index === context.stack.of - 1) {
return chunk;
}
if(body) {
return bodies.block(chunk, context);
}
else {
if (body) {
return body(chunk, context);
} else {
return chunk;
}
},
"idx": function(chunk, context, bodies) {
var body = bodies.block;
if(body) {
return bodies.block(chunk, context.push(context.stack.index));
"first": function(chunk, context, bodies) {
if (context.stack.index === 0) {
return bodies.block(chunk, context);
}
else {
return chunk;
},
"last": function(chunk, context, bodies) {
if (context.stack.index === context.stack.of - 1) {
return bodies.block(chunk, context);
}
return chunk;
},
/**
......@@ -168,7 +222,7 @@ var helpers = {
to = p.to || 'output',
key = p.key || 'current',
dump;
to = dust.helpers.tap(to, chunk, context),
to = dust.helpers.tap(to, chunk, context);
key = dust.helpers.tap(key, chunk, context);
if (key === 'full') {
dump = JSON.stringify(context.stack, jsonFilter, 2);
......@@ -177,10 +231,13 @@ var helpers = {
dump = JSON.stringify(context.stack.head, jsonFilter, 2);
}
if (to === 'console') {
_console.log(dump);
_log(dump);
return chunk;
}
else {
// encode opening brackets when outputting to html
dump = dump.replace(/</g, '\\u003c');
return chunk.write(dump);
}
},
......@@ -200,33 +257,6 @@ var helpers = {
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
* @param key is the value to perform math against
......@@ -242,47 +272,50 @@ var helpers = {
// operand can be null for "abs", ceil and floor
operand = params.operand,
round = params.round,
mathOut = null,
operError = function(){_console.log("operand is required for this math method"); return null;};
key = dust.helpers.tap(key, chunk, context);
operand = dust.helpers.tap(operand, chunk, context);
mathOut = null;
key = parseFloat(dust.helpers.tap(key, chunk, context));
operand = parseFloat(dust.helpers.tap(operand, chunk, context));
// TODO: handle and tests for negatives and floats in all math operations
switch(method) {
case "mod":
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;
case "add":
mathOut = parseFloat(key) + parseFloat(operand);
mathOut = key + operand;
break;
case "subtract":
mathOut = parseFloat(key) - parseFloat(operand);
mathOut = key - operand;
break;
case "multiply":
mathOut = parseFloat(key) * parseFloat(operand);
mathOut = key * operand;
break;
case "divide":
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;
case "ceil":
mathOut = Math.ceil(parseFloat(key));
mathOut = Math.ceil(key);
break;
case "floor":
mathOut = Math.floor(parseFloat(key));
mathOut = Math.floor(key);
break;
case "round":
mathOut = Math.round(parseFloat(key));
mathOut = Math.round(key);
break;
case "abs":
mathOut = Math.abs(parseFloat(key));
mathOut = Math.abs(key);
break;
case "toint":
mathOut = parseInt(key, 10);
break;
default:
_console.log( "method passed is not supported" );
_log("{@math}: method " + method + " not supported");
}
if (mathOut !== null){
......@@ -292,7 +325,8 @@ var helpers = {
if (bodies && bodies.block) {
// with bodies act like the select helper with mathOut as the key
// 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 {
// self closing math helper will return the calculated output
return chunk.write(mathOut);
......@@ -303,12 +337,12 @@ var helpers = {
}
// no key parameter and no method
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;
},
/**
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
@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"
......@@ -316,23 +350,28 @@ var helpers = {
@param type (optional), supported types are number, boolean, string, date, context, defaults to string
**/
"select": function(chunk, context, bodies, params) {
var body = bodies.block;
// key is required for processing, hence check for defined
if( params && typeof params.key !== "undefined"){
// returns given input as output, if the input is not a dust reference, else does a context lookup
var key = dust.helpers.tap(params.key, chunk, context);
var body = bodies.block,
state, key, len, x;
if (params.hasOwnProperty("key")) {
key = dust.helpers.tap(params.key, chunk, context);
// bodies['else'] is meaningless and is ignored
if( body ) {
return chunk.render(bodies.block, context.push({ isSelect: true, isResolved: false, selectKey: key }));
if (body) {
context = addSelectState(context, key);
state = getSelectState(context);
chunk = chunk.render(body, context);
// Resolve any deferred blocks (currently just {@any} blocks)
if(state.deferreds.length) {
state.isDeferredComplete = true;
for(x=0, len=state.deferreds.length; x<len; x++) {
state.deferreds[x]();
}
else {
_console.log( "Missing body block in the select helper ");
return chunk;
}
} else {
_log("Missing body block in {@select}");
}
// no key
else {
_console.log( "No key given in the select helper!" );
} else {
_log("No key provided for {@select}", "WARN");
}
return chunk;
},
......@@ -349,9 +388,7 @@ var helpers = {
Note : use type="number" when comparing numeric
**/
"eq": function(chunk, context, bodies, params) {
if(params) {
params.filterOpType = "eq";
}
return filter(chunk, context, bodies, params, function(expected, actual) { return actual === expected; });
},
......@@ -367,11 +404,8 @@ var helpers = {
Note : use type="number" when comparing numeric
**/
"ne": function(chunk, context, bodies, params) {
if(params) {
params.filterOpType = "ne";
return filter(chunk, context, bodies, params, function(expected, actual) { return actual !== expected; });
}
return chunk;
},
/**
......@@ -386,10 +420,8 @@ var helpers = {
Note : use type="number" when comparing numeric
**/
"lt": function(chunk, context, bodies, params) {
if(params) {
params.filterOpType = "lt";
return filter(chunk, context, bodies, params, function(expected, actual) { return actual < expected; });
}
},
/**
......@@ -404,14 +436,10 @@ var helpers = {
Note : use type="number" when comparing numeric
**/
"lte": function(chunk, context, bodies, params) {
if(params) {
params.filterOpType = "lte";
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
It can be used standalone or in conjunction with select for multiple branching
......@@ -424,12 +452,8 @@ var helpers = {
Note : use type="number" when comparing numeric
**/
"gt": function(chunk, context, bodies, params) {
// if no params do no go further
if(params) {
params.filterOpType = "gt";
return filter(chunk, context, bodies, params, function(expected, actual) { return actual > expected; });
}
return chunk;
},
/**
......@@ -444,21 +468,82 @@ var helpers = {
Note : use type="number" when comparing numeric
**/
"gte": function(chunk, context, bodies, params) {
if(params) {
params.filterOpType = "gte";
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;
},
// to be used in conjunction with the select helper
// TODO: fix the helper to do nothing when used standalone
/**
* {@none}
* Outputs if no truth tests inside a {@select} pass.
* Must be contained inside a {@select} block.
* The position of the helper does not matter.
*/
"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 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) {
// does not require any params
if(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(expected, actual) { return true; });
return filter(chunk, context, bodies, params, function() { return true; });
},
/**
......@@ -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) {
*/
function makeIterator(src, thisObj){
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':
// typeof null == "object"
return (src != null)? function(val, key, target){
return (src != null)? function(val){
return deepMatches(val, src);
} : src;
case 'string':
case 'number':
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:
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
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 () {
* Checks if the value is created by the `Object` constructor.
*/
function isPlainObject(value) {
return (!!value
&& typeof value === 'object'
&& value.constructor === Object);
return (!!value && typeof value === 'object' &&
value.constructor === Object);
}
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
* @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.
* see: http://github.com/jrburke/requirejs for details
*/
......@@ -12,7 +12,7 @@ var requirejs, require, define;
(function (global) {
var req, s, head, baseElement, dataMain, src,
interactiveScript, currentlyAddingScript, mainScript, subPath,
version = '2.1.8',
version = '2.1.16',
commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,
jsSuffixRegExp = /\.js$/,
......@@ -22,7 +22,7 @@ var requirejs, require, define;
hasOwn = op.hasOwnProperty,
ap = Array.prototype,
apsp = ap.splice,
isBrowser = !!(typeof window !== 'undefined' && navigator && window.document),
isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document),
isWebWorker = !isBrowser && typeof importScripts !== 'undefined',
//PS3 indicates loaded and complete, but need to wait for complete
//specifically. Sequence is 'loading', 'loaded', execution,
......@@ -108,7 +108,10 @@ var requirejs, require, define;
if (source) {
eachProp(source, function (value, 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]) {
target[prop] = {};
}
......@@ -138,7 +141,7 @@ var requirejs, require, define;
throw err;
}
//Allow getting a global that expressed in
//Allow getting a global that is expressed in
//dot notation, like 'a.b.c'.
function getGlobal(value) {
if (!value) {
......@@ -177,7 +180,7 @@ var requirejs, require, define;
if (typeof requirejs !== 'undefined') {
if (isFunction(requirejs)) {
//Do not overwrite and existing requirejs instance.
//Do not overwrite an existing requirejs instance.
return;
}
cfg = requirejs;
......@@ -201,6 +204,7 @@ var requirejs, require, define;
waitSeconds: 7,
baseUrl: './',
paths: {},
bundles: {},
pkgs: {},
shim: {},
config: {}
......@@ -214,6 +218,7 @@ var requirejs, require, define;
defQueue = [],
defined = {},
urlFetched = {},
bundlesMap = {},
requireCounter = 1,
unnormalizedCounter = 1;
......@@ -228,20 +233,19 @@ var requirejs, require, define;
*/
function trimDots(ary) {
var i, part;
for (i = 0; ary[i]; i += 1) {
for (i = 0; i < ary.length; i++) {
part = ary[i];
if (part === '.') {
ary.splice(i, 1);
i -= 1;
} else if (part === '..') {
if (i === 1 && (ary[2] === '..' || ary[0] === '..')) {
//End of the line. Keep at least one non-dot
//path segment at the front so it can be mapped
//correctly to disk. Otherwise, there is likely
//no path mapping for a path starting with '..'.
//This can still fail, but catches the most reasonable
//uses of ..
break;
// If at the start, or previous value is still ..,
// keep them so that when converted to a path it may
// still work when converted to a path, even though
// as an ID it is less than ideal. In larger point
// releases, may be better to just kick out an error.
if (i === 0 || (i == 1 && ary[2] === '..') || ary[i - 1] === '..') {
continue;
} else if (i > 0) {
ary.splice(i - 1, 2);
i -= 2;
......@@ -261,54 +265,45 @@ var requirejs, require, define;
* @returns {String} normalized name
*/
function normalize(name, baseName, applyMap) {
var pkgName, pkgConfig, mapValue, nameParts, i, j, nameSegment,
foundMap, foundI, foundStarMap, starI,
baseParts = baseName && baseName.split('/'),
normalizedBaseParts = baseParts,
var pkgMain, mapValue, nameParts, i, j, nameSegment, lastIndex,
foundMap, foundI, foundStarMap, starI, normalizedBaseParts,
baseParts = (baseName && baseName.split('/')),
map = config.map,
starMap = map && map['*'];
//Adjust any relative paths.
if (name && name.charAt(0) === '.') {
//If have a base name, try to normalize against it,
//otherwise, assume it is a top-level require that will
//be relative to baseUrl in the end.
if (baseName) {
if (getOwn(config.pkgs, baseName)) {
//If the baseName is a package name, then just treat it as one
//name to concat the name with.
normalizedBaseParts = baseParts = [baseName];
} else {
if (name) {
name = name.split('/');
lastIndex = name.length - 1;
// If wanting node ID compatibility, strip .js from end
// of IDs. Have to do this here, and not in nameToUrl
// because node allows either .js or non .js to map
// to same file.
if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
}
// Starts with a '.' so need the baseName
if (name[0].charAt(0) === '.' && baseParts) {
//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);
}
name = normalizedBaseParts.concat(name.split('/'));
trimDots(name);
//Some use of packages may use a . path to reference the
//'main' module name, so normalize for that.
pkgConfig = getOwn(config.pkgs, (pkgName = name[0]));
name = name.join('/');
if (pkgConfig && name === pkgName + '/' + pkgConfig.main) {
name = pkgName;
}
} else if (name.indexOf('./') === 0) {
// No baseName, so this is ID is resolved relative
// to baseUrl, pull off the leading dot.
name = name.substring(2);
}
}
//Apply map config if available.
if (applyMap && map && (baseParts || starMap)) {
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('/');
if (baseParts) {
......@@ -325,14 +320,10 @@ var requirejs, require, define;
//Match, update name to the new value.
foundMap = mapValue;
foundI = i;
break;
}
break outerLoop;
}
}
}
if (foundMap) {
break;
}
//Check for a star map match, but just hold on to it,
......@@ -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) {
......@@ -373,12 +368,17 @@ var requirejs, require, define;
function hasPathFallback(id) {
var pathConfig = getOwn(config.paths, id);
if (pathConfig && isArray(pathConfig) && pathConfig.length > 1) {
removeScript(id);
//Pop off the first array value, since it failed, and
//retry
pathConfig.shift();
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;
}
}
......@@ -444,7 +444,16 @@ var requirejs, require, define;
return normalize(name, parentName, applyMap);
});
} 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 {
//A regular module.
......@@ -549,7 +558,7 @@ var requirejs, require, define;
//local var ref to defQueue, so cannot just reassign the one
//on context.
apsp.apply(defQueue,
[defQueue.length - 1, 0].concat(globalDefQueue));
[defQueue.length, 0].concat(globalDefQueue));
globalDefQueue = [];
}
}
......@@ -566,7 +575,7 @@ var requirejs, require, define;
mod.usingExports = true;
if (mod.map.isDefine) {
if (mod.exports) {
return mod.exports;
return (defined[mod.map.id] = mod.exports);
} else {
return (mod.exports = defined[mod.map.id] = {});
}
......@@ -580,15 +589,9 @@ var requirejs, require, define;
id: mod.map.id,
uri: mod.map.url,
config: function () {
var c,
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 || {};
return getOwn(config.config, mod.map.id) || {};
},
exports: defined[mod.map.id]
exports: mod.exports || (mod.exports = {})
});
}
}
......@@ -629,7 +632,7 @@ var requirejs, require, define;
}
function checkLoaded() {
var map, modId, err, usingPathFallback,
var err, usingPathFallback,
waitInterval = config.waitSeconds * 1000,
//It is possible to disable the wait interval by using waitSeconds of 0.
expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(),
......@@ -647,7 +650,7 @@ var requirejs, require, define;
//Figure out the state of all the modules.
eachProp(enabledRegistry, function (mod) {
map = mod.map;
var map = mod.map,
modId = map.id;
//Skip things that are not enabled or in error state.
......@@ -871,17 +874,14 @@ var requirejs, require, define;
exports = context.execCb(id, factory, depExports, exports);
}
if (this.map.isDefine) {
//If setting exports via 'module' is in play,
//favor that over return value and exports. After that,
//favor a non-undefined return value over exports use.
// Favor return value over exports. If node/cjs in play,
// then will not have a return value anyway. Favor
// module.exports assignment over exports object.
if (this.map.isDefine && exports === undefined) {
cjsModule = this.module;
if (cjsModule &&
cjsModule.exports !== undefined &&
//Make sure it is not already the exports value
cjsModule.exports !== this.exports) {
if (cjsModule) {
exports = cjsModule.exports;
} else if (exports === undefined && this.usingExports) {
} else if (this.usingExports) {
//exports already set the defined value.
exports = this.exports;
}
......@@ -941,6 +941,7 @@ var requirejs, require, define;
on(pluginMap, 'defined', bind(this, function (plugin) {
var load, normalizedMap, normalizedMod,
bundleId = getOwn(bundlesMap, this.map.id),
name = this.map.name,
parentName = this.map.parentMap ? this.map.parentMap.name : null,
localRequire = context.makeRequire(map.parentMap, {
......@@ -986,6 +987,14 @@ var requirejs, require, define;
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) {
this.init([], function () { return value; }, null, {
enabled: true
......@@ -1114,6 +1123,13 @@ var requirejs, require, define;
if (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;
}
}
//Save off the paths and packages since they require special processing,
//Save off the paths since they require special processing,
//they are additive.
var pkgs = config.pkgs,
shim = config.shim,
var shim = config.shim,
objs = {
paths: true,
bundles: true,
config: true,
map: true
};
eachProp(cfg, function (value, prop) {
if (objs[prop]) {
if (prop === 'map') {
if (!config.map) {
config.map = {};
if (!config[prop]) {
config[prop] = {};
}
mixin(config[prop], value, true, true);
} else {
mixin(config[prop], value, true);
}
} else {
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
if (cfg.shim) {
eachProp(cfg.shim, function (value, id) {
......@@ -1295,29 +1318,25 @@ var requirejs, require, define;
//Adjust packages if necessary.
if (cfg.packages) {
each(cfg.packages, function (pkgObj) {
var location;
var location, name;
pkgObj = typeof pkgObj === 'string' ? { name: pkgObj } : pkgObj;
name = pkgObj.name;
location = pkgObj.location;
if (location) {
config.paths[name] = pkgObj.location;
}
//Create a brand new object on pkgs, since currentPackages can
//be passed in again, and config.pkgs is the internal transformed
//state for all package configs.
pkgs[pkgObj.name] = {
name: pkgObj.name,
location: location || pkgObj.name,
//Save pointer to main module ID for pkg name.
//Remove leading dot in main, so main paths are normalized,
//and remove any trailing .js, since different package
//envs have different conventions: some use a module name,
//some use a file name.
main: (pkgObj.main || 'main')
config.pkgs[name] = pkgObj.name + '/' + (pkgObj.main || 'main')
.replace(currDirRegExp, '')
.replace(jsSuffixRegExp, '')
};
.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,
......@@ -1464,10 +1483,21 @@ var requirejs, require, define;
var map = makeModuleMap(id, relMap, true),
mod = getOwn(registry, id);
removeScript(id);
delete defined[id];
delete urlFetched[map.url];
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) {
//Hold on to listeners in case the
//module will be attempted to be reloaded
......@@ -1487,7 +1517,7 @@ var requirejs, require, define;
/**
* Called to enable a module if it is still in the registry
* 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.
*/
enable: function (depMap) {
......@@ -1561,8 +1591,19 @@ var requirejs, require, define;
* internal API, not a public one. Use toUrl for the public API.
*/
nameToUrl: function (moduleName, ext, skipExt) {
var paths, pkgs, pkg, pkgPath, syms, i, parentModule, url,
parentPath;
var paths, syms, i, parentModule, url,
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
//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;
} else {
//A module that needs to be converted to a path.
paths = config.paths;
pkgs = config.pkgs;
syms = moduleName.split('/');
//For each module name segment, see if there is a path
......@@ -1584,7 +1624,7 @@ var requirejs, require, define;
//and work up from it.
for (i = syms.length; i > 0; i -= 1) {
parentModule = syms.slice(0, i).join('/');
pkg = getOwn(pkgs, parentModule);
parentPath = getOwn(paths, parentModule);
if (parentPath) {
//If an array, it means there are a few choices,
......@@ -1594,22 +1634,12 @@ var requirejs, require, define;
}
syms.splice(0, i, parentPath);
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.
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;
}
......@@ -1918,7 +1948,7 @@ var requirejs, require, define;
}
//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.
eachReverse(scripts(), function (script) {
//Set the 'head' where we can append children by
......
......@@ -12,25 +12,27 @@ button {
font-size: 100%;
vertical-align: baseline;
font-family: inherit;
font-weight: inherit;
color: inherit;
-webkit-appearance: none;
-ms-appearance: none;
-o-appearance: none;
appearance: none;
-webkit-font-smoothing: antialiased;
-moz-font-smoothing: antialiased;
font-smoothing: antialiased;
}
body {
font: 14px 'Helvetica Neue', Helvetica, Arial, sans-serif;
line-height: 1.4em;
background: #eaeaea url('bg.png');
background: #f5f5f5;
color: #4d4d4d;
width: 550px;
min-width: 230px;
max-width: 550px;
margin: 0 auto;
-webkit-font-smoothing: antialiased;
-moz-font-smoothing: antialiased;
-ms-font-smoothing: antialiased;
-o-font-smoothing: antialiased;
font-smoothing: antialiased;
font-weight: 300;
}
button,
......@@ -38,78 +40,49 @@ input[type="checkbox"] {
outline: none;
}
.hidden {
display: none;
}
#todoapp {
background: #fff;
background: rgba(255, 255, 255, 0.9);
margin: 130px 0 40px 0;
border: 1px solid #ccc;
position: relative;
border-top-left-radius: 2px;
border-top-right-radius: 2px;
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%;
box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.2),
0 25px 50px 0 rgba(0, 0, 0, 0.1);
}
#todoapp input::-webkit-input-placeholder {
font-style: italic;
font-weight: 300;
color: #e6e6e6;
}
#todoapp input::-moz-placeholder {
font-style: italic;
color: #a9a9a9;
font-weight: 300;
color: #e6e6e6;
}
#todoapp input::input-placeholder {
font-style: italic;
font-weight: 300;
color: #e6e6e6;
}
#todoapp h1 {
position: absolute;
top: -120px;
top: -155px;
width: 100%;
font-size: 70px;
font-weight: bold;
font-size: 100px;
font-weight: 100;
text-align: center;
color: #b3b3b3;
color: rgba(255, 255, 255, 0.3);
text-shadow: -1px -1px rgba(0, 0, 0, 0.2);
color: rgba(175, 47, 47, 0.15);
-webkit-text-rendering: optimizeLegibility;
-moz-text-rendering: optimizeLegibility;
-ms-text-rendering: optimizeLegibility;
-o-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,
.edit {
position: relative;
......@@ -117,6 +90,7 @@ input[type="checkbox"] {
width: 100%;
font-size: 24px;
font-family: inherit;
font-weight: inherit;
line-height: 1.4em;
border: 0;
outline: none;
......@@ -124,29 +98,23 @@ input[type="checkbox"] {
padding: 6px;
border: 1px solid #999;
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;
-webkit-font-smoothing: antialiased;
-moz-font-smoothing: antialiased;
-ms-font-smoothing: antialiased;
-o-font-smoothing: antialiased;
font-smoothing: antialiased;
}
#new-todo {
padding: 16px 16px 16px 60px;
border: none;
background: rgba(0, 0, 0, 0.02);
z-index: 2;
box-shadow: none;
background: rgba(0, 0, 0, 0.003);
box-shadow: inset 0 -2px 1px rgba(0,0,0,0.03);
}
#main {
position: relative;
z-index: 2;
border-top: 1px dotted #adadad;
border-top: 1px solid #e6e6e6;
}
label[for='toggle-all'] {
......@@ -155,19 +123,19 @@ label[for='toggle-all'] {
#toggle-all {
position: absolute;
top: -42px;
left: -4px;
width: 40px;
top: -55px;
left: -12px;
width: 60px;
height: 34px;
text-align: center;
/* Mobile Safari */
border: none;
border: none; /* Mobile Safari */
}
#toggle-all:before {
content: '»';
font-size: 28px;
color: #d9d9d9;
padding: 0 25px 7px;
content: '';
font-size: 22px;
color: #e6e6e6;
padding: 10px 27px 10px 27px;
}
#toggle-all:checked:before {
......@@ -183,7 +151,7 @@ label[for='toggle-all'] {
#todo-list li {
position: relative;
font-size: 24px;
border-bottom: 1px dotted #ccc;
border-bottom: 1px solid #ededed;
}
#todo-list li:last-child {
......@@ -215,28 +183,17 @@ label[for='toggle-all'] {
top: 0;
bottom: 0;
margin: auto 0;
/* Mobile Safari */
border: none;
border: none; /* Mobile Safari */
-webkit-appearance: none;
-ms-appearance: none;
-o-appearance: none;
appearance: none;
}
#todo-list li .toggle:after {
content: '✔';
/* 40 + a couple of pixels visual adjustment */
line-height: 43px;
font-size: 20px;
color: #d9d9d9;
text-shadow: 0 -1px 0 #bfbfbf;
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>');
}
#todo-list li .toggle:checked:after {
color: #85ada7;
text-shadow: 0 1px 0 #669991;
bottom: 1px;
position: relative;
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>');
}
#todo-list li label {
......@@ -246,12 +203,11 @@ label[for='toggle-all'] {
margin-left: 45px;
display: block;
line-height: 1.2;
-webkit-transition: color 0.4s;
transition: color 0.4s;
}
#todo-list li.completed label {
color: #a9a9a9;
color: #d9d9d9;
text-decoration: line-through;
}
......@@ -264,21 +220,18 @@ label[for='toggle-all'] {
width: 40px;
height: 40px;
margin: auto 0;
font-size: 22px;
color: #a88a8a;
-webkit-transition: all 0.2s;
transition: all 0.2s;
font-size: 30px;
color: #cc9a9a;
margin-bottom: 11px;
transition: color 0.2s ease-out;
}
#todo-list li .destroy:hover {
text-shadow: 0 0 1px #000,
0 0 10px rgba(199, 107, 107, 0.8);
-webkit-transform: scale(1.3);
transform: scale(1.3);
color: #af5b5e;
}
#todo-list li .destroy:after {
content: '';
content: '×';
}
#todo-list li:hover .destroy {
......@@ -295,29 +248,25 @@ label[for='toggle-all'] {
#footer {
color: #777;
padding: 0 15px;
position: absolute;
right: 0;
bottom: -31px;
left: 0;
padding: 10px 15px;
height: 20px;
z-index: 1;
text-align: center;
border-top: 1px solid #e6e6e6;
}
#footer:before {
content: '';
position: absolute;
right: 0;
bottom: 31px;
bottom: 0;
left: 0;
height: 50px;
z-index: -1;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.3),
0 6px 0 -3px rgba(255, 255, 255, 0.8),
0 7px 1px -3px rgba(0, 0, 0, 0.3),
0 43px 0 -6px rgba(255, 255, 255, 0.8),
0 44px 2px -6px rgba(0, 0, 0, 0.2);
overflow: hidden;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2),
0 8px 0 -3px #f6f6f6,
0 9px 1px -3px rgba(0, 0, 0, 0.2),
0 16px 0 -6px #f6f6f6,
0 17px 2px -6px rgba(0, 0, 0, 0.2);
}
#todo-count {
......@@ -325,6 +274,10 @@ label[for='toggle-all'] {
text-align: left;
}
#todo-count strong {
font-weight: 300;
}
#filters {
margin: 0;
padding: 0;
......@@ -339,49 +292,73 @@ label[for='toggle-all'] {
}
#filters li a {
color: #83756f;
margin: 2px;
color: inherit;
margin: 3px;
padding: 3px 7px;
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 {
font-weight: bold;
border-color: rgba(175, 47, 47, 0.2);
}
#clear-completed {
#clear-completed,
html #clear-completed:active {
float: right;
position: relative;
line-height: 20px;
text-decoration: none;
background: rgba(0, 0, 0, 0.1);
font-size: 11px;
padding: 0 10px;
border-radius: 3px;
box-shadow: 0 -1px 0 0 rgba(0, 0, 0, 0.2);
cursor: pointer;
visibility: hidden;
position: relative;
}
#clear-completed::after {
visibility: visible;
content: 'Clear completed';
position: absolute;
top: 0;
right: 0;
white-space: nowrap;
}
#clear-completed:hover {
background: rgba(0, 0, 0, 0.15);
box-shadow: 0 -1px 0 0 rgba(0, 0, 0, 0.3);
#clear-completed:hover::after {
text-decoration: underline;
}
#info {
margin: 65px auto 0;
color: #a6a6a6;
font-size: 12px;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
color: #bfbfbf;
font-size: 10px;
text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
text-align: center;
}
#info p {
line-height: 1;
}
#info a {
color: inherit;
text-decoration: none;
font-weight: 400;
}
#info a:hover {
text-decoration: underline;
}
/*
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) {
#toggle-all,
#todo-list li .toggle {
......@@ -393,10 +370,6 @@ label[for='toggle-all'] {
}
#toggle-all {
top: -56px;
left: -15px;
width: 65px;
height: 41px;
-webkit-transform: rotate(90deg);
transform: rotate(90deg);
-webkit-appearance: none;
......@@ -404,151 +377,12 @@ label[for='toggle-all'] {
}
}
.hidden {
display: none;
}
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;
@media (max-width: 430px) {
#footer {
height: 50px;
}
.learn-bar #todoapp {
width: 550px;
margin: 130px auto 40px auto;
#filters {
bottom: 10px;
}
}
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 () {
'use strict';
/* jshint ignore:start */
// Underscore's Template Module
// Courtesy of underscorejs.org
var _ = (function (_) {
......@@ -114,6 +116,7 @@
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'));
}
/* jshint ignore:end */
function redirect() {
if (location.hostname === 'tastejs.github.io') {
......@@ -175,13 +178,17 @@
if (learnJSON.backend) {
this.frameworkJSON = learnJSON.backend;
this.frameworkJSON.issueLabel = framework;
this.append({
backend: true
});
} else if (learnJSON[framework]) {
this.frameworkJSON = learnJSON[framework];
this.frameworkJSON.issueLabel = framework;
this.append();
}
this.fetchIssueCount();
}
Learn.prototype.append = function (opts) {
......@@ -212,6 +219,26 @@
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();
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