marionette.modal 1.0.0.6 → 1.0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gruntfile.coffee +1 -1
- data/examples/vendor/backbone.js +189 -169
- data/examples/vendor/marionette.js +287 -161
- data/examples/vendor/underscore.js +210 -123
- data/lib/marionette.modal/version.rb +1 -1
- data/test/spec/backbone.marionette.modals.spec.js +46 -13
- data/test/src/backbone.marionette.modals.spec.coffee +13 -4
- metadata +1 -1
@@ -1,15 +1,14 @@
|
|
1
|
-
//
|
2
|
-
//
|
1
|
+
// Underscore.js 1.5.2
|
2
|
+
// http://underscorejs.org
|
3
|
+
// (c) 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
4
|
+
// Underscore may be freely distributed under the MIT license.
|
3
5
|
|
4
|
-
// > http://underscorejs.org
|
5
|
-
// > (c) 2009-2013 Jeremy Ashkenas, DocumentCloud Inc.
|
6
|
-
// > Underscore may be freely distributed under the MIT license.
|
7
|
-
|
8
|
-
// Baseline setup
|
9
|
-
// --------------
|
10
6
|
(function() {
|
11
7
|
|
12
|
-
//
|
8
|
+
// Baseline setup
|
9
|
+
// --------------
|
10
|
+
|
11
|
+
// Establish the root object, `window` in the browser, or `exports` on the server.
|
13
12
|
var root = this;
|
14
13
|
|
15
14
|
// Save the previous value of the `_` variable.
|
@@ -21,12 +20,18 @@
|
|
21
20
|
// Save bytes in the minified (but not gzipped) version:
|
22
21
|
var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype;
|
23
22
|
|
23
|
+
//use the faster Date.now if available.
|
24
|
+
var getTime = (Date.now || function() {
|
25
|
+
return new Date().getTime();
|
26
|
+
});
|
27
|
+
|
24
28
|
// Create quick reference variables for speed access to core prototypes.
|
25
|
-
var
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
29
|
+
var
|
30
|
+
push = ArrayProto.push,
|
31
|
+
slice = ArrayProto.slice,
|
32
|
+
concat = ArrayProto.concat,
|
33
|
+
toString = ObjProto.toString,
|
34
|
+
hasOwnProperty = ObjProto.hasOwnProperty;
|
30
35
|
|
31
36
|
// All **ECMAScript 5** native function implementations that we hope to use
|
32
37
|
// are declared here.
|
@@ -65,7 +70,7 @@
|
|
65
70
|
}
|
66
71
|
|
67
72
|
// Current version.
|
68
|
-
_.VERSION = '1.
|
73
|
+
_.VERSION = '1.5.2';
|
69
74
|
|
70
75
|
// Collection Functions
|
71
76
|
// --------------------
|
@@ -78,14 +83,13 @@
|
|
78
83
|
if (nativeForEach && obj.forEach === nativeForEach) {
|
79
84
|
obj.forEach(iterator, context);
|
80
85
|
} else if (obj.length === +obj.length) {
|
81
|
-
for (var i = 0,
|
86
|
+
for (var i = 0, length = obj.length; i < length; i++) {
|
82
87
|
if (iterator.call(context, obj[i], i, obj) === breaker) return;
|
83
88
|
}
|
84
89
|
} else {
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
}
|
90
|
+
var keys = _.keys(obj);
|
91
|
+
for (var i = 0, length = keys.length; i < length; i++) {
|
92
|
+
if (iterator.call(context, obj[keys[i]], keys[i], obj) === breaker) return;
|
89
93
|
}
|
90
94
|
}
|
91
95
|
};
|
@@ -97,7 +101,7 @@
|
|
97
101
|
if (obj == null) return results;
|
98
102
|
if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
|
99
103
|
each(obj, function(value, index, list) {
|
100
|
-
results
|
104
|
+
results.push(iterator.call(context, value, index, list));
|
101
105
|
});
|
102
106
|
return results;
|
103
107
|
};
|
@@ -172,7 +176,7 @@
|
|
172
176
|
if (obj == null) return results;
|
173
177
|
if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context);
|
174
178
|
each(obj, function(value, index, list) {
|
175
|
-
if (iterator.call(context, value, index, list)) results
|
179
|
+
if (iterator.call(context, value, index, list)) results.push(value);
|
176
180
|
});
|
177
181
|
return results;
|
178
182
|
};
|
@@ -233,13 +237,13 @@
|
|
233
237
|
|
234
238
|
// Convenience version of a common use case of `map`: fetching a property.
|
235
239
|
_.pluck = function(obj, key) {
|
236
|
-
return _.map(obj,
|
240
|
+
return _.map(obj, _.property(key));
|
237
241
|
};
|
238
242
|
|
239
243
|
// Convenience version of a common use case of `filter`: selecting only objects
|
240
244
|
// containing specific `key:value` pairs.
|
241
245
|
_.where = function(obj, attrs, first) {
|
242
|
-
if (_.isEmpty(attrs)) return first ?
|
246
|
+
if (_.isEmpty(attrs)) return first ? void 0 : [];
|
243
247
|
return _[first ? 'find' : 'filter'](obj, function(value) {
|
244
248
|
for (var key in attrs) {
|
245
249
|
if (attrs[key] !== value[key]) return false;
|
@@ -256,7 +260,7 @@
|
|
256
260
|
|
257
261
|
// Return the maximum element or (element-based computation).
|
258
262
|
// Can't optimize arrays of integers longer than 65,535 elements.
|
259
|
-
// See
|
263
|
+
// See [WebKit Bug 80797](https://bugs.webkit.org/show_bug.cgi?id=80797)
|
260
264
|
_.max = function(obj, iterator, context) {
|
261
265
|
if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) {
|
262
266
|
return Math.max.apply(Math, obj);
|
@@ -265,7 +269,7 @@
|
|
265
269
|
var result = {computed : -Infinity, value: -Infinity};
|
266
270
|
each(obj, function(value, index, list) {
|
267
271
|
var computed = iterator ? iterator.call(context, value, index, list) : value;
|
268
|
-
computed
|
272
|
+
computed > result.computed && (result = {value : value, computed : computed});
|
269
273
|
});
|
270
274
|
return result.value;
|
271
275
|
};
|
@@ -284,7 +288,8 @@
|
|
284
288
|
return result.value;
|
285
289
|
};
|
286
290
|
|
287
|
-
// Shuffle an array
|
291
|
+
// Shuffle an array, using the modern version of the
|
292
|
+
// [Fisher-Yates shuffle](http://en.wikipedia.org/wiki/Fisher–Yates_shuffle).
|
288
293
|
_.shuffle = function(obj) {
|
289
294
|
var rand;
|
290
295
|
var index = 0;
|
@@ -297,19 +302,32 @@
|
|
297
302
|
return shuffled;
|
298
303
|
};
|
299
304
|
|
305
|
+
// Sample **n** random values from a collection.
|
306
|
+
// If **n** is not specified, returns a single random element.
|
307
|
+
// The internal `guard` argument allows it to work with `map`.
|
308
|
+
_.sample = function(obj, n, guard) {
|
309
|
+
if (n == null || guard) {
|
310
|
+
if (obj.length !== +obj.length) obj = _.values(obj);
|
311
|
+
return obj[_.random(obj.length - 1)];
|
312
|
+
}
|
313
|
+
return _.shuffle(obj).slice(0, Math.max(0, n));
|
314
|
+
};
|
315
|
+
|
300
316
|
// An internal function to generate lookup iterators.
|
301
317
|
var lookupIterator = function(value) {
|
302
|
-
|
318
|
+
if (value == null) return _.identity;
|
319
|
+
if (_.isFunction(value)) return value;
|
320
|
+
return _.property(value);
|
303
321
|
};
|
304
322
|
|
305
323
|
// Sort the object's values by a criterion produced by an iterator.
|
306
|
-
_.sortBy = function(obj,
|
307
|
-
|
324
|
+
_.sortBy = function(obj, iterator, context) {
|
325
|
+
iterator = lookupIterator(iterator);
|
308
326
|
return _.pluck(_.map(obj, function(value, index, list) {
|
309
327
|
return {
|
310
|
-
value
|
311
|
-
index
|
312
|
-
criteria
|
328
|
+
value: value,
|
329
|
+
index: index,
|
330
|
+
criteria: iterator.call(context, value, index, list)
|
313
331
|
};
|
314
332
|
}).sort(function(left, right) {
|
315
333
|
var a = left.criteria;
|
@@ -318,43 +336,46 @@
|
|
318
336
|
if (a > b || a === void 0) return 1;
|
319
337
|
if (a < b || b === void 0) return -1;
|
320
338
|
}
|
321
|
-
return left.index
|
339
|
+
return left.index - right.index;
|
322
340
|
}), 'value');
|
323
341
|
};
|
324
342
|
|
325
343
|
// An internal function used for aggregate "group by" operations.
|
326
|
-
var group = function(
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
344
|
+
var group = function(behavior) {
|
345
|
+
return function(obj, iterator, context) {
|
346
|
+
var result = {};
|
347
|
+
iterator = lookupIterator(iterator);
|
348
|
+
each(obj, function(value, index) {
|
349
|
+
var key = iterator.call(context, value, index, obj);
|
350
|
+
behavior(result, key, value);
|
351
|
+
});
|
352
|
+
return result;
|
353
|
+
};
|
334
354
|
};
|
335
355
|
|
336
356
|
// Groups the object's values by a criterion. Pass either a string attribute
|
337
357
|
// to group by, or a function that returns the criterion.
|
338
|
-
_.groupBy = function(
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
358
|
+
_.groupBy = group(function(result, key, value) {
|
359
|
+
(_.has(result, key) ? result[key] : (result[key] = [])).push(value);
|
360
|
+
});
|
361
|
+
|
362
|
+
// Indexes the object's values by a criterion, similar to `groupBy`, but for
|
363
|
+
// when you know that your index values will be unique.
|
364
|
+
_.indexBy = group(function(result, key, value) {
|
365
|
+
result[key] = value;
|
366
|
+
});
|
343
367
|
|
344
368
|
// Counts instances of an object that group by a certain criterion. Pass
|
345
369
|
// either a string attribute to count by, or a function that returns the
|
346
370
|
// criterion.
|
347
|
-
_.countBy = function(
|
348
|
-
|
349
|
-
|
350
|
-
result[key]++;
|
351
|
-
});
|
352
|
-
};
|
371
|
+
_.countBy = group(function(result, key) {
|
372
|
+
_.has(result, key) ? result[key]++ : result[key] = 1;
|
373
|
+
});
|
353
374
|
|
354
375
|
// Use a comparator function to figure out the smallest index at which
|
355
376
|
// an object should be inserted so as to maintain order. Uses binary search.
|
356
377
|
_.sortedIndex = function(array, obj, iterator, context) {
|
357
|
-
iterator =
|
378
|
+
iterator = lookupIterator(iterator);
|
358
379
|
var value = iterator.call(context, obj);
|
359
380
|
var low = 0, high = array.length;
|
360
381
|
while (low < high) {
|
@@ -364,7 +385,7 @@
|
|
364
385
|
return low;
|
365
386
|
};
|
366
387
|
|
367
|
-
// Safely
|
388
|
+
// Safely create a real, live array from anything iterable.
|
368
389
|
_.toArray = function(obj) {
|
369
390
|
if (!obj) return [];
|
370
391
|
if (_.isArray(obj)) return slice.call(obj);
|
@@ -386,7 +407,9 @@
|
|
386
407
|
// allows it to work with `_.map`.
|
387
408
|
_.first = _.head = _.take = function(array, n, guard) {
|
388
409
|
if (array == null) return void 0;
|
389
|
-
|
410
|
+
if ((n == null) || guard) return array[0];
|
411
|
+
if (n < 0) return [];
|
412
|
+
return slice.call(array, 0, n);
|
390
413
|
};
|
391
414
|
|
392
415
|
// Returns everything but the last entry of the array. Especially useful on
|
@@ -401,11 +424,8 @@
|
|
401
424
|
// values in the array. The **guard** check allows it to work with `_.map`.
|
402
425
|
_.last = function(array, n, guard) {
|
403
426
|
if (array == null) return void 0;
|
404
|
-
if ((n
|
405
|
-
|
406
|
-
} else {
|
407
|
-
return array[array.length - 1];
|
408
|
-
}
|
427
|
+
if ((n == null) || guard) return array[array.length - 1];
|
428
|
+
return slice.call(array, Math.max(array.length - n, 0));
|
409
429
|
};
|
410
430
|
|
411
431
|
// Returns everything but the first entry of the array. Aliased as `tail` and `drop`.
|
@@ -423,8 +443,11 @@
|
|
423
443
|
|
424
444
|
// Internal implementation of a recursive `flatten` function.
|
425
445
|
var flatten = function(input, shallow, output) {
|
446
|
+
if (shallow && _.every(input, _.isArray)) {
|
447
|
+
return concat.apply(output, input);
|
448
|
+
}
|
426
449
|
each(input, function(value) {
|
427
|
-
if (_.isArray(value)) {
|
450
|
+
if (_.isArray(value) || _.isArguments(value)) {
|
428
451
|
shallow ? push.apply(output, value) : flatten(value, shallow, output);
|
429
452
|
} else {
|
430
453
|
output.push(value);
|
@@ -433,7 +456,7 @@
|
|
433
456
|
return output;
|
434
457
|
};
|
435
458
|
|
436
|
-
//
|
459
|
+
// Flatten out an array, either recursively (by default), or just one level.
|
437
460
|
_.flatten = function(array, shallow) {
|
438
461
|
return flatten(array, shallow, []);
|
439
462
|
};
|
@@ -467,7 +490,7 @@
|
|
467
490
|
// Produce an array that contains the union: each distinct element from all of
|
468
491
|
// the passed-in arrays.
|
469
492
|
_.union = function() {
|
470
|
-
return _.uniq(
|
493
|
+
return _.uniq(_.flatten(arguments, true));
|
471
494
|
};
|
472
495
|
|
473
496
|
// Produce an array that contains every item shared between all the
|
@@ -491,11 +514,10 @@
|
|
491
514
|
// Zip together multiple lists into a single array -- elements that share
|
492
515
|
// an index go together.
|
493
516
|
_.zip = function() {
|
494
|
-
var
|
495
|
-
var length = _.max(_.pluck(args, 'length'));
|
517
|
+
var length = _.max(_.pluck(arguments, "length").concat(0));
|
496
518
|
var results = new Array(length);
|
497
519
|
for (var i = 0; i < length; i++) {
|
498
|
-
results[i] = _.pluck(
|
520
|
+
results[i] = _.pluck(arguments, '' + i);
|
499
521
|
}
|
500
522
|
return results;
|
501
523
|
};
|
@@ -506,7 +528,7 @@
|
|
506
528
|
_.object = function(list, values) {
|
507
529
|
if (list == null) return {};
|
508
530
|
var result = {};
|
509
|
-
for (var i = 0,
|
531
|
+
for (var i = 0, length = list.length; i < length; i++) {
|
510
532
|
if (values) {
|
511
533
|
result[list[i]] = values[i];
|
512
534
|
} else {
|
@@ -524,17 +546,17 @@
|
|
524
546
|
// for **isSorted** to use binary search.
|
525
547
|
_.indexOf = function(array, item, isSorted) {
|
526
548
|
if (array == null) return -1;
|
527
|
-
var i = 0,
|
549
|
+
var i = 0, length = array.length;
|
528
550
|
if (isSorted) {
|
529
551
|
if (typeof isSorted == 'number') {
|
530
|
-
i = (isSorted < 0 ? Math.max(0,
|
552
|
+
i = (isSorted < 0 ? Math.max(0, length + isSorted) : isSorted);
|
531
553
|
} else {
|
532
554
|
i = _.sortedIndex(array, item);
|
533
555
|
return array[i] === item ? i : -1;
|
534
556
|
}
|
535
557
|
}
|
536
558
|
if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item, isSorted);
|
537
|
-
for (; i <
|
559
|
+
for (; i < length; i++) if (array[i] === item) return i;
|
538
560
|
return -1;
|
539
561
|
};
|
540
562
|
|
@@ -560,11 +582,11 @@
|
|
560
582
|
}
|
561
583
|
step = arguments[2] || 1;
|
562
584
|
|
563
|
-
var
|
585
|
+
var length = Math.max(Math.ceil((stop - start) / step), 0);
|
564
586
|
var idx = 0;
|
565
|
-
var range = new Array(
|
587
|
+
var range = new Array(length);
|
566
588
|
|
567
|
-
while(idx <
|
589
|
+
while(idx < length) {
|
568
590
|
range[idx++] = start;
|
569
591
|
start += step;
|
570
592
|
}
|
@@ -575,14 +597,25 @@
|
|
575
597
|
// Function (ahem) Functions
|
576
598
|
// ------------------
|
577
599
|
|
600
|
+
// Reusable constructor function for prototype setting.
|
601
|
+
var ctor = function(){};
|
602
|
+
|
578
603
|
// Create a function bound to a given object (assigning `this`, and arguments,
|
579
604
|
// optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if
|
580
605
|
// available.
|
581
606
|
_.bind = function(func, context) {
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
607
|
+
var args, bound;
|
608
|
+
if (nativeBind && func.bind === nativeBind) return nativeBind.apply(func, slice.call(arguments, 1));
|
609
|
+
if (!_.isFunction(func)) throw new TypeError;
|
610
|
+
args = slice.call(arguments, 2);
|
611
|
+
return bound = function() {
|
612
|
+
if (!(this instanceof bound)) return func.apply(context, args.concat(slice.call(arguments)));
|
613
|
+
ctor.prototype = func.prototype;
|
614
|
+
var self = new ctor;
|
615
|
+
ctor.prototype = null;
|
616
|
+
var result = func.apply(self, args.concat(slice.call(arguments)));
|
617
|
+
if (Object(result) === result) return result;
|
618
|
+
return self;
|
586
619
|
};
|
587
620
|
};
|
588
621
|
|
@@ -595,11 +628,12 @@
|
|
595
628
|
};
|
596
629
|
};
|
597
630
|
|
598
|
-
// Bind
|
599
|
-
//
|
631
|
+
// Bind a number of an object's methods to that object. Remaining arguments
|
632
|
+
// are the method names to be bound. Useful for ensuring that all callbacks
|
633
|
+
// defined on an object belong to it.
|
600
634
|
_.bindAll = function(obj) {
|
601
635
|
var funcs = slice.call(arguments, 1);
|
602
|
-
if (funcs.length === 0)
|
636
|
+
if (funcs.length === 0) throw new Error("bindAll must be passed function names");
|
603
637
|
each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); });
|
604
638
|
return obj;
|
605
639
|
};
|
@@ -628,17 +662,24 @@
|
|
628
662
|
};
|
629
663
|
|
630
664
|
// Returns a function, that, when invoked, will only be triggered at most once
|
631
|
-
// during a given window of time.
|
632
|
-
|
633
|
-
|
665
|
+
// during a given window of time. Normally, the throttled function will run
|
666
|
+
// as much as it can, without ever going more than once per `wait` duration;
|
667
|
+
// but if you'd like to disable the execution on the leading edge, pass
|
668
|
+
// `{leading: false}`. To disable execution on the trailing edge, ditto.
|
669
|
+
_.throttle = function(func, wait, options) {
|
670
|
+
var context, args, result;
|
671
|
+
var timeout = null;
|
634
672
|
var previous = 0;
|
673
|
+
options || (options = {});
|
635
674
|
var later = function() {
|
636
|
-
previous =
|
675
|
+
previous = options.leading === false ? 0 : getTime();
|
637
676
|
timeout = null;
|
638
677
|
result = func.apply(context, args);
|
678
|
+
context = args = null;
|
639
679
|
};
|
640
680
|
return function() {
|
641
|
-
var now =
|
681
|
+
var now = getTime();
|
682
|
+
if (!previous && options.leading === false) previous = now;
|
642
683
|
var remaining = wait - (now - previous);
|
643
684
|
context = this;
|
644
685
|
args = arguments;
|
@@ -647,7 +688,8 @@
|
|
647
688
|
timeout = null;
|
648
689
|
previous = now;
|
649
690
|
result = func.apply(context, args);
|
650
|
-
|
691
|
+
context = args = null;
|
692
|
+
} else if (!timeout && options.trailing !== false) {
|
651
693
|
timeout = setTimeout(later, remaining);
|
652
694
|
}
|
653
695
|
return result;
|
@@ -659,17 +701,32 @@
|
|
659
701
|
// N milliseconds. If `immediate` is passed, trigger the function on the
|
660
702
|
// leading edge, instead of the trailing.
|
661
703
|
_.debounce = function(func, wait, immediate) {
|
662
|
-
var timeout, result;
|
704
|
+
var timeout, args, context, timestamp, result;
|
663
705
|
return function() {
|
664
|
-
|
706
|
+
context = this;
|
707
|
+
args = arguments;
|
708
|
+
timestamp = getTime();
|
665
709
|
var later = function() {
|
666
|
-
|
667
|
-
if (
|
710
|
+
var last = getTime() - timestamp;
|
711
|
+
if (last < wait) {
|
712
|
+
timeout = setTimeout(later, wait - last);
|
713
|
+
} else {
|
714
|
+
timeout = null;
|
715
|
+
if (!immediate) {
|
716
|
+
result = func.apply(context, args);
|
717
|
+
context = args = null;
|
718
|
+
}
|
719
|
+
}
|
668
720
|
};
|
669
721
|
var callNow = immediate && !timeout;
|
670
|
-
|
671
|
-
|
672
|
-
|
722
|
+
if (!timeout) {
|
723
|
+
timeout = setTimeout(later, wait);
|
724
|
+
}
|
725
|
+
if (callNow) {
|
726
|
+
result = func.apply(context, args);
|
727
|
+
context = args = null;
|
728
|
+
}
|
729
|
+
|
673
730
|
return result;
|
674
731
|
};
|
675
732
|
};
|
@@ -691,11 +748,7 @@
|
|
691
748
|
// allowing you to adjust arguments, run code before and after, and
|
692
749
|
// conditionally execute the original function.
|
693
750
|
_.wrap = function(func, wrapper) {
|
694
|
-
return
|
695
|
-
var args = [func];
|
696
|
-
push.apply(args, arguments);
|
697
|
-
return wrapper.apply(this, args);
|
698
|
-
};
|
751
|
+
return _.partial(wrapper, func);
|
699
752
|
};
|
700
753
|
|
701
754
|
// Returns a function that is the composition of a list of functions, each
|
@@ -713,7 +766,6 @@
|
|
713
766
|
|
714
767
|
// Returns a function that will only be executed after being called N times.
|
715
768
|
_.after = function(times, func) {
|
716
|
-
if (times <= 0) return func();
|
717
769
|
return function() {
|
718
770
|
if (--times < 1) {
|
719
771
|
return func.apply(this, arguments);
|
@@ -729,28 +781,39 @@
|
|
729
781
|
_.keys = nativeKeys || function(obj) {
|
730
782
|
if (obj !== Object(obj)) throw new TypeError('Invalid object');
|
731
783
|
var keys = [];
|
732
|
-
for (var key in obj) if (_.has(obj, key)) keys
|
784
|
+
for (var key in obj) if (_.has(obj, key)) keys.push(key);
|
733
785
|
return keys;
|
734
786
|
};
|
735
787
|
|
736
788
|
// Retrieve the values of an object's properties.
|
737
789
|
_.values = function(obj) {
|
738
|
-
var
|
739
|
-
|
790
|
+
var keys = _.keys(obj);
|
791
|
+
var length = keys.length;
|
792
|
+
var values = new Array(length);
|
793
|
+
for (var i = 0; i < length; i++) {
|
794
|
+
values[i] = obj[keys[i]];
|
795
|
+
}
|
740
796
|
return values;
|
741
797
|
};
|
742
798
|
|
743
799
|
// Convert an object into a list of `[key, value]` pairs.
|
744
800
|
_.pairs = function(obj) {
|
745
|
-
var
|
746
|
-
|
801
|
+
var keys = _.keys(obj);
|
802
|
+
var length = keys.length;
|
803
|
+
var pairs = new Array(length);
|
804
|
+
for (var i = 0; i < length; i++) {
|
805
|
+
pairs[i] = [keys[i], obj[keys[i]]];
|
806
|
+
}
|
747
807
|
return pairs;
|
748
808
|
};
|
749
809
|
|
750
810
|
// Invert the keys and values of an object. The values must be serializable.
|
751
811
|
_.invert = function(obj) {
|
752
812
|
var result = {};
|
753
|
-
|
813
|
+
var keys = _.keys(obj);
|
814
|
+
for (var i = 0, length = keys.length; i < length; i++) {
|
815
|
+
result[obj[keys[i]]] = keys[i];
|
816
|
+
}
|
754
817
|
return result;
|
755
818
|
};
|
756
819
|
|
@@ -801,7 +864,7 @@
|
|
801
864
|
each(slice.call(arguments, 1), function(source) {
|
802
865
|
if (source) {
|
803
866
|
for (var prop in source) {
|
804
|
-
if (obj[prop]
|
867
|
+
if (obj[prop] === void 0) obj[prop] = source[prop];
|
805
868
|
}
|
806
869
|
}
|
807
870
|
});
|
@@ -825,7 +888,7 @@
|
|
825
888
|
// Internal recursive comparison function for `isEqual`.
|
826
889
|
var eq = function(a, b, aStack, bStack) {
|
827
890
|
// Identical objects are equal. `0 === -0`, but they aren't identical.
|
828
|
-
// See the Harmony `egal` proposal
|
891
|
+
// See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
|
829
892
|
if (a === b) return a !== 0 || 1 / a == 1 / b;
|
830
893
|
// A strict comparison is necessary because `null == undefined`.
|
831
894
|
if (a == null || b == null) return a === b;
|
@@ -867,6 +930,14 @@
|
|
867
930
|
// unique nested structures.
|
868
931
|
if (aStack[length] == a) return bStack[length] == b;
|
869
932
|
}
|
933
|
+
// Objects with different constructors are not equivalent, but `Object`s
|
934
|
+
// from different frames are.
|
935
|
+
var aCtor = a.constructor, bCtor = b.constructor;
|
936
|
+
if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) &&
|
937
|
+
_.isFunction(bCtor) && (bCtor instanceof bCtor))
|
938
|
+
&& ('constructor' in a && 'constructor' in b)) {
|
939
|
+
return false;
|
940
|
+
}
|
870
941
|
// Add the first object to the stack of traversed objects.
|
871
942
|
aStack.push(a);
|
872
943
|
bStack.push(b);
|
@@ -883,13 +954,6 @@
|
|
883
954
|
}
|
884
955
|
}
|
885
956
|
} else {
|
886
|
-
// Objects with different constructors are not equivalent, but `Object`s
|
887
|
-
// from different frames are.
|
888
|
-
var aCtor = a.constructor, bCtor = b.constructor;
|
889
|
-
if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) &&
|
890
|
-
_.isFunction(bCtor) && (bCtor instanceof bCtor))) {
|
891
|
-
return false;
|
892
|
-
}
|
893
957
|
// Deep compare objects.
|
894
958
|
for (var key in a) {
|
895
959
|
if (_.has(a, key)) {
|
@@ -1011,9 +1075,21 @@
|
|
1011
1075
|
return value;
|
1012
1076
|
};
|
1013
1077
|
|
1078
|
+
_.constant = function(value) {
|
1079
|
+
return function () {
|
1080
|
+
return value;
|
1081
|
+
};
|
1082
|
+
};
|
1083
|
+
|
1084
|
+
_.property = function(key) {
|
1085
|
+
return function(obj) {
|
1086
|
+
return obj[key];
|
1087
|
+
};
|
1088
|
+
};
|
1089
|
+
|
1014
1090
|
// Run a function **n** times.
|
1015
1091
|
_.times = function(n, iterator, context) {
|
1016
|
-
var accum = Array(n);
|
1092
|
+
var accum = Array(Math.max(0, n));
|
1017
1093
|
for (var i = 0; i < n; i++) accum[i] = iterator.call(context, i);
|
1018
1094
|
return accum;
|
1019
1095
|
};
|
@@ -1034,8 +1110,7 @@
|
|
1034
1110
|
'<': '<',
|
1035
1111
|
'>': '>',
|
1036
1112
|
'"': '"',
|
1037
|
-
"'": '''
|
1038
|
-
'/': '/'
|
1113
|
+
"'": '''
|
1039
1114
|
}
|
1040
1115
|
};
|
1041
1116
|
entityMap.unescape = _.invert(entityMap.escape);
|
@@ -1056,17 +1131,17 @@
|
|
1056
1131
|
};
|
1057
1132
|
});
|
1058
1133
|
|
1059
|
-
// If the value of the named property is a function then invoke it
|
1060
|
-
// otherwise, return it.
|
1134
|
+
// If the value of the named `property` is a function then invoke it with the
|
1135
|
+
// `object` as context; otherwise, return it.
|
1061
1136
|
_.result = function(object, property) {
|
1062
|
-
if (object == null) return
|
1137
|
+
if (object == null) return void 0;
|
1063
1138
|
var value = object[property];
|
1064
1139
|
return _.isFunction(value) ? value.call(object) : value;
|
1065
1140
|
};
|
1066
1141
|
|
1067
1142
|
// Add your own custom functions to the Underscore object.
|
1068
1143
|
_.mixin = function(obj) {
|
1069
|
-
each(_.functions(obj), function(name){
|
1144
|
+
each(_.functions(obj), function(name) {
|
1070
1145
|
var func = _[name] = obj[name];
|
1071
1146
|
_.prototype[name] = function() {
|
1072
1147
|
var args = [this._wrapped];
|
@@ -1224,4 +1299,16 @@
|
|
1224
1299
|
|
1225
1300
|
});
|
1226
1301
|
|
1227
|
-
|
1302
|
+
// AMD registration happens at the end for compatibility with AMD loaders
|
1303
|
+
// that may not enforce next-turn semantics on modules. Even though general
|
1304
|
+
// practice for AMD registration is to be anonymous, underscore registers
|
1305
|
+
// as a named module because, like jQuery, it is a base library that is
|
1306
|
+
// popular enough to be bundled in a third party lib, but not be part of
|
1307
|
+
// an AMD load request. Those cases could generate an error when an
|
1308
|
+
// anonymous define() is called outside of a loader request.
|
1309
|
+
if (typeof define === 'function' && define.amd) {
|
1310
|
+
define('underscore', [], function() {
|
1311
|
+
return _;
|
1312
|
+
});
|
1313
|
+
}
|
1314
|
+
}).call(this);
|