From 837c15e4f92b82aa02551f7cfce0caebb53cf13e Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 15 Sep 2012 08:21:44 -0700 Subject: [PATCH] Update vendors. Former-commit-id: 1e93a793891e5f4e2c0d3927f3f38b25bd182263 --- vendor/backbone/backbone.js | 33 ++++++++++++-------- vendor/backbone/test/collection.js | 18 +++++++++-- vendor/underscore/test/collections.js | 31 ++++++++++++++----- vendor/underscore/test/functions.js | 16 +++++++--- vendor/underscore/underscore-min.js | 44 +++++++++++++-------------- vendor/underscore/underscore.js | 28 +++++++++-------- 6 files changed, 108 insertions(+), 62 deletions(-) diff --git a/vendor/backbone/backbone.js b/vendor/backbone/backbone.js index d8564b397..75ab600b8 100644 --- a/vendor/backbone/backbone.js +++ b/vendor/backbone/backbone.js @@ -731,15 +731,23 @@ // normal circumstances, as the set will maintain sort order as each item // is added. sort: function(options) { - options || (options = {}); - if (!this.comparator) throw new Error('Cannot sort a set without a comparator'); - var boundComparator = _.bind(this.comparator, this); - if (this.comparator.length === 1) { - this.models = this.sortBy(boundComparator); - } else { - this.models.sort(boundComparator); + if (!this.comparator) { + throw new Error('Cannot sort a set without a comparator'); } - if (!options.silent) this.trigger('reset', this, options); + + // If provided an attribute name, use it to sort the collection. + if (_.isString(this.comparator)) { + var attr = this.comparator; + this.comparator = function(model){ return model.get(attr); }; + } + + if (this.comparator.length === 1) { + this.models = this.sortBy(this.comparator, this); + } else { + this.models.sort(_.bind(this.comparator, this)); + } + + if (!options || !options.silent) this.trigger('reset', this, options); return this; }, @@ -752,14 +760,12 @@ // you can reset the entire set with a new list of models, without firing // any `add` or `remove` events. Fires `reset` when finished. reset: function(models, options) { - models || (models = []); - options || (options = {}); for (var i = 0, l = this.models.length; i < l; i++) { this._removeReference(this.models[i]); } this._reset(); - this.add(models, _.extend({silent: true}, options)); - if (!options.silent) this.trigger('reset', this, options); + if (models) this.add(models, _.extend({silent: true}, options)); + if (!options || !options.silent) this.trigger('reset', this, options); return this; }, @@ -1151,7 +1157,8 @@ // a new one to the browser history. _updateHash: function(location, fragment, replace) { if (replace) { - location.replace(location.href.replace(/(javascript:|#).*$/, '') + '#' + fragment); + var href = location.href.replace(/(javascript:|#).*$/, ''); + location.replace(href + '#' + fragment); } else { location.hash = fragment; } diff --git a/vendor/backbone/test/collection.js b/vendor/backbone/test/collection.js index f2ec126ce..98fd53e5e 100644 --- a/vendor/backbone/test/collection.js +++ b/vendor/backbone/test/collection.js @@ -34,6 +34,15 @@ $(document).ready(function() { equal(col.length, 4); }); + test("String comparator.", 1, function() { + var collection = new Backbone.Collection([ + {id: 3}, + {id: 1}, + {id: 2} + ], {comparator: 'id'}); + deepEqual(collection.pluck('id'), [1, 2, 3]); + }); + test("new and parse", 3, function() { var Collection = Backbone.Collection.extend({ parse : function(data) { @@ -222,7 +231,7 @@ $(document).ready(function() { equal(col.indexOf(tom), 2); }); - test("comparator that depends on `this`", 1, function() { + test("comparator that depends on `this`", 2, function() { var col = new Backbone.Collection; col.negative = function(num) { return -num; @@ -231,7 +240,12 @@ $(document).ready(function() { return this.negative(a.id); }; col.add([{id: 1}, {id: 2}, {id: 3}]); - equal(col.pluck('id').join(' '), '3 2 1'); + deepEqual(col.pluck('id'), [3, 2, 1]); + col.comparator = function(a, b) { + return this.negative(b.id) - this.negative(a.id); + }; + col.sort(); + deepEqual(col.pluck('id'), [1, 2, 3]); }); test("remove", 5, function() { diff --git a/vendor/underscore/test/collections.js b/vendor/underscore/test/collections.js index c31f8e5c5..64047d989 100644 --- a/vendor/underscore/test/collections.js +++ b/vendor/underscore/test/collections.js @@ -245,6 +245,29 @@ $(document).ready(function() { var list = ["one", "two", "three", "four", "five"]; var sorted = _.sortBy(list, 'length'); equal(sorted.join(' '), 'one two four five three', 'sorted by length'); + + function Pair(x, y) { + this.x = x; + this.y = y; + } + + var collection = [ + new Pair(1, 1), new Pair(1, 2), + new Pair(1, 3), new Pair(1, 4), + new Pair(1, 5), new Pair(1, 6), + new Pair(2, 1), new Pair(2, 2), + new Pair(2, 3), new Pair(2, 4), + new Pair(2, 5), new Pair(2, 6), + new Pair(undefined, 1), new Pair(undefined, 2), + new Pair(undefined, 3), new Pair(undefined, 4), + new Pair(undefined, 5), new Pair(undefined, 6) + ]; + + var actual = _.sortBy(collection, function(pair) { + return pair.x; + }); + + deepEqual(actual, collection, 'sortBy should be stable'); }); test('groupBy', function() { @@ -296,14 +319,6 @@ $(document).ready(function() { var numbers = _.toArray({one : 1, two : 2, three : 3}); equal(numbers.join(', '), '1, 2, 3', 'object flattened into array'); - - var objectWithToArrayFunction = {toArray: function() { - return [1, 2, 3]; - }}; - equal(_.toArray(objectWithToArrayFunction).join(', '), '1, 2, 3', 'toArray method used if present'); - - var objectWithToArrayValue = {toArray: 1}; - equal(_.toArray(objectWithToArrayValue).join(', '), '1', 'toArray property ignored if not a function'); }); test('size', function() { diff --git a/vendor/underscore/test/functions.js b/vendor/underscore/test/functions.js index 43aab1073..a52965877 100644 --- a/vendor/underscore/test/functions.js +++ b/vendor/underscore/test/functions.js @@ -141,7 +141,7 @@ $(document).ready(function() { var incr = function(){ return ++counter; }; var throttledIncr = _.throttle(incr, 100); var results = []; - var saveResult = function() { results.push(throttledIncr()); } + var saveResult = function() { results.push(throttledIncr()); }; saveResult(); saveResult(); saveResult(); setTimeout(saveResult, 70); setTimeout(saveResult, 120); @@ -159,7 +159,7 @@ $(document).ready(function() { equal(results[6], 2, "incr was throttled"); equal(results[7], 3, "incr was called thrice"); equal(results[8], 3, "incr was throttled"); - start(); + start(); }, 400); }); @@ -176,11 +176,17 @@ $(document).ready(function() { _.delay(function(){ equal(counter, 1, "incr was debounced"); start(); }, 220); }); - asyncTest("debounce asap", 2, function() { + asyncTest("debounce asap", 5, function() { + var a, b, c; var counter = 0; - var incr = function(){ counter++; }; + var incr = function(){ return ++counter; }; var debouncedIncr = _.debounce(incr, 50, true); - debouncedIncr(); debouncedIncr(); debouncedIncr(); + a = debouncedIncr(); + b = debouncedIncr(); + c = debouncedIncr(); + equal(a, 1); + equal(b, 1); + equal(c, 1); equal(counter, 1, 'incr was called immediately'); setTimeout(debouncedIncr, 30); setTimeout(debouncedIncr, 60); diff --git a/vendor/underscore/underscore-min.js b/vendor/underscore/underscore-min.js index 811dfbfc7..ed8e59ba1 100644 --- a/vendor/underscore/underscore-min.js +++ b/vendor/underscore/underscore-min.js @@ -5,29 +5,29 @@ // Oliver Steele's Functional, and John Resig's Micro-Templating. // For all details and documentation: // http://documentcloud.github.com/underscore -(function(){var s=this,L=s._,o={},k=Array.prototype,p=Object.prototype,M=k.push,h=k.slice,q=k.concat,l=p.toString,N=p.hasOwnProperty,y=k.forEach,z=k.map,A=k.reduce,B=k.reduceRight,C=k.filter,D=k.every,E=k.some,r=k.indexOf,F=k.lastIndexOf,p=Array.isArray,O=Object.keys,t=Function.prototype.bind,b=function(a){if(a instanceof b)return a;if(!(this instanceof b))return new b(a);this._wrapped=a};"undefined"!==typeof exports?("undefined"!==typeof module&&module.exports&&(exports=module.exports=b),exports._= -b):s._=b;b.VERSION="1.3.3";var j=b.each=b.forEach=function(a,c,d){if(a!=null)if(y&&a.forEach===y)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,g=a.length;e2;a==null&&(a= -[]);if(A&&a.reduce===A){e&&(c=b.bind(c,e));return g?a.reduce(c,d):a.reduce(c)}j(a,function(a,b,h){if(g)d=c.call(e,d,a,b,h);else{d=a;g=true}});if(!g)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var g=arguments.length>2;a==null&&(a=[]);if(B&&a.reduceRight===B){e&&(c=b.bind(c,e));return g?a.reduceRight(c,d):a.reduceRight(c)}var f=b.toArray(a).reverse();e&&!g&&(c=b.bind(c,e));return g?b.reduce(f,c,d,e):b.reduce(f,c)};b.find=b.detect= -function(a,c,b){var e;G(a,function(a,f,i){if(c.call(b,a,f,i)){e=a;return true}});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(C&&a.filter===C)return a.filter(c,b);j(a,function(a,f,i){c.call(b,a,f,i)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,f,i){c.call(b,a,f,i)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,d){c||(c=b.identity);var e=true;if(a==null)return e;if(D&&a.every===D)return a.every(c,d);j(a,function(a, -b,i){if(!(e=e&&c.call(d,a,b,i)))return o});return!!e};var G=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(E&&a.some===E)return a.some(c,d);j(a,function(a,b,i){if(e||(e=c.call(d,a,b,i)))return o});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;if(r&&a.indexOf===r)return a.indexOf(c)!=-1;return b=G(a,function(a){return a===c})};b.invoke=function(a,c){var d=h.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c:a[c]).apply(a, +(function(){var s=this,M=s._,o={},k=Array.prototype,p=Object.prototype,t=k.push,f=k.slice,q=k.concat,l=p.toString,N=p.hasOwnProperty,z=k.forEach,A=k.map,B=k.reduce,C=k.reduceRight,D=k.filter,E=k.every,F=k.some,r=k.indexOf,G=k.lastIndexOf,p=Array.isArray,O=Object.keys,u=Function.prototype.bind,b=function(a){if(a instanceof b)return a;if(!(this instanceof b))return new b(a);this._wrapped=a};"undefined"!==typeof exports?("undefined"!==typeof module&&module.exports&&(exports=module.exports=b),exports._= +b):s._=b;b.VERSION="1.3.3";var j=b.each=b.forEach=function(a,c,d){if(a!=null)if(z&&a.forEach===z)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,h=a.length;e2;a==null&&(a= +[]);if(B&&a.reduce===B){e&&(c=b.bind(c,e));return h?a.reduce(c,d):a.reduce(c)}j(a,function(a,b,f){if(h)d=c.call(e,d,a,b,f);else{d=a;h=true}});if(!h)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var h=arguments.length>2;a==null&&(a=[]);if(C&&a.reduceRight===C){e&&(c=b.bind(c,e));return h?a.reduceRight(c,d):a.reduceRight(c)}var g=b.toArray(a).reverse();e&&!h&&(c=b.bind(c,e));return h?b.reduce(g,c,d,e):b.reduce(g,c)};b.find=b.detect= +function(a,c,b){var e;H(a,function(a,g,i){if(c.call(b,a,g,i)){e=a;return true}});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(D&&a.filter===D)return a.filter(c,b);j(a,function(a,g,i){c.call(b,a,g,i)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,g,i){c.call(b,a,g,i)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,d){c||(c=b.identity);var e=true;if(a==null)return e;if(E&&a.every===E)return a.every(c,d);j(a,function(a, +b,i){if(!(e=e&&c.call(d,a,b,i)))return o});return!!e};var H=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(F&&a.some===F)return a.some(c,d);j(a,function(a,b,i){if(e||(e=c.call(d,a,b,i)))return o});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;if(r&&a.indexOf===r)return a.indexOf(c)!=-1;return b=H(a,function(a){return a===c})};b.invoke=function(a,c){var d=f.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c:a[c]).apply(a, d)})};b.pluck=function(a,c){return b.map(a,function(a){return a[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,i){b=c?c.call(d,a,b,i):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a)&&a[0]===+a[0]&&a.length<65535)return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a, -function(a,b,i){b=c?c.call(d,a,b,i):a;bd?1:0}),"value")};var H=function(a,c){return b.isFunction(c)?c:function(a){return a[c]}}, -I=function(a,c,b){var e={},g=H(a,c);j(a,function(a,c){var h=g(a,c);b(e,h,a)});return e};b.groupBy=function(a,c){return I(a,c,function(a,c,b){(a[c]||(a[c]=[])).push(b)})};b.countBy=function(a,c){return I(a,c,function(a,c){a[c]||(a[c]=0);a[c]++})};b.sortedIndex=function(a,c,d){d||(d=b.identity);for(var c=d(c),e=0,g=a.length;e>1;d(a[f])= -0})})};b.difference=function(a){var c=q.apply(k,h.call(arguments,1));return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=h.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}}; -b.keys=O||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.pairs=function(a){return b.map(a,function(a,b){return[b,a]})};b.invert=function(a){return b.reduce(a,function(a,b,e){a[b]=e;return a},{})};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(h.call(arguments,1),function(b){for(var d in b)a[d]= -b[d]});return a};b.pick=function(a){var b={},d=q.apply(k,h.call(arguments,1));j(d,function(d){d in a&&(b[d]=a[d])});return b};b.omit=function(a){var c={},d=q.apply(k,h.call(arguments,1)),e;for(e in a)b.include(d,e)||(c[e]=a[e]);return c};b.defaults=function(a){j(h.call(arguments,1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};var u=function(a,c,d,e){if(a===c)return a!== -0||1/a==1/c;if(a==null||c==null)return a===c;if(a instanceof b)a=a._wrapped;if(c instanceof b)c=c._wrapped;var g=l.call(a);if(g!=l.call(c))return false;switch(g){case "[object String]":return a==""+c;case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source==c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f= -d.length;f--;)if(d[f]==a)return e[f]==c;d.push(a);e.push(c);var f=0,i=true;if(g=="[object Array]"){f=a.length;if(i=f==c.length)for(;f--;)if(!(i=u(a[f],c[f],d,e)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var h in a)if(b.has(a,h)){f++;if(!(i=b.has(c,h)&&u(a[h],c[h],d,e)))break}if(i){for(h in c)if(b.has(c,h)&&!f--)break;i=!f}}d.pop();e.pop();return i};b.isEqual=function(a,b){return u(a,b,[],[])};b.isEmpty=function(a){if(a==null)return true;if(b.isArray(a)|| +function(a,b,i){b=c?c.call(d,a,b,i):a;bd?1:e>1;d(a[g])=0})})};b.difference=function(a){var c=q.apply(k,f.call(arguments,1));return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=f.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}};b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this, +arguments)}};b.keys=O||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.pairs=function(a){return b.map(a,function(a,b){return[b,a]})};b.invert=function(a){return b.reduce(a,function(a,b,e){a[b]=e;return a},{})};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(f.call(arguments,1),function(b){for(var d in b)a[d]= +b[d]});return a};b.pick=function(a){var b={},d=q.apply(k,f.call(arguments,1));j(d,function(d){d in a&&(b[d]=a[d])});return b};b.omit=function(a){var c={},d=q.apply(k,f.call(arguments,1)),e;for(e in a)b.include(d,e)||(c[e]=a[e]);return c};b.defaults=function(a){j(f.call(arguments,1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};var v=function(a,c,d,e){if(a===c)return a!== +0||1/a==1/c;if(a==null||c==null)return a===c;if(a instanceof b)a=a._wrapped;if(c instanceof b)c=c._wrapped;var h=l.call(a);if(h!=l.call(c))return false;switch(h){case "[object String]":return a==""+c;case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source==c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var g= +d.length;g--;)if(d[g]==a)return e[g]==c;d.push(a);e.push(c);var g=0,i=true;if(h=="[object Array]"){g=a.length;if(i=g==c.length)for(;g--;)if(!(i=v(a[g],c[g],d,e)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var f in a)if(b.has(a,f)){g++;if(!(i=b.has(c,f)&&v(a[f],c[f],d,e)))break}if(i){for(f in c)if(b.has(c,f)&&!g--)break;i=!g}}d.pop();e.pop();return i};b.isEqual=function(a,b){return v(a,b,[],[])};b.isEmpty=function(a){if(a==null)return true;if(b.isArray(a)|| b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=p||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)};j("Arguments,Function,String,Number,Date,RegExp".split(","),function(a){b["is"+a]=function(b){return l.call(b)=="[object "+a+"]"}});b.isArguments(arguments)||(b.isArguments=function(a){return!(!a||!b.has(a,"callee"))});b.isFinite=function(a){return b.isNumber(a)&& -isFinite(a)};b.isNaN=function(a){return b.isNumber(a)&&a!=+a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return N.call(a,b)};b.noConflict=function(){s._=L;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e":">", +isFinite(a)};b.isNaN=function(a){return b.isNumber(a)&&a!=+a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return N.call(a,b)};b.noConflict=function(){s._=M;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e":">", '"':""","'":"'","/":"/"}};m.unescape=b.invert(m.escape);var P={escape:RegExp("["+b.keys(m.escape).join("")+"]","g"),unescape:RegExp("("+b.keys(m.unescape).join("|")+")","g")};b.each(["escape","unescape"],function(a){b[a]=function(b){return b==null?"":(""+b).replace(P[a],function(b){return m[a][b]})}});b.result=function(a,c){if(a==null)return null;var d=a[c];return b.isFunction(d)?d.call(a):d};b.mixin=function(a){j(b.functions(a),function(c){var d=b[c]=a[c];b.prototype[c]=function(){var a= -h.call(arguments);a.unshift(this._wrapped);a=d.apply(b,a);return this._chain?b(a).chain():a}})};var Q=0;b.uniqueId=function(a){var b=Q++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var v=/.^/,n={"\\":"\\","'":"'",r:"\r",n:"\n",t:"\t",u2028:"\u2028",u2029:"\u2029"},w;for(w in n)n[n[w]]=w;var R=/\\|'|\r|\n|\t|\u2028|\u2029/g,S=/\\(\\|'|r|n|t|u2028|u2029)/g,x=function(a){return a.replace(S,function(a,b){return n[b]})};b.template= -function(a,c,d){d=b.defaults({},d,b.templateSettings);a="__p+='"+a.replace(R,function(a){return"\\"+n[a]}).replace(d.escape||v,function(a,b){return"'+\n((__t=("+x(b)+"))==null?'':_.escape(__t))+\n'"}).replace(d.interpolate||v,function(a,b){return"'+\n((__t=("+x(b)+"))==null?'':__t)+\n'"}).replace(d.evaluate||v,function(a,b){return"';\n"+x(b)+"\n__p+='"})+"';\n";d.variable||(a="with(obj||{}){\n"+a+"}\n");a="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+ -a+"return __p;\n";try{var e=new Function(d.variable||"obj","_",a)}catch(g){g.source=a;throw g;}if(c)return e(c,b);c=function(a){return e.call(this,a,b)};c.source="function("+(d.variable||"obj")+"){\n"+a+"}";return c};b.chain=function(a){return b(a).chain()};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var c=k[a];b.prototype[a]=function(){var d=this._wrapped;c.apply(d,arguments);(a=="shift"||a=="splice")&&d.length===0&&delete d[0];return this._chain?b(d).chain(): +[this._wrapped];t.apply(a,arguments);a=d.apply(b,a);return this._chain?b(a).chain():a}})};var Q=0;b.uniqueId=function(a){var b=Q++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var w=/.^/,n={"\\":"\\","'":"'",r:"\r",n:"\n",t:"\t",u2028:"\u2028",u2029:"\u2029"},x;for(x in n)n[n[x]]=x;var R=/\\|'|\r|\n|\t|\u2028|\u2029/g,S=/\\(\\|'|r|n|t|u2028|u2029)/g,y=function(a){return a.replace(S,function(a,b){return n[b]})};b.template= +function(a,c,d){d=b.defaults({},d,b.templateSettings);a="__p+='"+a.replace(R,function(a){return"\\"+n[a]}).replace(d.escape||w,function(a,b){return"'+\n((__t=("+y(b)+"))==null?'':_.escape(__t))+\n'"}).replace(d.interpolate||w,function(a,b){return"'+\n((__t=("+y(b)+"))==null?'':__t)+\n'"}).replace(d.evaluate||w,function(a,b){return"';\n"+y(b)+"\n__p+='"})+"';\n";d.variable||(a="with(obj||{}){\n"+a+"}\n");a="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+ +a+"return __p;\n";try{var e=new Function(d.variable||"obj","_",a)}catch(f){f.source=a;throw f;}if(c)return e(c,b);c=function(a){return e.call(this,a,b)};c.source="function("+(d.variable||"obj")+"){\n"+a+"}";return c};b.chain=function(a){return b(a).chain()};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var c=k[a];b.prototype[a]=function(){var d=this._wrapped;c.apply(d,arguments);(a=="shift"||a=="splice")&&d.length===0&&delete d[0];return this._chain?b(d).chain(): d}});j(["concat","join","slice"],function(a){var c=k[a];b.prototype[a]=function(){var a=c.apply(this._wrapped,arguments);return this._chain?b(a).chain():a}});b.extend(b.prototype,{chain:function(){this._chain=true;return this},value:function(){return this._wrapped}})}).call(this); diff --git a/vendor/underscore/underscore.js b/vendor/underscore/underscore.js index d9dad9c4b..4889be4e0 100644 --- a/vendor/underscore/underscore.js +++ b/vendor/underscore/underscore.js @@ -277,13 +277,16 @@ return _.pluck(_.map(obj, function(value, index, list) { return { value : value, + index : index, criteria : iterator.call(context, value, index, list) }; }).sort(function(left, right) { - var a = left.criteria, b = right.criteria; + var a = left.criteria, b = right.criteria; + var ai = left.index, bi = right.index; + if (a === b) return ai < bi ? -1 : 1; if (a === void 0) return 1; if (b === void 0) return -1; - return a < b ? -1 : a > b ? 1 : 0; + return a < b ? -1 : a > b ? 1 : ai < bi ? -1 : 1; }), 'value'); }; @@ -336,9 +339,8 @@ // Safely convert anything iterable into a real, live array. _.toArray = function(obj) { - if (!obj) return []; - if (_.isArray(obj) || _.isArguments(obj)) return slice.call(obj); - if (_.isFunction(obj.toArray)) return obj.toArray(); + if (!obj) return []; + if (obj.length === +obj.length) return slice.call(obj); return _.values(obj); }; @@ -614,17 +616,18 @@ // N milliseconds. If `immediate` is passed, trigger the function on the // leading edge, instead of the trailing. _.debounce = function(func, wait, immediate) { - var timeout; + var timeout, result; return function() { var context = this, args = arguments; var later = function() { timeout = null; - if (!immediate) func.apply(context, args); + if (!immediate) result = func.apply(context, args); }; var callNow = immediate && !timeout; clearTimeout(timeout); timeout = setTimeout(later, wait); - if (callNow) func.apply(context, args); + if (callNow) result = func.apply(context, args); + return result; }; }; @@ -646,7 +649,8 @@ // conditionally execute the original function. _.wrap = function(func, wrapper) { return function() { - var args = [func].concat(slice.call(arguments, 0)); + var args = [func]; + push.apply(args, arguments); return wrapper.apply(this, args); }; }; @@ -999,8 +1003,8 @@ each(_.functions(obj), function(name){ var func = _[name] = obj[name]; _.prototype[name] = function() { - var args = slice.call(arguments); - args.unshift(this._wrapped); + var args = [this._wrapped]; + push.apply(args, arguments); return result.call(this, func.apply(_, args)); }; }); @@ -1152,4 +1156,4 @@ }); -}).call(this); +}).call(this); \ No newline at end of file