atlas_assets 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/.gitignore +2 -0
  2. data/Gemfile +15 -0
  3. data/Gemfile.lock +86 -0
  4. data/LICENSE +22 -0
  5. data/Procfile +1 -0
  6. data/README.md +36 -0
  7. data/Rakefile +16 -0
  8. data/_config.yml +13 -0
  9. data/atlas_assets.gemspec +21 -0
  10. data/config.ru +9 -0
  11. data/docs/.gitignore +1 -0
  12. data/docs/404.html +1 -0
  13. data/docs/_layouts/default.html +56 -0
  14. data/docs/_plugins/jekyll_assets.rb +3 -0
  15. data/docs/_posts/2013-05-17-buttons.md +43 -0
  16. data/docs/_posts/2013-05-17-flash.md +58 -0
  17. data/docs/_posts/2013-05-17-fonts.md +26 -0
  18. data/docs/_posts/2013-05-17-grid.md +60 -0
  19. data/docs/_posts/2013-05-17-helpers.md +9 -0
  20. data/docs/_posts/2013-05-17-icons.md +1089 -0
  21. data/docs/_posts/2013-05-17-lists.md +76 -0
  22. data/docs/_posts/2013-05-17-navbar.md +73 -0
  23. data/docs/_posts/2013-05-21-forms.md +423 -0
  24. data/docs/index.html +31 -0
  25. data/lib/assets/fonts/atlas.eot +0 -0
  26. data/lib/assets/fonts/atlas.svg +279 -0
  27. data/lib/assets/fonts/atlas.ttf +0 -0
  28. data/lib/assets/fonts/atlas.woff +0 -0
  29. data/lib/assets/javascripts/atlas_assets.js +9 -0
  30. data/lib/assets/javascripts/backbone.js +1572 -0
  31. data/lib/assets/javascripts/jquery.js +9405 -0
  32. data/lib/assets/javascripts/jquery_ujs.js +378 -0
  33. data/lib/assets/javascripts/keypress.js +20 -0
  34. data/lib/assets/javascripts/pusher.js +101 -0
  35. data/lib/assets/javascripts/setup.js +35 -0
  36. data/lib/assets/javascripts/string.js +912 -0
  37. data/lib/assets/javascripts/underscore.js +1228 -0
  38. data/lib/assets/stylesheets/atlas_assets.css +10 -0
  39. data/lib/assets/stylesheets/buttons.css.scss +56 -0
  40. data/lib/assets/stylesheets/flash.css.scss +32 -0
  41. data/lib/assets/stylesheets/fonts.css.scss +66 -0
  42. data/lib/assets/stylesheets/forms.css.scss +861 -0
  43. data/lib/assets/stylesheets/grid.css.scss +762 -0
  44. data/lib/assets/stylesheets/helpers.css.scss +55 -0
  45. data/lib/assets/stylesheets/icons.css.scss +823 -0
  46. data/lib/assets/stylesheets/lists.css.scss +73 -0
  47. data/lib/assets/stylesheets/navbar.css.scss +121 -0
  48. data/lib/assets/stylesheets/pre.css.scss +7 -0
  49. data/lib/atlas_assets/engine.rb +8 -0
  50. data/lib/atlas_assets/version.rb +5 -0
  51. data/lib/atlas_assets.rb +1 -0
  52. data/rails/init.rb +1 -0
  53. metadata +114 -0
@@ -0,0 +1,1228 @@
1
+
2
+ // Underscore.js 1.4.4
3
+ // ===================
4
+
5
+ // > http://underscorejs.org
6
+ // > (c) 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
7
+ // > Underscore may be freely distributed under the MIT license.
8
+
9
+ // Baseline setup
10
+ // --------------
11
+ (function() {
12
+
13
+ // Establish the root object, `window` in the browser, or `global` on the server.
14
+ var root = this;
15
+
16
+ // Save the previous value of the `_` variable.
17
+ var previousUnderscore = root._;
18
+
19
+ // Establish the object that gets returned to break out of a loop iteration.
20
+ var breaker = {};
21
+
22
+ // Save bytes in the minified (but not gzipped) version:
23
+ var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
24
+
25
+ // Create quick reference variables for speed access to core prototypes.
26
+ var push = ArrayProto.push,
27
+ slice = ArrayProto.slice,
28
+ concat = ArrayProto.concat,
29
+ toString = ObjProto.toString,
30
+ hasOwnProperty = ObjProto.hasOwnProperty;
31
+
32
+ // All **ECMAScript 5** native function implementations that we hope to use
33
+ // are declared here.
34
+ var
35
+ nativeForEach = ArrayProto.forEach,
36
+ nativeMap = ArrayProto.map,
37
+ nativeReduce = ArrayProto.reduce,
38
+ nativeReduceRight = ArrayProto.reduceRight,
39
+ nativeFilter = ArrayProto.filter,
40
+ nativeEvery = ArrayProto.every,
41
+ nativeSome = ArrayProto.some,
42
+ nativeIndexOf = ArrayProto.indexOf,
43
+ nativeLastIndexOf = ArrayProto.lastIndexOf,
44
+ nativeIsArray = Array.isArray,
45
+ nativeKeys = Object.keys,
46
+ nativeBind = FuncProto.bind;
47
+
48
+ // Create a safe reference to the Underscore object for use below.
49
+ var _ = function(obj) {
50
+ if (obj instanceof _) return obj;
51
+ if (!(this instanceof _)) return new _(obj);
52
+ this._wrapped = obj;
53
+ };
54
+
55
+ // Export the Underscore object for **Node.js**, with
56
+ // backwards-compatibility for the old `require()` API. If we're in
57
+ // the browser, add `_` as a global object via a string identifier,
58
+ // for Closure Compiler "advanced" mode.
59
+ if (typeof exports !== 'undefined') {
60
+ if (typeof module !== 'undefined' && module.exports) {
61
+ exports = module.exports = _;
62
+ }
63
+ exports._ = _;
64
+ } else {
65
+ root._ = _;
66
+ }
67
+
68
+ // Current version.
69
+ _.VERSION = '1.4.4';
70
+
71
+ // Collection Functions
72
+ // --------------------
73
+
74
+ // The cornerstone, an `each` implementation, aka `forEach`.
75
+ // Handles objects with the built-in `forEach`, arrays, and raw objects.
76
+ // Delegates to **ECMAScript 5**'s native `forEach` if available.
77
+ var each = _.each = _.forEach = function(obj, iterator, context) {
78
+ if (obj == null) return;
79
+ if (nativeForEach && obj.forEach === nativeForEach) {
80
+ obj.forEach(iterator, context);
81
+ } else if (obj.length === +obj.length) {
82
+ for (var i = 0, l = obj.length; i < l; i++) {
83
+ if (iterator.call(context, obj[i], i, obj) === breaker) return;
84
+ }
85
+ } else {
86
+ for (var key in obj) {
87
+ if (_.has(obj, key)) {
88
+ if (iterator.call(context, obj[key], key, obj) === breaker) return;
89
+ }
90
+ }
91
+ }
92
+ };
93
+
94
+ // Return the results of applying the iterator to each element.
95
+ // Delegates to **ECMAScript 5**'s native `map` if available.
96
+ _.map = _.collect = function(obj, iterator, context) {
97
+ var results = [];
98
+ if (obj == null) return results;
99
+ if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
100
+ each(obj, function(value, index, list) {
101
+ results[results.length] = iterator.call(context, value, index, list);
102
+ });
103
+ return results;
104
+ };
105
+
106
+ var reduceError = 'Reduce of empty array with no initial value';
107
+
108
+ // **Reduce** builds up a single result from a list of values, aka `inject`,
109
+ // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available.
110
+ _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) {
111
+ var initial = arguments.length > 2;
112
+ if (obj == null) obj = [];
113
+ if (nativeReduce && obj.reduce === nativeReduce) {
114
+ if (context) iterator = _.bind(iterator, context);
115
+ return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator);
116
+ }
117
+ each(obj, function(value, index, list) {
118
+ if (!initial) {
119
+ memo = value;
120
+ initial = true;
121
+ } else {
122
+ memo = iterator.call(context, memo, value, index, list);
123
+ }
124
+ });
125
+ if (!initial) throw new TypeError(reduceError);
126
+ return memo;
127
+ };
128
+
129
+ // The right-associative version of reduce, also known as `foldr`.
130
+ // Delegates to **ECMAScript 5**'s native `reduceRight` if available.
131
+ _.reduceRight = _.foldr = function(obj, iterator, memo, context) {
132
+ var initial = arguments.length > 2;
133
+ if (obj == null) obj = [];
134
+ if (nativeReduceRight && obj.reduceRight === nativeReduceRight) {
135
+ if (context) iterator = _.bind(iterator, context);
136
+ return initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator);
137
+ }
138
+ var length = obj.length;
139
+ if (length !== +length) {
140
+ var keys = _.keys(obj);
141
+ length = keys.length;
142
+ }
143
+ each(obj, function(value, index, list) {
144
+ index = keys ? keys[--length] : --length;
145
+ if (!initial) {
146
+ memo = obj[index];
147
+ initial = true;
148
+ } else {
149
+ memo = iterator.call(context, memo, obj[index], index, list);
150
+ }
151
+ });
152
+ if (!initial) throw new TypeError(reduceError);
153
+ return memo;
154
+ };
155
+
156
+ // Return the first value which passes a truth test. Aliased as `detect`.
157
+ _.find = _.detect = function(obj, iterator, context) {
158
+ var result;
159
+ any(obj, function(value, index, list) {
160
+ if (iterator.call(context, value, index, list)) {
161
+ result = value;
162
+ return true;
163
+ }
164
+ });
165
+ return result;
166
+ };
167
+
168
+ // Return all the elements that pass a truth test.
169
+ // Delegates to **ECMAScript 5**'s native `filter` if available.
170
+ // Aliased as `select`.
171
+ _.filter = _.select = function(obj, iterator, context) {
172
+ var results = [];
173
+ if (obj == null) return results;
174
+ if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context);
175
+ each(obj, function(value, index, list) {
176
+ if (iterator.call(context, value, index, list)) results[results.length] = value;
177
+ });
178
+ return results;
179
+ };
180
+
181
+ // Return all the elements for which a truth test fails.
182
+ _.reject = function(obj, iterator, context) {
183
+ return _.filter(obj, function(value, index, list) {
184
+ return !iterator.call(context, value, index, list);
185
+ }, context);
186
+ };
187
+
188
+ // Determine whether all of the elements match a truth test.
189
+ // Delegates to **ECMAScript 5**'s native `every` if available.
190
+ // Aliased as `all`.
191
+ _.every = _.all = function(obj, iterator, context) {
192
+ iterator || (iterator = _.identity);
193
+ var result = true;
194
+ if (obj == null) return result;
195
+ if (nativeEvery && obj.every === nativeEvery) return obj.every(iterator, context);
196
+ each(obj, function(value, index, list) {
197
+ if (!(result = result && iterator.call(context, value, index, list))) return breaker;
198
+ });
199
+ return !!result;
200
+ };
201
+
202
+ // Determine if at least one element in the object matches a truth test.
203
+ // Delegates to **ECMAScript 5**'s native `some` if available.
204
+ // Aliased as `any`.
205
+ var any = _.some = _.any = function(obj, iterator, context) {
206
+ iterator || (iterator = _.identity);
207
+ var result = false;
208
+ if (obj == null) return result;
209
+ if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
210
+ each(obj, function(value, index, list) {
211
+ if (result || (result = iterator.call(context, value, index, list))) return breaker;
212
+ });
213
+ return !!result;
214
+ };
215
+
216
+ // Determine if the array or object contains a given value (using `===`).
217
+ // Aliased as `include`.
218
+ _.contains = _.include = function(obj, target) {
219
+ if (obj == null) return false;
220
+ if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1;
221
+ return any(obj, function(value) {
222
+ return value === target;
223
+ });
224
+ };
225
+
226
+ // Invoke a method (with arguments) on every item in a collection.
227
+ _.invoke = function(obj, method) {
228
+ var args = slice.call(arguments, 2);
229
+ var isFunc = _.isFunction(method);
230
+ return _.map(obj, function(value) {
231
+ return (isFunc ? method : value[method]).apply(value, args);
232
+ });
233
+ };
234
+
235
+ // Convenience version of a common use case of `map`: fetching a property.
236
+ _.pluck = function(obj, key) {
237
+ return _.map(obj, function(value){ return value[key]; });
238
+ };
239
+
240
+ // Convenience version of a common use case of `filter`: selecting only objects
241
+ // containing specific `key:value` pairs.
242
+ _.where = function(obj, attrs, first) {
243
+ if (_.isEmpty(attrs)) return first ? null : [];
244
+ return _[first ? 'find' : 'filter'](obj, function(value) {
245
+ for (var key in attrs) {
246
+ if (attrs[key] !== value[key]) return false;
247
+ }
248
+ return true;
249
+ });
250
+ };
251
+
252
+ // Convenience version of a common use case of `find`: getting the first object
253
+ // containing specific `key:value` pairs.
254
+ _.findWhere = function(obj, attrs) {
255
+ return _.where(obj, attrs, true);
256
+ };
257
+
258
+ // Return the maximum element or (element-based computation).
259
+ // Can't optimize arrays of integers longer than 65,535 elements.
260
+ // See: https://bugs.webkit.org/show_bug.cgi?id=80797
261
+ _.max = function(obj, iterator, context) {
262
+ if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
263
+ return Math.max.apply(Math, obj);
264
+ }
265
+ if (!iterator && _.isEmpty(obj)) return -Infinity;
266
+ var result = {computed : -Infinity, value: -Infinity};
267
+ each(obj, function(value, index, list) {
268
+ var computed = iterator ? iterator.call(context, value, index, list) : value;
269
+ computed >= result.computed && (result = {value : value, computed : computed});
270
+ });
271
+ return result.value;
272
+ };
273
+
274
+ // Return the minimum element (or element-based computation).
275
+ _.min = function(obj, iterator, context) {
276
+ if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
277
+ return Math.min.apply(Math, obj);
278
+ }
279
+ if (!iterator && _.isEmpty(obj)) return Infinity;
280
+ var result = {computed : Infinity, value: Infinity};
281
+ each(obj, function(value, index, list) {
282
+ var computed = iterator ? iterator.call(context, value, index, list) : value;
283
+ computed < result.computed && (result = {value : value, computed : computed});
284
+ });
285
+ return result.value;
286
+ };
287
+
288
+ // Shuffle an array.
289
+ _.shuffle = function(obj) {
290
+ var rand;
291
+ var index = 0;
292
+ var shuffled = [];
293
+ each(obj, function(value) {
294
+ rand = _.random(index++);
295
+ shuffled[index - 1] = shuffled[rand];
296
+ shuffled[rand] = value;
297
+ });
298
+ return shuffled;
299
+ };
300
+
301
+ // An internal function to generate lookup iterators.
302
+ var lookupIterator = function(value) {
303
+ return _.isFunction(value) ? value : function(obj){ return obj[value]; };
304
+ };
305
+
306
+ // Sort the object's values by a criterion produced by an iterator.
307
+ _.sortBy = function(obj, value, context) {
308
+ var iterator = lookupIterator(value);
309
+ return _.pluck(_.map(obj, function(value, index, list) {
310
+ return {
311
+ value : value,
312
+ index : index,
313
+ criteria : iterator.call(context, value, index, list)
314
+ };
315
+ }).sort(function(left, right) {
316
+ var a = left.criteria;
317
+ var b = right.criteria;
318
+ if (a !== b) {
319
+ if (a > b || a === void 0) return 1;
320
+ if (a < b || b === void 0) return -1;
321
+ }
322
+ return left.index < right.index ? -1 : 1;
323
+ }), 'value');
324
+ };
325
+
326
+ // An internal function used for aggregate "group by" operations.
327
+ var group = function(obj, value, context, behavior) {
328
+ var result = {};
329
+ var iterator = lookupIterator(value || _.identity);
330
+ each(obj, function(value, index) {
331
+ var key = iterator.call(context, value, index, obj);
332
+ behavior(result, key, value);
333
+ });
334
+ return result;
335
+ };
336
+
337
+ // Groups the object's values by a criterion. Pass either a string attribute
338
+ // to group by, or a function that returns the criterion.
339
+ _.groupBy = function(obj, value, context) {
340
+ return group(obj, value, context, function(result, key, value) {
341
+ (_.has(result, key) ? result[key] : (result[key] = [])).push(value);
342
+ });
343
+ };
344
+
345
+ // Counts instances of an object that group by a certain criterion. Pass
346
+ // either a string attribute to count by, or a function that returns the
347
+ // criterion.
348
+ _.countBy = function(obj, value, context) {
349
+ return group(obj, value, context, function(result, key) {
350
+ if (!_.has(result, key)) result[key] = 0;
351
+ result[key]++;
352
+ });
353
+ };
354
+
355
+ // Use a comparator function to figure out the smallest index at which
356
+ // an object should be inserted so as to maintain order. Uses binary search.
357
+ _.sortedIndex = function(array, obj, iterator, context) {
358
+ iterator = iterator == null ? _.identity : lookupIterator(iterator);
359
+ var value = iterator.call(context, obj);
360
+ var low = 0, high = array.length;
361
+ while (low < high) {
362
+ var mid = (low + high) >>> 1;
363
+ iterator.call(context, array[mid]) < value ? low = mid + 1 : high = mid;
364
+ }
365
+ return low;
366
+ };
367
+
368
+ // Safely convert anything iterable into a real, live array.
369
+ _.toArray = function(obj) {
370
+ if (!obj) return [];
371
+ if (_.isArray(obj)) return slice.call(obj);
372
+ if (obj.length === +obj.length) return _.map(obj, _.identity);
373
+ return _.values(obj);
374
+ };
375
+
376
+ // Return the number of elements in an object.
377
+ _.size = function(obj) {
378
+ if (obj == null) return 0;
379
+ return (obj.length === +obj.length) ? obj.length : _.keys(obj).length;
380
+ };
381
+
382
+ // Array Functions
383
+ // ---------------
384
+
385
+ // Get the first element of an array. Passing **n** will return the first N
386
+ // values in the array. Aliased as `head` and `take`. The **guard** check
387
+ // allows it to work with `_.map`.
388
+ _.first = _.head = _.take = function(array, n, guard) {
389
+ if (array == null) return void 0;
390
+ return (n != null) && !guard ? slice.call(array, 0, n) : array[0];
391
+ };
392
+
393
+ // Returns everything but the last entry of the array. Especially useful on
394
+ // the arguments object. Passing **n** will return all the values in
395
+ // the array, excluding the last N. The **guard** check allows it to work with
396
+ // `_.map`.
397
+ _.initial = function(array, n, guard) {
398
+ return slice.call(array, 0, array.length - ((n == null) || guard ? 1 : n));
399
+ };
400
+
401
+ // Get the last element of an array. Passing **n** will return the last N
402
+ // values in the array. The **guard** check allows it to work with `_.map`.
403
+ _.last = function(array, n, guard) {
404
+ if (array == null) return void 0;
405
+ if ((n != null) && !guard) {
406
+ return slice.call(array, Math.max(array.length - n, 0));
407
+ } else {
408
+ return array[array.length - 1];
409
+ }
410
+ };
411
+
412
+ // Returns everything but the first entry of the array. Aliased as `tail` and `drop`.
413
+ // Especially useful on the arguments object. Passing an **n** will return
414
+ // the rest N values in the array. The **guard**
415
+ // check allows it to work with `_.map`.
416
+ _.rest = _.tail = _.drop = function(array, n, guard) {
417
+ return slice.call(array, (n == null) || guard ? 1 : n);
418
+ };
419
+
420
+ // Trim out all falsy values from an array.
421
+ _.compact = function(array) {
422
+ return _.filter(array, _.identity);
423
+ };
424
+
425
+ // Internal implementation of a recursive `flatten` function.
426
+ var flatten = function(input, shallow, output) {
427
+ each(input, function(value) {
428
+ if (_.isArray(value)) {
429
+ shallow ? push.apply(output, value) : flatten(value, shallow, output);
430
+ } else {
431
+ output.push(value);
432
+ }
433
+ });
434
+ return output;
435
+ };
436
+
437
+ // Return a completely flattened version of an array.
438
+ _.flatten = function(array, shallow) {
439
+ return flatten(array, shallow, []);
440
+ };
441
+
442
+ // Return a version of the array that does not contain the specified value(s).
443
+ _.without = function(array) {
444
+ return _.difference(array, slice.call(arguments, 1));
445
+ };
446
+
447
+ // Produce a duplicate-free version of the array. If the array has already
448
+ // been sorted, you have the option of using a faster algorithm.
449
+ // Aliased as `unique`.
450
+ _.uniq = _.unique = function(array, isSorted, iterator, context) {
451
+ if (_.isFunction(isSorted)) {
452
+ context = iterator;
453
+ iterator = isSorted;
454
+ isSorted = false;
455
+ }
456
+ var initial = iterator ? _.map(array, iterator, context) : array;
457
+ var results = [];
458
+ var seen = [];
459
+ each(initial, function(value, index) {
460
+ if (isSorted ? (!index || seen[seen.length - 1] !== value) : !_.contains(seen, value)) {
461
+ seen.push(value);
462
+ results.push(array[index]);
463
+ }
464
+ });
465
+ return results;
466
+ };
467
+
468
+ // Produce an array that contains the union: each distinct element from all of
469
+ // the passed-in arrays.
470
+ _.union = function() {
471
+ return _.uniq(concat.apply(ArrayProto, arguments));
472
+ };
473
+
474
+ // Produce an array that contains every item shared between all the
475
+ // passed-in arrays.
476
+ _.intersection = function(array) {
477
+ var rest = slice.call(arguments, 1);
478
+ return _.filter(_.uniq(array), function(item) {
479
+ return _.every(rest, function(other) {
480
+ return _.indexOf(other, item) >= 0;
481
+ });
482
+ });
483
+ };
484
+
485
+ // Take the difference between one array and a number of other arrays.
486
+ // Only the elements present in just the first array will remain.
487
+ _.difference = function(array) {
488
+ var rest = concat.apply(ArrayProto, slice.call(arguments, 1));
489
+ return _.filter(array, function(value){ return !_.contains(rest, value); });
490
+ };
491
+
492
+ // Zip together multiple lists into a single array -- elements that share
493
+ // an index go together.
494
+ _.zip = function() {
495
+ var args = slice.call(arguments);
496
+ var length = _.max(_.pluck(args, 'length'));
497
+ var results = new Array(length);
498
+ for (var i = 0; i < length; i++) {
499
+ results[i] = _.pluck(args, "" + i);
500
+ }
501
+ return results;
502
+ };
503
+
504
+ // Converts lists into objects. Pass either a single array of `[key, value]`
505
+ // pairs, or two parallel arrays of the same length -- one of keys, and one of
506
+ // the corresponding values.
507
+ _.object = function(list, values) {
508
+ if (list == null) return {};
509
+ var result = {};
510
+ for (var i = 0, l = list.length; i < l; i++) {
511
+ if (values) {
512
+ result[list[i]] = values[i];
513
+ } else {
514
+ result[list[i][0]] = list[i][1];
515
+ }
516
+ }
517
+ return result;
518
+ };
519
+
520
+ // If the browser doesn't supply us with indexOf (I'm looking at you, **MSIE**),
521
+ // we need this function. Return the position of the first occurrence of an
522
+ // item in an array, or -1 if the item is not included in the array.
523
+ // Delegates to **ECMAScript 5**'s native `indexOf` if available.
524
+ // If the array is large and already in sort order, pass `true`
525
+ // for **isSorted** to use binary search.
526
+ _.indexOf = function(array, item, isSorted) {
527
+ if (array == null) return -1;
528
+ var i = 0, l = array.length;
529
+ if (isSorted) {
530
+ if (typeof isSorted == 'number') {
531
+ i = (isSorted < 0 ? Math.max(0, l + isSorted) : isSorted);
532
+ } else {
533
+ i = _.sortedIndex(array, item);
534
+ return array[i] === item ? i : -1;
535
+ }
536
+ }
537
+ if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item, isSorted);
538
+ for (; i < l; i++) if (array[i] === item) return i;
539
+ return -1;
540
+ };
541
+
542
+ // Delegates to **ECMAScript 5**'s native `lastIndexOf` if available.
543
+ _.lastIndexOf = function(array, item, from) {
544
+ if (array == null) return -1;
545
+ var hasIndex = from != null;
546
+ if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) {
547
+ return hasIndex ? array.lastIndexOf(item, from) : array.lastIndexOf(item);
548
+ }
549
+ var i = (hasIndex ? from : array.length);
550
+ while (i--) if (array[i] === item) return i;
551
+ return -1;
552
+ };
553
+
554
+ // Generate an integer Array containing an arithmetic progression. A port of
555
+ // the native Python `range()` function. See
556
+ // [the Python documentation](http://docs.python.org/library/functions.html#range).
557
+ _.range = function(start, stop, step) {
558
+ if (arguments.length <= 1) {
559
+ stop = start || 0;
560
+ start = 0;
561
+ }
562
+ step = arguments[2] || 1;
563
+
564
+ var len = Math.max(Math.ceil((stop - start) / step), 0);
565
+ var idx = 0;
566
+ var range = new Array(len);
567
+
568
+ while(idx < len) {
569
+ range[idx++] = start;
570
+ start += step;
571
+ }
572
+
573
+ return range;
574
+ };
575
+
576
+ // Function (ahem) Functions
577
+ // ------------------
578
+
579
+ // Create a function bound to a given object (assigning `this`, and arguments,
580
+ // optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
581
+ // available.
582
+ _.bind = function(func, context) {
583
+ if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
584
+ var args = slice.call(arguments, 2);
585
+ return function() {
586
+ return func.apply(context, args.concat(slice.call(arguments)));
587
+ };
588
+ };
589
+
590
+ // Partially apply a function by creating a version that has had some of its
591
+ // arguments pre-filled, without changing its dynamic `this` context.
592
+ _.partial = function(func) {
593
+ var args = slice.call(arguments, 1);
594
+ return function() {
595
+ return func.apply(this, args.concat(slice.call(arguments)));
596
+ };
597
+ };
598
+
599
+ // Bind all of an object's methods to that object. Useful for ensuring that
600
+ // all callbacks defined on an object belong to it.
601
+ _.bindAll = function(obj) {
602
+ var funcs = slice.call(arguments, 1);
603
+ if (funcs.length === 0) funcs = _.functions(obj);
604
+ each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); });
605
+ return obj;
606
+ };
607
+
608
+ // Memoize an expensive function by storing its results.
609
+ _.memoize = function(func, hasher) {
610
+ var memo = {};
611
+ hasher || (hasher = _.identity);
612
+ return function() {
613
+ var key = hasher.apply(this, arguments);
614
+ return _.has(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments));
615
+ };
616
+ };
617
+
618
+ // Delays a function for the given number of milliseconds, and then calls
619
+ // it with the arguments supplied.
620
+ _.delay = function(func, wait) {
621
+ var args = slice.call(arguments, 2);
622
+ return setTimeout(function(){ return func.apply(null, args); }, wait);
623
+ };
624
+
625
+ // Defers a function, scheduling it to run after the current call stack has
626
+ // cleared.
627
+ _.defer = function(func) {
628
+ return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1)));
629
+ };
630
+
631
+ // Returns a function, that, when invoked, will only be triggered at most once
632
+ // during a given window of time.
633
+ _.throttle = function(func, wait) {
634
+ var context, args, timeout, result;
635
+ var previous = 0;
636
+ var later = function() {
637
+ previous = new Date;
638
+ timeout = null;
639
+ result = func.apply(context, args);
640
+ };
641
+ return function() {
642
+ var now = new Date;
643
+ var remaining = wait - (now - previous);
644
+ context = this;
645
+ args = arguments;
646
+ if (remaining <= 0) {
647
+ clearTimeout(timeout);
648
+ timeout = null;
649
+ previous = now;
650
+ result = func.apply(context, args);
651
+ } else if (!timeout) {
652
+ timeout = setTimeout(later, remaining);
653
+ }
654
+ return result;
655
+ };
656
+ };
657
+
658
+ // Returns a function, that, as long as it continues to be invoked, will not
659
+ // be triggered. The function will be called after it stops being called for
660
+ // N milliseconds. If `immediate` is passed, trigger the function on the
661
+ // leading edge, instead of the trailing.
662
+ _.debounce = function(func, wait, immediate) {
663
+ var timeout, result;
664
+ return function() {
665
+ var context = this, args = arguments;
666
+ var later = function() {
667
+ timeout = null;
668
+ if (!immediate) result = func.apply(context, args);
669
+ };
670
+ var callNow = immediate && !timeout;
671
+ clearTimeout(timeout);
672
+ timeout = setTimeout(later, wait);
673
+ if (callNow) result = func.apply(context, args);
674
+ return result;
675
+ };
676
+ };
677
+
678
+ // Returns a function that will be executed at most one time, no matter how
679
+ // often you call it. Useful for lazy initialization.
680
+ _.once = function(func) {
681
+ var ran = false, memo;
682
+ return function() {
683
+ if (ran) return memo;
684
+ ran = true;
685
+ memo = func.apply(this, arguments);
686
+ func = null;
687
+ return memo;
688
+ };
689
+ };
690
+
691
+ // Returns the first function passed as an argument to the second,
692
+ // allowing you to adjust arguments, run code before and after, and
693
+ // conditionally execute the original function.
694
+ _.wrap = function(func, wrapper) {
695
+ return function() {
696
+ var args = [func];
697
+ push.apply(args, arguments);
698
+ return wrapper.apply(this, args);
699
+ };
700
+ };
701
+
702
+ // Returns a function that is the composition of a list of functions, each
703
+ // consuming the return value of the function that follows.
704
+ _.compose = function() {
705
+ var funcs = arguments;
706
+ return function() {
707
+ var args = arguments;
708
+ for (var i = funcs.length - 1; i >= 0; i--) {
709
+ args = [funcs[i].apply(this, args)];
710
+ }
711
+ return args[0];
712
+ };
713
+ };
714
+
715
+ // Returns a function that will only be executed after being called N times.
716
+ _.after = function(times, func) {
717
+ if (times <= 0) return func();
718
+ return function() {
719
+ if (--times < 1) {
720
+ return func.apply(this, arguments);
721
+ }
722
+ };
723
+ };
724
+
725
+ // Object Functions
726
+ // ----------------
727
+
728
+ // Retrieve the names of an object's properties.
729
+ // Delegates to **ECMAScript 5**'s native `Object.keys`
730
+ _.keys = nativeKeys || function(obj) {
731
+ if (obj !== Object(obj)) throw new TypeError('Invalid object');
732
+ var keys = [];
733
+ for (var key in obj) if (_.has(obj, key)) keys[keys.length] = key;
734
+ return keys;
735
+ };
736
+
737
+ // Retrieve the values of an object's properties.
738
+ _.values = function(obj) {
739
+ var values = [];
740
+ for (var key in obj) if (_.has(obj, key)) values.push(obj[key]);
741
+ return values;
742
+ };
743
+
744
+ // Convert an object into a list of `[key, value]` pairs.
745
+ _.pairs = function(obj) {
746
+ var pairs = [];
747
+ for (var key in obj) if (_.has(obj, key)) pairs.push([key, obj[key]]);
748
+ return pairs;
749
+ };
750
+
751
+ // Invert the keys and values of an object. The values must be serializable.
752
+ _.invert = function(obj) {
753
+ var result = {};
754
+ for (var key in obj) if (_.has(obj, key)) result[obj[key]] = key;
755
+ return result;
756
+ };
757
+
758
+ // Return a sorted list of the function names available on the object.
759
+ // Aliased as `methods`
760
+ _.functions = _.methods = function(obj) {
761
+ var names = [];
762
+ for (var key in obj) {
763
+ if (_.isFunction(obj[key])) names.push(key);
764
+ }
765
+ return names.sort();
766
+ };
767
+
768
+ // Extend a given object with all the properties in passed-in object(s).
769
+ _.extend = function(obj) {
770
+ each(slice.call(arguments, 1), function(source) {
771
+ if (source) {
772
+ for (var prop in source) {
773
+ obj[prop] = source[prop];
774
+ }
775
+ }
776
+ });
777
+ return obj;
778
+ };
779
+
780
+ // Return a copy of the object only containing the whitelisted properties.
781
+ _.pick = function(obj) {
782
+ var copy = {};
783
+ var keys = concat.apply(ArrayProto, slice.call(arguments, 1));
784
+ each(keys, function(key) {
785
+ if (key in obj) copy[key] = obj[key];
786
+ });
787
+ return copy;
788
+ };
789
+
790
+ // Return a copy of the object without the blacklisted properties.
791
+ _.omit = function(obj) {
792
+ var copy = {};
793
+ var keys = concat.apply(ArrayProto, slice.call(arguments, 1));
794
+ for (var key in obj) {
795
+ if (!_.contains(keys, key)) copy[key] = obj[key];
796
+ }
797
+ return copy;
798
+ };
799
+
800
+ // Fill in a given object with default properties.
801
+ _.defaults = function(obj) {
802
+ each(slice.call(arguments, 1), function(source) {
803
+ if (source) {
804
+ for (var prop in source) {
805
+ if (obj[prop] == null) obj[prop] = source[prop];
806
+ }
807
+ }
808
+ });
809
+ return obj;
810
+ };
811
+
812
+ // Create a (shallow-cloned) duplicate of an object.
813
+ _.clone = function(obj) {
814
+ if (!_.isObject(obj)) return obj;
815
+ return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
816
+ };
817
+
818
+ // Invokes interceptor with the obj, and then returns obj.
819
+ // The primary purpose of this method is to "tap into" a method chain, in
820
+ // order to perform operations on intermediate results within the chain.
821
+ _.tap = function(obj, interceptor) {
822
+ interceptor(obj);
823
+ return obj;
824
+ };
825
+
826
+ // Internal recursive comparison function for `isEqual`.
827
+ var eq = function(a, b, aStack, bStack) {
828
+ // Identical objects are equal. `0 === -0`, but they aren't identical.
829
+ // See the Harmony `egal` proposal: http://wiki.ecmascript.org/doku.php?id=harmony:egal.
830
+ if (a === b) return a !== 0 || 1 / a == 1 / b;
831
+ // A strict comparison is necessary because `null == undefined`.
832
+ if (a == null || b == null) return a === b;
833
+ // Unwrap any wrapped objects.
834
+ if (a instanceof _) a = a._wrapped;
835
+ if (b instanceof _) b = b._wrapped;
836
+ // Compare `[[Class]]` names.
837
+ var className = toString.call(a);
838
+ if (className != toString.call(b)) return false;
839
+ switch (className) {
840
+ // Strings, numbers, dates, and booleans are compared by value.
841
+ case '[object String]':
842
+ // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
843
+ // equivalent to `new String("5")`.
844
+ return a == String(b);
845
+ case '[object Number]':
846
+ // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for
847
+ // other numeric values.
848
+ return a != +a ? b != +b : (a == 0 ? 1 / a == 1 / b : a == +b);
849
+ case '[object Date]':
850
+ case '[object Boolean]':
851
+ // Coerce dates and booleans to numeric primitive values. Dates are compared by their
852
+ // millisecond representations. Note that invalid dates with millisecond representations
853
+ // of `NaN` are not equivalent.
854
+ return +a == +b;
855
+ // RegExps are compared by their source patterns and flags.
856
+ case '[object RegExp]':
857
+ return a.source == b.source &&
858
+ a.global == b.global &&
859
+ a.multiline == b.multiline &&
860
+ a.ignoreCase == b.ignoreCase;
861
+ }
862
+ if (typeof a != 'object' || typeof b != 'object') return false;
863
+ // Assume equality for cyclic structures. The algorithm for detecting cyclic
864
+ // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
865
+ var length = aStack.length;
866
+ while (length--) {
867
+ // Linear search. Performance is inversely proportional to the number of
868
+ // unique nested structures.
869
+ if (aStack[length] == a) return bStack[length] == b;
870
+ }
871
+ // Add the first object to the stack of traversed objects.
872
+ aStack.push(a);
873
+ bStack.push(b);
874
+ var size = 0, result = true;
875
+ // Recursively compare objects and arrays.
876
+ if (className == '[object Array]') {
877
+ // Compare array lengths to determine if a deep comparison is necessary.
878
+ size = a.length;
879
+ result = size == b.length;
880
+ if (result) {
881
+ // Deep compare the contents, ignoring non-numeric properties.
882
+ while (size--) {
883
+ if (!(result = eq(a[size], b[size], aStack, bStack))) break;
884
+ }
885
+ }
886
+ } else {
887
+ // Objects with different constructors are not equivalent, but `Object`s
888
+ // from different frames are.
889
+ var aCtor = a.constructor, bCtor = b.constructor;
890
+ if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) &&
891
+ _.isFunction(bCtor) && (bCtor instanceof bCtor))) {
892
+ return false;
893
+ }
894
+ // Deep compare objects.
895
+ for (var key in a) {
896
+ if (_.has(a, key)) {
897
+ // Count the expected number of properties.
898
+ size++;
899
+ // Deep compare each member.
900
+ if (!(result = _.has(b, key) && eq(a[key], b[key], aStack, bStack))) break;
901
+ }
902
+ }
903
+ // Ensure that both objects contain the same number of properties.
904
+ if (result) {
905
+ for (key in b) {
906
+ if (_.has(b, key) && !(size--)) break;
907
+ }
908
+ result = !size;
909
+ }
910
+ }
911
+ // Remove the first object from the stack of traversed objects.
912
+ aStack.pop();
913
+ bStack.pop();
914
+ return result;
915
+ };
916
+
917
+ // Perform a deep comparison to check if two objects are equal.
918
+ _.isEqual = function(a, b) {
919
+ return eq(a, b, [], []);
920
+ };
921
+
922
+ // Is a given array, string, or object empty?
923
+ // An "empty" object has no enumerable own-properties.
924
+ _.isEmpty = function(obj) {
925
+ if (obj == null) return true;
926
+ if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
927
+ for (var key in obj) if (_.has(obj, key)) return false;
928
+ return true;
929
+ };
930
+
931
+ // Is a given value a DOM element?
932
+ _.isElement = function(obj) {
933
+ return !!(obj && obj.nodeType === 1);
934
+ };
935
+
936
+ // Is a given value an array?
937
+ // Delegates to ECMA5's native Array.isArray
938
+ _.isArray = nativeIsArray || function(obj) {
939
+ return toString.call(obj) == '[object Array]';
940
+ };
941
+
942
+ // Is a given variable an object?
943
+ _.isObject = function(obj) {
944
+ return obj === Object(obj);
945
+ };
946
+
947
+ // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp.
948
+ each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) {
949
+ _['is' + name] = function(obj) {
950
+ return toString.call(obj) == '[object ' + name + ']';
951
+ };
952
+ });
953
+
954
+ // Define a fallback version of the method in browsers (ahem, IE), where
955
+ // there isn't any inspectable "Arguments" type.
956
+ if (!_.isArguments(arguments)) {
957
+ _.isArguments = function(obj) {
958
+ return !!(obj && _.has(obj, 'callee'));
959
+ };
960
+ }
961
+
962
+ // Optimize `isFunction` if appropriate.
963
+ if (typeof (/./) !== 'function') {
964
+ _.isFunction = function(obj) {
965
+ return typeof obj === 'function';
966
+ };
967
+ }
968
+
969
+ // Is a given object a finite number?
970
+ _.isFinite = function(obj) {
971
+ return isFinite(obj) && !isNaN(parseFloat(obj));
972
+ };
973
+
974
+ // Is the given value `NaN`? (NaN is the only number which does not equal itself).
975
+ _.isNaN = function(obj) {
976
+ return _.isNumber(obj) && obj != +obj;
977
+ };
978
+
979
+ // Is a given value a boolean?
980
+ _.isBoolean = function(obj) {
981
+ return obj === true || obj === false || toString.call(obj) == '[object Boolean]';
982
+ };
983
+
984
+ // Is a given value equal to null?
985
+ _.isNull = function(obj) {
986
+ return obj === null;
987
+ };
988
+
989
+ // Is a given variable undefined?
990
+ _.isUndefined = function(obj) {
991
+ return obj === void 0;
992
+ };
993
+
994
+ // Shortcut function for checking if an object has a given property directly
995
+ // on itself (in other words, not on a prototype).
996
+ _.has = function(obj, key) {
997
+ return hasOwnProperty.call(obj, key);
998
+ };
999
+
1000
+ // Utility Functions
1001
+ // -----------------
1002
+
1003
+ // Run Underscore.js in *noConflict* mode, returning the `_` variable to its
1004
+ // previous owner. Returns a reference to the Underscore object.
1005
+ _.noConflict = function() {
1006
+ root._ = previousUnderscore;
1007
+ return this;
1008
+ };
1009
+
1010
+ // Keep the identity function around for default iterators.
1011
+ _.identity = function(value) {
1012
+ return value;
1013
+ };
1014
+
1015
+ // Run a function **n** times.
1016
+ _.times = function(n, iterator, context) {
1017
+ var accum = Array(n);
1018
+ for (var i = 0; i < n; i++) accum[i] = iterator.call(context, i);
1019
+ return accum;
1020
+ };
1021
+
1022
+ // Return a random integer between min and max (inclusive).
1023
+ _.random = function(min, max) {
1024
+ if (max == null) {
1025
+ max = min;
1026
+ min = 0;
1027
+ }
1028
+ return min + Math.floor(Math.random() * (max - min + 1));
1029
+ };
1030
+
1031
+ // List of HTML entities for escaping.
1032
+ var entityMap = {
1033
+ escape: {
1034
+ '&': '&amp;',
1035
+ '<': '&lt;',
1036
+ '>': '&gt;',
1037
+ '"': '&quot;',
1038
+ "'": '&#x27;',
1039
+ '/': '&#x2F;'
1040
+ }
1041
+ };
1042
+ entityMap.unescape = _.invert(entityMap.escape);
1043
+
1044
+ // Regexes containing the keys and values listed immediately above.
1045
+ var entityRegexes = {
1046
+ escape: new RegExp('[' + _.keys(entityMap.escape).join('') + ']', 'g'),
1047
+ unescape: new RegExp('(' + _.keys(entityMap.unescape).join('|') + ')', 'g')
1048
+ };
1049
+
1050
+ // Functions for escaping and unescaping strings to/from HTML interpolation.
1051
+ _.each(['escape', 'unescape'], function(method) {
1052
+ _[method] = function(string) {
1053
+ if (string == null) return '';
1054
+ return ('' + string).replace(entityRegexes[method], function(match) {
1055
+ return entityMap[method][match];
1056
+ });
1057
+ };
1058
+ });
1059
+
1060
+ // If the value of the named property is a function then invoke it;
1061
+ // otherwise, return it.
1062
+ _.result = function(object, property) {
1063
+ if (object == null) return null;
1064
+ var value = object[property];
1065
+ return _.isFunction(value) ? value.call(object) : value;
1066
+ };
1067
+
1068
+ // Add your own custom functions to the Underscore object.
1069
+ _.mixin = function(obj) {
1070
+ each(_.functions(obj), function(name){
1071
+ var func = _[name] = obj[name];
1072
+ _.prototype[name] = function() {
1073
+ var args = [this._wrapped];
1074
+ push.apply(args, arguments);
1075
+ return result.call(this, func.apply(_, args));
1076
+ };
1077
+ });
1078
+ };
1079
+
1080
+ // Generate a unique integer id (unique within the entire client session).
1081
+ // Useful for temporary DOM ids.
1082
+ var idCounter = 0;
1083
+ _.uniqueId = function(prefix) {
1084
+ var id = ++idCounter + '';
1085
+ return prefix ? prefix + id : id;
1086
+ };
1087
+
1088
+ // By default, Underscore uses ERB-style template delimiters, change the
1089
+ // following template settings to use alternative delimiters.
1090
+ _.templateSettings = {
1091
+ evaluate : /<%([\s\S]+?)%>/g,
1092
+ interpolate : /<%=([\s\S]+?)%>/g,
1093
+ escape : /<%-([\s\S]+?)%>/g
1094
+ };
1095
+
1096
+ // When customizing `templateSettings`, if you don't want to define an
1097
+ // interpolation, evaluation or escaping regex, we need one that is
1098
+ // guaranteed not to match.
1099
+ var noMatch = /(.)^/;
1100
+
1101
+ // Certain characters need to be escaped so that they can be put into a
1102
+ // string literal.
1103
+ var escapes = {
1104
+ "'": "'",
1105
+ '\\': '\\',
1106
+ '\r': 'r',
1107
+ '\n': 'n',
1108
+ '\t': 't',
1109
+ '\u2028': 'u2028',
1110
+ '\u2029': 'u2029'
1111
+ };
1112
+
1113
+ var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g;
1114
+
1115
+ // JavaScript micro-templating, similar to John Resig's implementation.
1116
+ // Underscore templating handles arbitrary delimiters, preserves whitespace,
1117
+ // and correctly escapes quotes within interpolated code.
1118
+ _.template = function(text, data, settings) {
1119
+ var render;
1120
+ settings = _.defaults({}, settings, _.templateSettings);
1121
+
1122
+ // Combine delimiters into one regular expression via alternation.
1123
+ var matcher = new RegExp([
1124
+ (settings.escape || noMatch).source,
1125
+ (settings.interpolate || noMatch).source,
1126
+ (settings.evaluate || noMatch).source
1127
+ ].join('|') + '|$', 'g');
1128
+
1129
+ // Compile the template source, escaping string literals appropriately.
1130
+ var index = 0;
1131
+ var source = "__p+='";
1132
+ text.replace(matcher, function(match, escape, interpolate, evaluate, offset) {
1133
+ source += text.slice(index, offset)
1134
+ .replace(escaper, function(match) { return '\\' + escapes[match]; });
1135
+
1136
+ if (escape) {
1137
+ source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'";
1138
+ }
1139
+ if (interpolate) {
1140
+ source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'";
1141
+ }
1142
+ if (evaluate) {
1143
+ source += "';\n" + evaluate + "\n__p+='";
1144
+ }
1145
+ index = offset + match.length;
1146
+ return match;
1147
+ });
1148
+ source += "';\n";
1149
+
1150
+ // If a variable is not specified, place data values in local scope.
1151
+ if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n';
1152
+
1153
+ source = "var __t,__p='',__j=Array.prototype.join," +
1154
+ "print=function(){__p+=__j.call(arguments,'');};\n" +
1155
+ source + "return __p;\n";
1156
+
1157
+ try {
1158
+ render = new Function(settings.variable || 'obj', '_', source);
1159
+ } catch (e) {
1160
+ e.source = source;
1161
+ throw e;
1162
+ }
1163
+
1164
+ if (data) return render(data, _);
1165
+ var template = function(data) {
1166
+ return render.call(this, data, _);
1167
+ };
1168
+
1169
+ // Provide the compiled function source as a convenience for precompilation.
1170
+ template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}';
1171
+
1172
+ return template;
1173
+ };
1174
+
1175
+ // Add a "chain" function, which will delegate to the wrapper.
1176
+ _.chain = function(obj) {
1177
+ return _(obj).chain();
1178
+ };
1179
+
1180
+ // OOP
1181
+ // ---------------
1182
+ // If Underscore is called as a function, it returns a wrapped object that
1183
+ // can be used OO-style. This wrapper holds altered versions of all the
1184
+ // underscore functions. Wrapped objects may be chained.
1185
+
1186
+ // Helper function to continue chaining intermediate results.
1187
+ var result = function(obj) {
1188
+ return this._chain ? _(obj).chain() : obj;
1189
+ };
1190
+
1191
+ // Add all of the Underscore functions to the wrapper object.
1192
+ _.mixin(_);
1193
+
1194
+ // Add all mutator Array functions to the wrapper.
1195
+ each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
1196
+ var method = ArrayProto[name];
1197
+ _.prototype[name] = function() {
1198
+ var obj = this._wrapped;
1199
+ method.apply(obj, arguments);
1200
+ if ((name == 'shift' || name == 'splice') && obj.length === 0) delete obj[0];
1201
+ return result.call(this, obj);
1202
+ };
1203
+ });
1204
+
1205
+ // Add all accessor Array functions to the wrapper.
1206
+ each(['concat', 'join', 'slice'], function(name) {
1207
+ var method = ArrayProto[name];
1208
+ _.prototype[name] = function() {
1209
+ return result.call(this, method.apply(this._wrapped, arguments));
1210
+ };
1211
+ });
1212
+
1213
+ _.extend(_.prototype, {
1214
+
1215
+ // Start chaining a wrapped Underscore object.
1216
+ chain: function() {
1217
+ this._chain = true;
1218
+ return this;
1219
+ },
1220
+
1221
+ // Extracts the result from a wrapped and chained object.
1222
+ value: function() {
1223
+ return this._wrapped;
1224
+ }
1225
+
1226
+ });
1227
+
1228
+ }).call(this);