upgrade backbone and underscore js

This commit is contained in:
danielgrippi 2012-02-03 11:38:05 -08:00
parent 6dbd644b01
commit 67a79d5937
2 changed files with 556 additions and 420 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
// Underscore.js 1.2.4 // Underscore.js 1.3.1
// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. // (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
// Underscore is freely distributable under the MIT license. // Underscore is freely distributable under the MIT license.
// Portions of Underscore are inspired or borrowed from Prototype, // Portions of Underscore are inspired or borrowed from Prototype,
@ -48,26 +48,21 @@
// Create a safe reference to the Underscore object for use below. // Create a safe reference to the Underscore object for use below.
var _ = function(obj) { return new wrapper(obj); }; var _ = function(obj) { return new wrapper(obj); };
// Export the Underscore object for **Node.js** and **"CommonJS"**, with // Export the Underscore object for **Node.js**, with
// backwards-compatibility for the old `require()` API. If we're not in // backwards-compatibility for the old `require()` API. If we're in
// CommonJS, add `_` to the global object. // the browser, add `_` as a global object via a string identifier,
// for Closure Compiler "advanced" mode.
if (typeof exports !== 'undefined') { if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) { if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = _; exports = module.exports = _;
} }
exports._ = _; exports._ = _;
} else if (typeof define === 'function' && define.amd) {
// Register as a named module with AMD.
define('underscore', function() {
return _;
});
} else { } else {
// Exported as a string, for Closure Compiler "advanced" mode.
root['_'] = _; root['_'] = _;
} }
// Current version. // Current version.
_.VERSION = '1.2.4'; _.VERSION = '1.3.1';
// Collection Functions // Collection Functions
// -------------------- // --------------------
@ -85,7 +80,7 @@
} }
} else { } else {
for (var key in obj) { for (var key in obj) {
if (hasOwnProperty.call(obj, key)) { if (_.has(obj, key)) {
if (iterator.call(context, obj[key], key, obj) === breaker) return; if (iterator.call(context, obj[key], key, obj) === breaker) return;
} }
} }
@ -94,7 +89,7 @@
// Return the results of applying the iterator to each element. // Return the results of applying the iterator to each element.
// Delegates to **ECMAScript 5**'s native `map` if available. // Delegates to **ECMAScript 5**'s native `map` if available.
_.map = function(obj, iterator, context) { _.map = _.collect = function(obj, iterator, context) {
var results = []; var results = [];
if (obj == null) return results; if (obj == null) return results;
if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context); if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
@ -511,7 +506,7 @@
hasher || (hasher = _.identity); hasher || (hasher = _.identity);
return function() { return function() {
var key = hasher.apply(this, arguments); var key = hasher.apply(this, arguments);
return hasOwnProperty.call(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments)); return _.has(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments));
}; };
}; };
@ -617,7 +612,7 @@
_.keys = nativeKeys || function(obj) { _.keys = nativeKeys || function(obj) {
if (obj !== Object(obj)) throw new TypeError('Invalid object'); if (obj !== Object(obj)) throw new TypeError('Invalid object');
var keys = []; var keys = [];
for (var key in obj) if (hasOwnProperty.call(obj, key)) keys[keys.length] = key; for (var key in obj) if (_.has(obj, key)) keys[keys.length] = key;
return keys; return keys;
}; };
@ -640,7 +635,7 @@
_.extend = function(obj) { _.extend = function(obj) {
each(slice.call(arguments, 1), function(source) { each(slice.call(arguments, 1), function(source) {
for (var prop in source) { for (var prop in source) {
if (source[prop] !== void 0) obj[prop] = source[prop]; obj[prop] = source[prop];
} }
}); });
return obj; return obj;
@ -738,17 +733,17 @@
if ('constructor' in a != 'constructor' in b || a.constructor != b.constructor) return false; if ('constructor' in a != 'constructor' in b || a.constructor != b.constructor) return false;
// Deep compare objects. // Deep compare objects.
for (var key in a) { for (var key in a) {
if (hasOwnProperty.call(a, key)) { if (_.has(a, key)) {
// Count the expected number of properties. // Count the expected number of properties.
size++; size++;
// Deep compare each member. // Deep compare each member.
if (!(result = hasOwnProperty.call(b, key) && eq(a[key], b[key], stack))) break; if (!(result = _.has(b, key) && eq(a[key], b[key], stack))) break;
} }
} }
// Ensure that both objects contain the same number of properties. // Ensure that both objects contain the same number of properties.
if (result) { if (result) {
for (key in b) { for (key in b) {
if (hasOwnProperty.call(b, key) && !(size--)) break; if (_.has(b, key) && !(size--)) break;
} }
result = !size; result = !size;
} }
@ -767,7 +762,7 @@
// An "empty" object has no enumerable own-properties. // An "empty" object has no enumerable own-properties.
_.isEmpty = function(obj) { _.isEmpty = function(obj) {
if (_.isArray(obj) || _.isString(obj)) return obj.length === 0; if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
for (var key in obj) if (hasOwnProperty.call(obj, key)) return false; for (var key in obj) if (_.has(obj, key)) return false;
return true; return true;
}; };
@ -793,7 +788,7 @@
}; };
if (!_.isArguments(arguments)) { if (!_.isArguments(arguments)) {
_.isArguments = function(obj) { _.isArguments = function(obj) {
return !!(obj && hasOwnProperty.call(obj, 'callee')); return !!(obj && _.has(obj, 'callee'));
}; };
} }
@ -843,6 +838,11 @@
return obj === void 0; return obj === void 0;
}; };
// Has own property?
_.has = function(obj, key) {
return hasOwnProperty.call(obj, key);
};
// Utility Functions // Utility Functions
// ----------------- // -----------------
@ -897,6 +897,12 @@
// guaranteed not to match. // guaranteed not to match.
var noMatch = /.^/; var noMatch = /.^/;
// Within an interpolation, evaluation, or escaping, remove HTML escaping
// that had been previously added.
var unescape = function(code) {
return code.replace(/\\\\/g, '\\').replace(/\\'/g, "'");
};
// JavaScript micro-templating, similar to John Resig's implementation. // JavaScript micro-templating, similar to John Resig's implementation.
// Underscore templating handles arbitrary delimiters, preserves whitespace, // Underscore templating handles arbitrary delimiters, preserves whitespace,
// and correctly escapes quotes within interpolated code. // and correctly escapes quotes within interpolated code.
@ -907,15 +913,13 @@
str.replace(/\\/g, '\\\\') str.replace(/\\/g, '\\\\')
.replace(/'/g, "\\'") .replace(/'/g, "\\'")
.replace(c.escape || noMatch, function(match, code) { .replace(c.escape || noMatch, function(match, code) {
return "',_.escape(" + code.replace(/\\'/g, "'") + "),'"; return "',_.escape(" + unescape(code) + "),'";
}) })
.replace(c.interpolate || noMatch, function(match, code) { .replace(c.interpolate || noMatch, function(match, code) {
return "'," + code.replace(/\\'/g, "'") + ",'"; return "'," + unescape(code) + ",'";
}) })
.replace(c.evaluate || noMatch, function(match, code) { .replace(c.evaluate || noMatch, function(match, code) {
return "');" + code.replace(/\\'/g, "'") return "');" + unescape(code).replace(/[\r\n\t]/g, ' ') + ";__p.push('";
.replace(/[\r\n\t]/g, ' ')
.replace(/\\\\/g, '\\') + ";__p.push('";
}) })
.replace(/\r/g, '\\r') .replace(/\r/g, '\\r')
.replace(/\n/g, '\\n') .replace(/\n/g, '\\n')