i0n_rails3_generators 0.2.17 → 0.2.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (20) hide show
  1. data/config/version.yml +1 -1
  2. data/lib/generators/i0n/layout/layout_generator.rb +23 -8
  3. data/lib/generators/i0n/layout/templates/app/views/layouts/application.haml +4 -4
  4. data/lib/generators/i0n/layout/templates/config/assets.yml +25 -0
  5. data/lib/generators/i0n/layout/templates/public/javascripts/application.js +8 -0
  6. data/lib/generators/i0n/layout/templates/public/javascripts/lib/client.js +12 -0
  7. data/lib/generators/i0n/layout/templates/public/javascripts/lib/create_html5_elements.js +6 -0
  8. data/lib/generators/i0n/layout/templates/public/javascripts/lib/rails.js +132 -0
  9. data/lib/generators/i0n/layout/templates/public/javascripts/vendor/IE9.js +6 -0
  10. data/lib/generators/i0n/layout/templates/public/javascripts/vendor/backbone.0.3.3.js +1012 -0
  11. data/lib/generators/i0n/layout/templates/public/javascripts/vendor/jquery.1.5.2.js +8374 -0
  12. data/lib/generators/i0n/layout/templates/public/javascripts/vendor/jquery.form.2.4.9.js +785 -0
  13. data/lib/generators/i0n/layout/templates/public/javascripts/vendor/jquery.remotipart.js +52 -0
  14. data/lib/generators/i0n/layout/templates/public/javascripts/vendor/jquery.uploadProgress.js +116 -0
  15. data/lib/generators/i0n/layout/templates/public/javascripts/vendor/json2.js +481 -0
  16. data/lib/generators/i0n/layout/templates/public/javascripts/vendor/underscore.1.1.5.js +796 -0
  17. data/lib/generators/i0n/layout/templates/public/javascripts/views/index.js +0 -0
  18. data/lib/generators/i0n/layout/templates/public/javascripts/views/new.js +0 -0
  19. data/lib/generators/i0n/layout/templates/public/javascripts/views/show.js +0 -0
  20. metadata +18 -2
@@ -0,0 +1,796 @@
1
+ // Underscore.js 1.1.5
2
+ // (c) 2011 Jeremy Ashkenas, DocumentCloud Inc.
3
+ // Underscore is freely distributable under the MIT license.
4
+ // Portions of Underscore are inspired or borrowed from Prototype,
5
+ // Oliver Steele's Functional, and John Resig's Micro-Templating.
6
+ // For all details and documentation:
7
+ // http://documentcloud.github.com/underscore
8
+
9
+ (function() {
10
+
11
+ // Baseline setup
12
+ // --------------
13
+
14
+ // Establish the root object, `window` in the browser, or `global` on the server.
15
+ var root = this;
16
+
17
+ // Save the previous value of the `_` variable.
18
+ var previousUnderscore = root._;
19
+
20
+ // Establish the object that gets returned to break out of a loop iteration.
21
+ var breaker = {};
22
+
23
+ // Save bytes in the minified (but not gzipped) version:
24
+ var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
25
+
26
+ // Create quick reference variables for speed access to core prototypes.
27
+ var slice = ArrayProto.slice,
28
+ unshift = ArrayProto.unshift,
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) { return new wrapper(obj); };
50
+
51
+ // Export the Underscore object for **CommonJS**, with backwards-compatibility
52
+ // for the old `require()` API. If we're not in CommonJS, add `_` to the
53
+ // global object.
54
+ if (typeof module !== 'undefined' && module.exports) {
55
+ module.exports = _;
56
+ _._ = _;
57
+ } else {
58
+ root._ = _;
59
+ }
60
+
61
+ // Current version.
62
+ _.VERSION = '1.1.5';
63
+
64
+ // Collection Functions
65
+ // --------------------
66
+
67
+ // The cornerstone, an `each` implementation, aka `forEach`.
68
+ // Handles objects implementing `forEach`, arrays, and raw objects.
69
+ // Delegates to **ECMAScript 5**'s native `forEach` if available.
70
+ var each = _.each = _.forEach = function(obj, iterator, context) {
71
+ if (obj == null) return;
72
+ if (nativeForEach && obj.forEach === nativeForEach) {
73
+ obj.forEach(iterator, context);
74
+ } else if (_.isNumber(obj.length)) {
75
+ for (var i = 0, l = obj.length; i < l; i++) {
76
+ if (iterator.call(context, obj[i], i, obj) === breaker) return;
77
+ }
78
+ } else {
79
+ for (var key in obj) {
80
+ if (hasOwnProperty.call(obj, key)) {
81
+ if (iterator.call(context, obj[key], key, obj) === breaker) return;
82
+ }
83
+ }
84
+ }
85
+ };
86
+
87
+ // Return the results of applying the iterator to each element.
88
+ // Delegates to **ECMAScript 5**'s native `map` if available.
89
+ _.map = function(obj, iterator, context) {
90
+ var results = [];
91
+ if (obj == null) return results;
92
+ if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
93
+ each(obj, function(value, index, list) {
94
+ results[results.length] = iterator.call(context, value, index, list);
95
+ });
96
+ return results;
97
+ };
98
+
99
+ // **Reduce** builds up a single result from a list of values, aka `inject`,
100
+ // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available.
101
+ _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) {
102
+ var initial = memo !== void 0;
103
+ if (obj == null) obj = [];
104
+ if (nativeReduce && obj.reduce === nativeReduce) {
105
+ if (context) iterator = _.bind(iterator, context);
106
+ return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator);
107
+ }
108
+ each(obj, function(value, index, list) {
109
+ if (!initial && index === 0) {
110
+ memo = value;
111
+ initial = true;
112
+ } else {
113
+ memo = iterator.call(context, memo, value, index, list);
114
+ }
115
+ });
116
+ if (!initial) throw new TypeError("Reduce of empty array with no initial value");
117
+ return memo;
118
+ };
119
+
120
+ // The right-associative version of reduce, also known as `foldr`.
121
+ // Delegates to **ECMAScript 5**'s native `reduceRight` if available.
122
+ _.reduceRight = _.foldr = function(obj, iterator, memo, context) {
123
+ if (obj == null) obj = [];
124
+ if (nativeReduceRight && obj.reduceRight === nativeReduceRight) {
125
+ if (context) iterator = _.bind(iterator, context);
126
+ return memo !== void 0 ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator);
127
+ }
128
+ var reversed = (_.isArray(obj) ? obj.slice() : _.toArray(obj)).reverse();
129
+ return _.reduce(reversed, iterator, memo, context);
130
+ };
131
+
132
+ // Return the first value which passes a truth test. Aliased as `detect`.
133
+ _.find = _.detect = function(obj, iterator, context) {
134
+ var result;
135
+ any(obj, function(value, index, list) {
136
+ if (iterator.call(context, value, index, list)) {
137
+ result = value;
138
+ return true;
139
+ }
140
+ });
141
+ return result;
142
+ };
143
+
144
+ // Return all the elements that pass a truth test.
145
+ // Delegates to **ECMAScript 5**'s native `filter` if available.
146
+ // Aliased as `select`.
147
+ _.filter = _.select = function(obj, iterator, context) {
148
+ var results = [];
149
+ if (obj == null) return results;
150
+ if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context);
151
+ each(obj, function(value, index, list) {
152
+ if (iterator.call(context, value, index, list)) results[results.length] = value;
153
+ });
154
+ return results;
155
+ };
156
+
157
+ // Return all the elements for which a truth test fails.
158
+ _.reject = function(obj, iterator, context) {
159
+ var results = [];
160
+ if (obj == null) return results;
161
+ each(obj, function(value, index, list) {
162
+ if (!iterator.call(context, value, index, list)) results[results.length] = value;
163
+ });
164
+ return results;
165
+ };
166
+
167
+ // Determine whether all of the elements match a truth test.
168
+ // Delegates to **ECMAScript 5**'s native `every` if available.
169
+ // Aliased as `all`.
170
+ _.every = _.all = function(obj, iterator, context) {
171
+ iterator = iterator || _.identity;
172
+ var result = true;
173
+ if (obj == null) return result;
174
+ if (nativeEvery && obj.every === nativeEvery) return obj.every(iterator, context);
175
+ each(obj, function(value, index, list) {
176
+ if (!(result = result && iterator.call(context, value, index, list))) return breaker;
177
+ });
178
+ return result;
179
+ };
180
+
181
+ // Determine if at least one element in the object matches a truth test.
182
+ // Delegates to **ECMAScript 5**'s native `some` if available.
183
+ // Aliased as `any`.
184
+ var any = _.some = _.any = function(obj, iterator, context) {
185
+ iterator = iterator || _.identity;
186
+ var result = false;
187
+ if (obj == null) return result;
188
+ if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context);
189
+ each(obj, function(value, index, list) {
190
+ if (result = iterator.call(context, value, index, list)) return breaker;
191
+ });
192
+ return result;
193
+ };
194
+
195
+ // Determine if a given value is included in the array or object using `===`.
196
+ // Aliased as `contains`.
197
+ _.include = _.contains = function(obj, target) {
198
+ var found = false;
199
+ if (obj == null) return found;
200
+ if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1;
201
+ any(obj, function(value) {
202
+ if (found = value === target) return true;
203
+ });
204
+ return found;
205
+ };
206
+
207
+ // Invoke a method (with arguments) on every item in a collection.
208
+ _.invoke = function(obj, method) {
209
+ var args = slice.call(arguments, 2);
210
+ return _.map(obj, function(value) {
211
+ return (method ? value[method] : value).apply(value, args);
212
+ });
213
+ };
214
+
215
+ // Convenience version of a common use case of `map`: fetching a property.
216
+ _.pluck = function(obj, key) {
217
+ return _.map(obj, function(value){ return value[key]; });
218
+ };
219
+
220
+ // Return the maximum element or (element-based computation).
221
+ _.max = function(obj, iterator, context) {
222
+ if (!iterator && _.isArray(obj)) return Math.max.apply(Math, obj);
223
+ var result = {computed : -Infinity};
224
+ each(obj, function(value, index, list) {
225
+ var computed = iterator ? iterator.call(context, value, index, list) : value;
226
+ computed >= result.computed && (result = {value : value, computed : computed});
227
+ });
228
+ return result.value;
229
+ };
230
+
231
+ // Return the minimum element (or element-based computation).
232
+ _.min = function(obj, iterator, context) {
233
+ if (!iterator && _.isArray(obj)) return Math.min.apply(Math, obj);
234
+ var result = {computed : Infinity};
235
+ each(obj, function(value, index, list) {
236
+ var computed = iterator ? iterator.call(context, value, index, list) : value;
237
+ computed < result.computed && (result = {value : value, computed : computed});
238
+ });
239
+ return result.value;
240
+ };
241
+
242
+ // Sort the object's values by a criterion produced by an iterator.
243
+ _.sortBy = function(obj, iterator, context) {
244
+ return _.pluck(_.map(obj, function(value, index, list) {
245
+ return {
246
+ value : value,
247
+ criteria : iterator.call(context, value, index, list)
248
+ };
249
+ }).sort(function(left, right) {
250
+ var a = left.criteria, b = right.criteria;
251
+ return a < b ? -1 : a > b ? 1 : 0;
252
+ }), 'value');
253
+ };
254
+
255
+ // Use a comparator function to figure out at what index an object should
256
+ // be inserted so as to maintain order. Uses binary search.
257
+ _.sortedIndex = function(array, obj, iterator) {
258
+ iterator = iterator || _.identity;
259
+ var low = 0, high = array.length;
260
+ while (low < high) {
261
+ var mid = (low + high) >> 1;
262
+ iterator(array[mid]) < iterator(obj) ? low = mid + 1 : high = mid;
263
+ }
264
+ return low;
265
+ };
266
+
267
+ // Safely convert anything iterable into a real, live array.
268
+ _.toArray = function(iterable) {
269
+ if (!iterable) return [];
270
+ if (iterable.toArray) return iterable.toArray();
271
+ if (_.isArray(iterable)) return iterable;
272
+ if (_.isArguments(iterable)) return slice.call(iterable);
273
+ return _.values(iterable);
274
+ };
275
+
276
+ // Return the number of elements in an object.
277
+ _.size = function(obj) {
278
+ return _.toArray(obj).length;
279
+ };
280
+
281
+ // Array Functions
282
+ // ---------------
283
+
284
+ // Get the first element of an array. Passing **n** will return the first N
285
+ // values in the array. Aliased as `head`. The **guard** check allows it to work
286
+ // with `_.map`.
287
+ _.first = _.head = function(array, n, guard) {
288
+ return (n != null) && !guard ? slice.call(array, 0, n) : array[0];
289
+ };
290
+
291
+ // Returns everything but the first entry of the array. Aliased as `tail`.
292
+ // Especially useful on the arguments object. Passing an **index** will return
293
+ // the rest of the values in the array from that index onward. The **guard**
294
+ // check allows it to work with `_.map`.
295
+ _.rest = _.tail = function(array, index, guard) {
296
+ return slice.call(array, (index == null) || guard ? 1 : index);
297
+ };
298
+
299
+ // Get the last element of an array.
300
+ _.last = function(array) {
301
+ return array[array.length - 1];
302
+ };
303
+
304
+ // Trim out all falsy values from an array.
305
+ _.compact = function(array) {
306
+ return _.filter(array, function(value){ return !!value; });
307
+ };
308
+
309
+ // Return a completely flattened version of an array.
310
+ _.flatten = function(array) {
311
+ return _.reduce(array, function(memo, value) {
312
+ if (_.isArray(value)) return memo.concat(_.flatten(value));
313
+ memo[memo.length] = value;
314
+ return memo;
315
+ }, []);
316
+ };
317
+
318
+ // Return a version of the array that does not contain the specified value(s).
319
+ _.without = function(array) {
320
+ var values = slice.call(arguments, 1);
321
+ return _.filter(array, function(value){ return !_.include(values, value); });
322
+ };
323
+
324
+ // Produce a duplicate-free version of the array. If the array has already
325
+ // been sorted, you have the option of using a faster algorithm.
326
+ // Aliased as `unique`.
327
+ _.uniq = _.unique = function(array, isSorted) {
328
+ return _.reduce(array, function(memo, el, i) {
329
+ if (0 == i || (isSorted === true ? _.last(memo) != el : !_.include(memo, el))) memo[memo.length] = el;
330
+ return memo;
331
+ }, []);
332
+ };
333
+
334
+ // Produce an array that contains every item shared between all the
335
+ // passed-in arrays.
336
+ _.intersect = function(array) {
337
+ var rest = slice.call(arguments, 1);
338
+ return _.filter(_.uniq(array), function(item) {
339
+ return _.every(rest, function(other) {
340
+ return _.indexOf(other, item) >= 0;
341
+ });
342
+ });
343
+ };
344
+
345
+ // Zip together multiple lists into a single array -- elements that share
346
+ // an index go together.
347
+ _.zip = function() {
348
+ var args = slice.call(arguments);
349
+ var length = _.max(_.pluck(args, 'length'));
350
+ var results = new Array(length);
351
+ for (var i = 0; i < length; i++) results[i] = _.pluck(args, "" + i);
352
+ return results;
353
+ };
354
+
355
+ // If the browser doesn't supply us with indexOf (I'm looking at you, **MSIE**),
356
+ // we need this function. Return the position of the first occurrence of an
357
+ // item in an array, or -1 if the item is not included in the array.
358
+ // Delegates to **ECMAScript 5**'s native `indexOf` if available.
359
+ // If the array is large and already in sort order, pass `true`
360
+ // for **isSorted** to use binary search.
361
+ _.indexOf = function(array, item, isSorted) {
362
+ if (array == null) return -1;
363
+ var i, l;
364
+ if (isSorted) {
365
+ i = _.sortedIndex(array, item);
366
+ return array[i] === item ? i : -1;
367
+ }
368
+ if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item);
369
+ for (i = 0, l = array.length; i < l; i++) if (array[i] === item) return i;
370
+ return -1;
371
+ };
372
+
373
+
374
+ // Delegates to **ECMAScript 5**'s native `lastIndexOf` if available.
375
+ _.lastIndexOf = function(array, item) {
376
+ if (array == null) return -1;
377
+ if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) return array.lastIndexOf(item);
378
+ var i = array.length;
379
+ while (i--) if (array[i] === item) return i;
380
+ return -1;
381
+ };
382
+
383
+ // Generate an integer Array containing an arithmetic progression. A port of
384
+ // the native Python `range()` function. See
385
+ // [the Python documentation](http://docs.python.org/library/functions.html#range).
386
+ _.range = function(start, stop, step) {
387
+ if (arguments.length <= 1) {
388
+ stop = start || 0;
389
+ start = 0;
390
+ }
391
+ step = arguments[2] || 1;
392
+
393
+ var len = Math.max(Math.ceil((stop - start) / step), 0);
394
+ var idx = 0;
395
+ var range = new Array(len);
396
+
397
+ while(idx < len) {
398
+ range[idx++] = start;
399
+ start += step;
400
+ }
401
+
402
+ return range;
403
+ };
404
+
405
+ // Function (ahem) Functions
406
+ // ------------------
407
+
408
+ // Create a function bound to a given object (assigning `this`, and arguments,
409
+ // optionally). Binding with arguments is also known as `curry`.
410
+ // Delegates to **ECMAScript 5**'s native `Function.bind` if available.
411
+ _.bind = function(func, obj) {
412
+ if (nativeBind && func.bind === nativeBind) return func.bind.apply(func, slice.call(arguments, 1));
413
+ var args = slice.call(arguments, 2);
414
+ return function() {
415
+ return func.apply(obj, args.concat(slice.call(arguments)));
416
+ };
417
+ };
418
+
419
+ // Bind all of an object's methods to that object. Useful for ensuring that
420
+ // all callbacks defined on an object belong to it.
421
+ _.bindAll = function(obj) {
422
+ var funcs = slice.call(arguments, 1);
423
+ if (funcs.length == 0) funcs = _.functions(obj);
424
+ each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); });
425
+ return obj;
426
+ };
427
+
428
+ // Memoize an expensive function by storing its results.
429
+ _.memoize = function(func, hasher) {
430
+ var memo = {};
431
+ hasher = hasher || _.identity;
432
+ return function() {
433
+ var key = hasher.apply(this, arguments);
434
+ return hasOwnProperty.call(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments));
435
+ };
436
+ };
437
+
438
+ // Delays a function for the given number of milliseconds, and then calls
439
+ // it with the arguments supplied.
440
+ _.delay = function(func, wait) {
441
+ var args = slice.call(arguments, 2);
442
+ return setTimeout(function(){ return func.apply(func, args); }, wait);
443
+ };
444
+
445
+ // Defers a function, scheduling it to run after the current call stack has
446
+ // cleared.
447
+ _.defer = function(func) {
448
+ return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1)));
449
+ };
450
+
451
+ // Internal function used to implement `_.throttle` and `_.debounce`.
452
+ var limit = function(func, wait, debounce) {
453
+ var timeout;
454
+ return function() {
455
+ var context = this, args = arguments;
456
+ var throttler = function() {
457
+ timeout = null;
458
+ func.apply(context, args);
459
+ };
460
+ if (debounce) clearTimeout(timeout);
461
+ if (debounce || !timeout) timeout = setTimeout(throttler, wait);
462
+ };
463
+ };
464
+
465
+ // Returns a function, that, when invoked, will only be triggered at most once
466
+ // during a given window of time.
467
+ _.throttle = function(func, wait) {
468
+ return limit(func, wait, false);
469
+ };
470
+
471
+ // Returns a function, that, as long as it continues to be invoked, will not
472
+ // be triggered. The function will be called after it stops being called for
473
+ // N milliseconds.
474
+ _.debounce = function(func, wait) {
475
+ return limit(func, wait, true);
476
+ };
477
+
478
+ // Returns a function that will be executed at most one time, no matter how
479
+ // often you call it. Useful for lazy initialization.
480
+ _.once = function(func) {
481
+ var ran = false, memo;
482
+ return function() {
483
+ if (ran) return memo;
484
+ ran = true;
485
+ return memo = func.apply(this, arguments);
486
+ };
487
+ };
488
+
489
+ // Returns the first function passed as an argument to the second,
490
+ // allowing you to adjust arguments, run code before and after, and
491
+ // conditionally execute the original function.
492
+ _.wrap = function(func, wrapper) {
493
+ return function() {
494
+ var args = [func].concat(slice.call(arguments));
495
+ return wrapper.apply(this, args);
496
+ };
497
+ };
498
+
499
+ // Returns a function that is the composition of a list of functions, each
500
+ // consuming the return value of the function that follows.
501
+ _.compose = function() {
502
+ var funcs = slice.call(arguments);
503
+ return function() {
504
+ var args = slice.call(arguments);
505
+ for (var i=funcs.length-1; i >= 0; i--) {
506
+ args = [funcs[i].apply(this, args)];
507
+ }
508
+ return args[0];
509
+ };
510
+ };
511
+
512
+ // Object Functions
513
+ // ----------------
514
+
515
+ // Retrieve the names of an object's properties.
516
+ // Delegates to **ECMAScript 5**'s native `Object.keys`
517
+ _.keys = nativeKeys || function(obj) {
518
+ if (obj !== Object(obj)) throw new TypeError('Invalid object');
519
+ var keys = [];
520
+ for (var key in obj) if (hasOwnProperty.call(obj, key)) keys[keys.length] = key;
521
+ return keys;
522
+ };
523
+
524
+ // Retrieve the values of an object's properties.
525
+ _.values = function(obj) {
526
+ return _.map(obj, _.identity);
527
+ };
528
+
529
+ // Return a sorted list of the function names available on the object.
530
+ // Aliased as `methods`
531
+ _.functions = _.methods = function(obj) {
532
+ return _.filter(_.keys(obj), function(key){ return _.isFunction(obj[key]); }).sort();
533
+ };
534
+
535
+ // Extend a given object with all the properties in passed-in object(s).
536
+ _.extend = function(obj) {
537
+ each(slice.call(arguments, 1), function(source) {
538
+ for (var prop in source) obj[prop] = source[prop];
539
+ });
540
+ return obj;
541
+ };
542
+
543
+ // Fill in a given object with default properties.
544
+ _.defaults = function(obj) {
545
+ each(slice.call(arguments, 1), function(source) {
546
+ for (var prop in source) if (obj[prop] == null) obj[prop] = source[prop];
547
+ });
548
+ return obj;
549
+ };
550
+
551
+ // Create a (shallow-cloned) duplicate of an object.
552
+ _.clone = function(obj) {
553
+ return _.isArray(obj) ? obj.slice() : _.extend({}, obj);
554
+ };
555
+
556
+ // Invokes interceptor with the obj, and then returns obj.
557
+ // The primary purpose of this method is to "tap into" a method chain, in
558
+ // order to perform operations on intermediate results within the chain.
559
+ _.tap = function(obj, interceptor) {
560
+ interceptor(obj);
561
+ return obj;
562
+ };
563
+
564
+ // Perform a deep comparison to check if two objects are equal.
565
+ _.isEqual = function(a, b) {
566
+ // Check object identity.
567
+ if (a === b) return true;
568
+ // Different types?
569
+ var atype = typeof(a), btype = typeof(b);
570
+ if (atype != btype) return false;
571
+ // Basic equality test (watch out for coercions).
572
+ if (a == b) return true;
573
+ // One is falsy and the other truthy.
574
+ if ((!a && b) || (a && !b)) return false;
575
+ // Unwrap any wrapped objects.
576
+ if (a._chain) a = a._wrapped;
577
+ if (b._chain) b = b._wrapped;
578
+ // One of them implements an isEqual()?
579
+ if (a.isEqual) return a.isEqual(b);
580
+ // Check dates' integer values.
581
+ if (_.isDate(a) && _.isDate(b)) return a.getTime() === b.getTime();
582
+ // Both are NaN?
583
+ if (_.isNaN(a) && _.isNaN(b)) return false;
584
+ // Compare regular expressions.
585
+ if (_.isRegExp(a) && _.isRegExp(b))
586
+ return a.source === b.source &&
587
+ a.global === b.global &&
588
+ a.ignoreCase === b.ignoreCase &&
589
+ a.multiline === b.multiline;
590
+ // If a is not an object by this point, we can't handle it.
591
+ if (atype !== 'object') return false;
592
+ // Check for different array lengths before comparing contents.
593
+ if (a.length && (a.length !== b.length)) return false;
594
+ // Nothing else worked, deep compare the contents.
595
+ var aKeys = _.keys(a), bKeys = _.keys(b);
596
+ // Different object sizes?
597
+ if (aKeys.length != bKeys.length) return false;
598
+ // Recursive comparison of contents.
599
+ for (var key in a) if (!(key in b) || !_.isEqual(a[key], b[key])) return false;
600
+ return true;
601
+ };
602
+
603
+ // Is a given array or object empty?
604
+ _.isEmpty = function(obj) {
605
+ if (_.isArray(obj) || _.isString(obj)) return obj.length === 0;
606
+ for (var key in obj) if (hasOwnProperty.call(obj, key)) return false;
607
+ return true;
608
+ };
609
+
610
+ // Is a given value a DOM element?
611
+ _.isElement = function(obj) {
612
+ return !!(obj && obj.nodeType == 1);
613
+ };
614
+
615
+ // Is a given value an array?
616
+ // Delegates to ECMA5's native Array.isArray
617
+ _.isArray = nativeIsArray || function(obj) {
618
+ return toString.call(obj) === '[object Array]';
619
+ };
620
+
621
+ // Is a given variable an arguments object?
622
+ _.isArguments = function(obj) {
623
+ return !!(obj && hasOwnProperty.call(obj, 'callee'));
624
+ };
625
+
626
+ // Is a given value a function?
627
+ _.isFunction = function(obj) {
628
+ return !!(obj && obj.constructor && obj.call && obj.apply);
629
+ };
630
+
631
+ // Is a given value a string?
632
+ _.isString = function(obj) {
633
+ return !!(obj === '' || (obj && obj.charCodeAt && obj.substr));
634
+ };
635
+
636
+ // Is a given value a number?
637
+ _.isNumber = function(obj) {
638
+ return !!(obj === 0 || (obj && obj.toExponential && obj.toFixed));
639
+ };
640
+
641
+ // Is the given value `NaN`? `NaN` happens to be the only value in JavaScript
642
+ // that does not equal itself.
643
+ _.isNaN = function(obj) {
644
+ return obj !== obj;
645
+ };
646
+
647
+ // Is a given value a boolean?
648
+ _.isBoolean = function(obj) {
649
+ return obj === true || obj === false;
650
+ };
651
+
652
+ // Is a given value a date?
653
+ _.isDate = function(obj) {
654
+ return !!(obj && obj.getTimezoneOffset && obj.setUTCFullYear);
655
+ };
656
+
657
+ // Is the given value a regular expression?
658
+ _.isRegExp = function(obj) {
659
+ return !!(obj && obj.test && obj.exec && (obj.ignoreCase || obj.ignoreCase === false));
660
+ };
661
+
662
+ // Is a given value equal to null?
663
+ _.isNull = function(obj) {
664
+ return obj === null;
665
+ };
666
+
667
+ // Is a given variable undefined?
668
+ _.isUndefined = function(obj) {
669
+ return obj === void 0;
670
+ };
671
+
672
+ // Utility Functions
673
+ // -----------------
674
+
675
+ // Run Underscore.js in *noConflict* mode, returning the `_` variable to its
676
+ // previous owner. Returns a reference to the Underscore object.
677
+ _.noConflict = function() {
678
+ root._ = previousUnderscore;
679
+ return this;
680
+ };
681
+
682
+ // Keep the identity function around for default iterators.
683
+ _.identity = function(value) {
684
+ return value;
685
+ };
686
+
687
+ // Run a function **n** times.
688
+ _.times = function (n, iterator, context) {
689
+ for (var i = 0; i < n; i++) iterator.call(context, i);
690
+ };
691
+
692
+ // Add your own custom functions to the Underscore object, ensuring that
693
+ // they're correctly added to the OOP wrapper as well.
694
+ _.mixin = function(obj) {
695
+ each(_.functions(obj), function(name){
696
+ addToWrapper(name, _[name] = obj[name]);
697
+ });
698
+ };
699
+
700
+ // Generate a unique integer id (unique within the entire client session).
701
+ // Useful for temporary DOM ids.
702
+ var idCounter = 0;
703
+ _.uniqueId = function(prefix) {
704
+ var id = idCounter++;
705
+ return prefix ? prefix + id : id;
706
+ };
707
+
708
+ // By default, Underscore uses ERB-style template delimiters, change the
709
+ // following template settings to use alternative delimiters.
710
+ _.templateSettings = {
711
+ evaluate : /<%([\s\S]+?)%>/g,
712
+ interpolate : /<%=([\s\S]+?)%>/g
713
+ };
714
+
715
+ // JavaScript micro-templating, similar to John Resig's implementation.
716
+ // Underscore templating handles arbitrary delimiters, preserves whitespace,
717
+ // and correctly escapes quotes within interpolated code.
718
+ _.template = function(str, data) {
719
+ var c = _.templateSettings;
720
+ var tmpl = 'var __p=[],print=function(){__p.push.apply(__p,arguments);};' +
721
+ 'with(obj||{}){__p.push(\'' +
722
+ str.replace(/\\/g, '\\\\')
723
+ .replace(/'/g, "\\'")
724
+ .replace(c.interpolate, function(match, code) {
725
+ return "'," + code.replace(/\\'/g, "'") + ",'";
726
+ })
727
+ .replace(c.evaluate || null, function(match, code) {
728
+ return "');" + code.replace(/\\'/g, "'")
729
+ .replace(/[\r\n\t]/g, ' ') + "__p.push('";
730
+ })
731
+ .replace(/\r/g, '\\r')
732
+ .replace(/\n/g, '\\n')
733
+ .replace(/\t/g, '\\t')
734
+ + "');}return __p.join('');";
735
+ var func = new Function('obj', tmpl);
736
+ return data ? func(data) : func;
737
+ };
738
+
739
+ // The OOP Wrapper
740
+ // ---------------
741
+
742
+ // If Underscore is called as a function, it returns a wrapped object that
743
+ // can be used OO-style. This wrapper holds altered versions of all the
744
+ // underscore functions. Wrapped objects may be chained.
745
+ var wrapper = function(obj) { this._wrapped = obj; };
746
+
747
+ // Expose `wrapper.prototype` as `_.prototype`
748
+ _.prototype = wrapper.prototype;
749
+
750
+ // Helper function to continue chaining intermediate results.
751
+ var result = function(obj, chain) {
752
+ return chain ? _(obj).chain() : obj;
753
+ };
754
+
755
+ // A method to easily add functions to the OOP wrapper.
756
+ var addToWrapper = function(name, func) {
757
+ wrapper.prototype[name] = function() {
758
+ var args = slice.call(arguments);
759
+ unshift.call(args, this._wrapped);
760
+ return result(func.apply(_, args), this._chain);
761
+ };
762
+ };
763
+
764
+ // Add all of the Underscore functions to the wrapper object.
765
+ _.mixin(_);
766
+
767
+ // Add all mutator Array functions to the wrapper.
768
+ each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) {
769
+ var method = ArrayProto[name];
770
+ wrapper.prototype[name] = function() {
771
+ method.apply(this._wrapped, arguments);
772
+ return result(this._wrapped, this._chain);
773
+ };
774
+ });
775
+
776
+ // Add all accessor Array functions to the wrapper.
777
+ each(['concat', 'join', 'slice'], function(name) {
778
+ var method = ArrayProto[name];
779
+ wrapper.prototype[name] = function() {
780
+ return result(method.apply(this._wrapped, arguments), this._chain);
781
+ };
782
+ });
783
+
784
+ // Start chaining a wrapped Underscore object.
785
+ wrapper.prototype.chain = function() {
786
+ this._chain = true;
787
+ return this;
788
+ };
789
+
790
+ // Extracts the result from a wrapped and chained object.
791
+ wrapper.prototype.value = function() {
792
+ return this._wrapped;
793
+ };
794
+
795
+ })();
796
+