Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

updating to latest underscore version 1.3.0

  • Loading branch information...
commit 75bac19f78f8b62af58745e44289350e84d0dc1b 1 parent 3d3d0e5
@ryanfitz ryanfitz authored
View
6 Rakefile
@@ -28,11 +28,11 @@ end
task :default => :test
namespace :backbone do
- desc "Download the latest versions of underscore and backbone.js from git"
+ desc "Download the latest released versions of underscore and backbone.js"
task :download_latest do
files = {
- 'underscore.js'=>'https://github.com/documentcloud/underscore/raw/master/underscore.js',
- 'backbone.js' => 'https://github.com/documentcloud/backbone/raw/master/backbone.js'
+ 'underscore.js'=>'http://underscorejs.org/underscore.js',
+ 'backbone.js' => 'http://backbonejs.org/backbone.js'
}
vendor_dir = "vendor/assets/javascripts"
View
6 vendor/assets/javascripts/backbone.js
@@ -31,8 +31,8 @@
var _ = root._;
if (!_ && (typeof require !== 'undefined')) _ = require('underscore')._;
- // For Backbone's purposes, jQuery, Zepto, or Ender owns the `$` variable.
- var $ = root.jQuery || root.Zepto || root.ender;
+ // For Backbone's purposes, jQuery or Zepto owns the `$` variable.
+ var $ = root.jQuery || root.Zepto;
// Runs Backbone.js in *noConflict* mode, returning the `Backbone` variable
// to its previous owner. Returns a reference to this Backbone object.
@@ -984,7 +984,7 @@
// Ensure that the View has a DOM element to render into.
// If `this.el` is a string, pass it through `$()`, take the first
// matching element, and re-assign it to `el`. Otherwise, create
- // an element from the `id`, `className` and `tagName` properties.
+ // an element from the `id`, `className` and `tagName` proeprties.
_ensureElement : function() {
if (!this.el) {
var attrs = this.attributes || {};
View
51 vendor/assets/javascripts/underscore.js
@@ -1,5 +1,5 @@
-// Underscore.js 1.2.3
-// (c) 2009-2011 Jeremy Ashkenas, DocumentCloud Inc.
+// Underscore.js 1.3.0
+// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
// Underscore is freely distributable under the MIT license.
// Portions of Underscore are inspired or borrowed from Prototype,
// Oliver Steele's Functional, and John Resig's Micro-Templating.
@@ -25,7 +25,6 @@
// Create quick reference variables for speed access to core prototypes.
var slice = ArrayProto.slice,
- concat = ArrayProto.concat,
unshift = ArrayProto.unshift,
toString = ObjProto.toString,
hasOwnProperty = ObjProto.hasOwnProperty;
@@ -49,26 +48,21 @@
// Create a safe reference to the Underscore object for use below.
var _ = function(obj) { return new wrapper(obj); };
- // Export the Underscore object for **Node.js** and **"CommonJS"**, with
- // backwards-compatibility for the old `require()` API. If we're not in
- // CommonJS, add `_` to the global object.
+ // Export the Underscore object for **Node.js**, with
+ // backwards-compatibility for the old `require()` API. If we're in
+ // the browser, add `_` as a global object via a string identifier,
+ // for Closure Compiler "advanced" mode.
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = _;
}
exports._ = _;
- } else if (typeof define === 'function' && define.amd) {
- // Register as a named module with AMD.
- define('underscore', function() {
- return _;
- });
} else {
- // Exported as a string, for Closure Compiler "advanced" mode.
root['_'] = _;
}
// Current version.
- _.VERSION = '1.2.3';
+ _.VERSION = '1.3.0';
// Collection Functions
// --------------------
@@ -102,6 +96,7 @@
each(obj, function(value, index, list) {
results[results.length] = iterator.call(context, value, index, list);
});
+ if (obj.length === +obj.length) results.length = obj.length;
return results;
};
@@ -218,7 +213,7 @@
_.invoke = function(obj, method) {
var args = slice.call(arguments, 2);
return _.map(obj, function(value) {
- return (method.call ? method || value : value[method]).apply(value, args);
+ return (_.isFunction(method) ? method || value : value[method]).apply(value, args);
});
};
@@ -583,7 +578,7 @@
// conditionally execute the original function.
_.wrap = function(func, wrapper) {
return function() {
- var args = concat.apply([func], arguments);
+ var args = [func].concat(slice.call(arguments, 0));
return wrapper.apply(this, args);
};
};
@@ -892,6 +887,11 @@
escape : /<%-([\s\S]+?)%>/g
};
+ // When customizing `templateSettings`, if you don't want to define an
+ // interpolation, evaluation or escaping regex, we need one that is
+ // guaranteed not to match.
+ var noMatch = /.^/;
+
// JavaScript micro-templating, similar to John Resig's implementation.
// Underscore templating handles arbitrary delimiters, preserves whitespace,
// and correctly escapes quotes within interpolated code.
@@ -901,15 +901,16 @@
'with(obj||{}){__p.push(\'' +
str.replace(/\\/g, '\\\\')
.replace(/'/g, "\\'")
- .replace(c.escape, function(match, code) {
+ .replace(c.escape || noMatch, function(match, code) {
return "',_.escape(" + code.replace(/\\'/g, "'") + "),'";
})
- .replace(c.interpolate, function(match, code) {
+ .replace(c.interpolate || noMatch, function(match, code) {
return "'," + code.replace(/\\'/g, "'") + ",'";
})
- .replace(c.evaluate || null, function(match, code) {
+ .replace(c.evaluate || noMatch, function(match, code) {
return "');" + code.replace(/\\'/g, "'")
- .replace(/[\r\n\t]/g, ' ') + ";__p.push('";
+ .replace(/[\r\n\t]/g, ' ')
+ .replace(/\\\\/g, '\\') + ";__p.push('";
})
.replace(/\r/g, '\\r')
.replace(/\n/g, '\\n')
@@ -922,6 +923,11 @@
};
};
+ // Add a "chain" function, which will delegate to the wrapper.
+ _.chain = function(obj) {
+ return _(obj).chain();
+ };
+
// The OOP Wrapper
// ---------------
@@ -954,8 +960,11 @@
each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
var method = ArrayProto[name];
wrapper.prototype[name] = function() {
- method.apply(this._wrapped, arguments);
- return result(this._wrapped, this._chain);
+ var wrapped = this._wrapped;
+ method.apply(wrapped, arguments);
+ var length = wrapped.length;
+ if ((name == 'shift' || name == 'splice') && length === 0) delete wrapped[0];
+ return result(wrapped, this._chain);
};
});
Please sign in to comment.
Something went wrong with that request. Please try again.