Skip to content

Commit d076fd4

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents dd3abbb + fd671ab commit d076fd4

File tree

9 files changed

+1276
-1104
lines changed

9 files changed

+1276
-1104
lines changed

src/prototype/dom/dom.js

Lines changed: 603 additions & 587 deletions
Large diffs are not rendered by default.

src/prototype/dom/layout.js

Lines changed: 340 additions & 306 deletions
Large diffs are not rendered by default.

src/prototype/lang/array.js

Lines changed: 60 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
11
/** section: Language, related to: Array
22
* $A(iterable) -> Array
3-
*
3+
*
44
* Accepts an array-like collection (anything with numeric indices) and returns
55
* its equivalent as an actual [[Array]] object. This method is a convenience
66
* alias of [[Array.from]], but is the preferred way of casting to an [[Array]].
7-
*
7+
*
88
* The primary use of [[$A]] is to obtain an actual [[Array]] object based on
99
* anything that could pass as an array (e.g. the `NodeList` or
1010
* `HTMLCollection` objects returned by numerous DOM methods, or the predefined
1111
* `arguments` reference within your functions).
12-
*
12+
*
1313
* The reason you would want an actual [[Array]] is simple:
1414
* [[Array Prototype extends Array]] to equip it with numerous extra methods,
1515
* and also mixes in the [[Enumerable]] module, which brings in another
1616
* boatload of nifty methods. Therefore, in Prototype, actual [[Array]]s trump
1717
* any other collection type you might otherwise get.
18-
*
18+
*
1919
* The conversion performed is rather simple: `null`, `undefined` and `false` become
2020
* an empty array; any object featuring an explicit `toArray` method (as many Prototype
2121
* objects do) has it invoked; otherwise, we assume the argument "looks like an array"
2222
* (e.g. features a `length` property and the `[]` operator), and iterate over its components
2323
* in the usual way.
24-
*
24+
*
2525
* When passed an array, [[$A]] _makes a copy_ of that array and returns it.
26-
*
26+
*
2727
* ##### Examples
28-
*
28+
*
2929
* The well-known DOM method [`document.getElementsByTagName()`](http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-A6C9094)
3030
* doesn't return an [[Array]], but a `NodeList` object that implements the basic array
3131
* "interface." Internet Explorer does not allow us to extend `Enumerable` onto `NodeList.prototype`,
3232
* so instead we cast the returned `NodeList` to an [[Array]]:
33-
*
33+
*
3434
* var paras = $A(document.getElementsByTagName('p'));
3535
* paras.each(Element.hide);
3636
* $(paras.last()).show();
37-
*
37+
*
3838
* Notice we had to use [[Enumerable#each each]] and [[Element.hide]] because
3939
* [[$A]] doesn't perform DOM extensions, since the array could contain
4040
* anything (not just DOM elements). To use the [[Element#hide]] instance
4141
* method we first must make sure all the target elements are extended:
42-
*
42+
*
4343
* $A(document.getElementsByTagName('p')).map(Element.extend).invoke('hide');
44-
*
44+
*
4545
* Want to display your arguments easily? [[Array]] features a `join` method, but the `arguments`
4646
* value that exists in all functions *does not* inherit from [[Array]]. So, the tough
4747
* way, or the easy way?
48-
*
48+
*
4949
* // The hard way...
5050
* function showArgs() {
5151
* alert(Array.prototype.join.call(arguments, ', '));
5252
* }
53-
*
53+
*
5454
* // The easy way...
5555
* function showArgs() {
5656
* alert($A(arguments).join(', '));
@@ -69,26 +69,26 @@ function $A(iterable) {
6969

7070
/** section: Language, related to: Array
7171
* $w(String) -> Array
72-
*
72+
*
7373
* Splits a string into an [[Array]], treating all whitespace as delimiters. Equivalent
7474
* to Ruby's `%w{foo bar}` or Perl's `qw(foo bar)`.
75-
*
75+
*
7676
* This is one of those life-savers for people who just hate commas in literal arrays :-)
77-
*
77+
*
7878
* ### Examples
79-
*
79+
*
8080
* $w('apples bananas kiwis')
8181
* // -> ['apples', 'bananas', 'kiwis']
82-
*
82+
*
8383
* This can slightly shorten code when writing simple iterations:
84-
*
84+
*
8585
* $w('apples bananas kiwis').each(function(fruit){
8686
* var message = 'I like ' + fruit
8787
* // do something with the message
8888
* })
89-
*
89+
*
9090
* This also becomes sweet when combined with [[Element]] functions:
91-
*
91+
*
9292
* $w('ads navbar funkyLinks').each(Element.hide);
9393
**/
9494

@@ -195,7 +195,7 @@ Array.from = $A;
195195
}
196196
}
197197
if (!_each) _each = each;
198-
198+
199199
/**
200200
* Array#clear() -> Array
201201
*
@@ -430,10 +430,10 @@ Array.from = $A;
430430
**/
431431
function indexOf(item, i) {
432432
if (this == null) throw new TypeError();
433-
433+
434434
var array = Object(this), length = array.length >>> 0;
435435
if (length === 0) return -1;
436-
436+
437437
// The rules for the `fromIndex` argument are tricky. Let's follow the
438438
// spec line-by-line.
439439
i = Number(i);
@@ -443,11 +443,11 @@ Array.from = $A;
443443
// Equivalent to ES5's `ToInteger` operation.
444444
i = (i > 0 ? 1 : -1) * Math.floor(Math.abs(i));
445445
}
446-
446+
447447
// If the search index is greater than the length of the array,
448448
// return -1.
449449
if (i > length) return -1;
450-
450+
451451
// If the search index is negative, take its absolute value, subtract it
452452
// from the length, and make that the new search index. If it's still
453453
// negative, make it 0.
@@ -456,7 +456,7 @@ Array.from = $A;
456456
if (k in array && array[k] === item) return k;
457457
return -1;
458458
}
459-
459+
460460

461461
/** related to: Array#indexOf
462462
* Array#lastIndexOf(item[, offset]) -> Number
@@ -466,7 +466,7 @@ Array.from = $A;
466466
*
467467
* Returns the position of the last occurrence of `item` within the
468468
* array — or `-1` if `item` doesn't exist in the array.
469-
*
469+
*
470470
* `Array#lastIndexOf` acts as an ECMAScript 5 [polyfill](http://remysharp.com/2010/10/08/what-is-a-polyfill/).
471471
* It is only defined if not already present in the user's browser, and it
472472
* is meant to behave like the native version as much as possible. Consult
@@ -475,10 +475,10 @@ Array.from = $A;
475475
**/
476476
function lastIndexOf(item, i) {
477477
if (this == null) throw new TypeError();
478-
478+
479479
var array = Object(this), length = array.length >>> 0;
480480
if (length === 0) return -1;
481-
481+
482482
// The rules for the `fromIndex` argument are tricky. Let's follow the
483483
// spec line-by-line.
484484
if (!Object.isUndefined(i)) {
@@ -492,7 +492,7 @@ Array.from = $A;
492492
} else {
493493
i = length;
494494
}
495-
495+
496496
// If fromIndex is positive, clamp it to the last index in the array;
497497
// if it's negative, subtract its absolute value from the array's length.
498498
var k = i >= 0 ? Math.min(i, length - 1) :
@@ -526,22 +526,22 @@ Array.from = $A;
526526
array.length = n;
527527
return array;
528528
}
529-
529+
530530
// Certain ES5 array methods have the same names as Prototype array methods
531531
// and perform the same functions.
532532
//
533533
// Prototype's implementations of these methods differ from the ES5 spec in
534-
// the way a missing iterator function is handled. Prototype uses
534+
// the way a missing iterator function is handled. Prototype uses
535535
// `Prototype.K` as a default iterator, while ES5 specifies that a
536-
// `TypeError` must be thrown. Implementing the ES5 spec completely would
536+
// `TypeError` must be thrown. Implementing the ES5 spec completely would
537537
// break backward compatibility and would force users to pass `Prototype.K`
538-
// manually.
538+
// manually.
539539
//
540540
// Instead, if native versions of these methods exist, we wrap the existing
541541
// methods with our own behavior. This has very little performance impact.
542542
// It violates the spec by suppressing `TypeError`s for certain methods,
543543
// but that's an acceptable trade-off.
544-
544+
545545
function wrapNative(method) {
546546
return function() {
547547
if (arguments.length === 0) {
@@ -559,15 +559,15 @@ Array.from = $A;
559559
}
560560
};
561561
}
562-
562+
563563
// Note that #map, #filter, #some, and #every take some extra steps for
564564
// ES5 compliance: the context in which they're called is coerced to an
565565
// object, and that object's `length` property is coerced to a finite
566566
// integer. This makes it easier to use the methods as generics.
567567
//
568568
// This means that they behave a little differently from other methods in
569569
// `Enumerable`/`Array` that don't collide with ES5, but that's OK.
570-
570+
571571
/**
572572
* Array#map([iterator = Prototype.K[, context]]) -> Array
573573
* - iterator (Function): The iterator function to apply to each element
@@ -601,11 +601,11 @@ Array.from = $A;
601601
results.length = n;
602602
return results;
603603
}
604-
604+
605605
if (arrayProto.map) {
606606
map = wrapNative(Array.prototype.map);
607607
}
608-
608+
609609
/**
610610
* Array#filter(iterator[, context]) -> Array
611611
* - iterator (Function): An iterator function to use to test the
@@ -625,7 +625,7 @@ Array.from = $A;
625625
function filter(iterator) {
626626
if (this == null || !Object.isFunction(iterator))
627627
throw new TypeError();
628-
628+
629629
var object = Object(this);
630630
var results = [], context = arguments[1], value;
631631

@@ -674,15 +674,14 @@ Array.from = $A;
674674
return true;
675675
}
676676
}
677-
677+
678678
return false;
679679
}
680-
680+
681681
if (arrayProto.some) {
682-
var some = wrapNative(Array.prototype.some);
682+
some = wrapNative(Array.prototype.some);
683683
}
684-
685-
684+
686685
/**
687686
* Array#every([iterator = Prototype.K[, context]]) -> Boolean
688687
* - iterator (Function): An optional function to use to evaluate each
@@ -699,7 +698,7 @@ Array.from = $A;
699698
* is meant to behave like the native version as much as possible. Consult
700699
* the [ES5 specification](http://es5.github.com/#x15.4.4.16) for more
701700
* information.
702-
*
701+
*
703702
**/
704703
function every(iterator) {
705704
if (this == null) throw new TypeError();
@@ -712,27 +711,34 @@ Array.from = $A;
712711
return false;
713712
}
714713
}
715-
714+
716715
return true;
717716
}
718-
717+
719718
if (arrayProto.every) {
720-
var every = wrapNative(Array.prototype.every);
719+
every = wrapNative(Array.prototype.every);
721720
}
722-
721+
723722
// We used to define an `inject` method here that relied on ES5's
724723
// `Array#reduce` (if present), but using `reduce` prevents us from
725724
// catching a thrown `$break`. So arrays now use the standard
726725
// `Enumerable.inject` like they did previously.
727-
726+
728727
Object.extend(arrayProto, Enumerable);
729728

729+
// Enumerable's `entries` method is no longer safe to mixin to arrays, as
730+
// it conflicts with an ES6 method. But it can still be mixed into other
731+
// things.
732+
if (arrayProto.entries === Enumerable.entries) {
733+
delete arrayProto.entries;
734+
}
735+
730736
if (!arrayProto._reverse)
731737
arrayProto._reverse = arrayProto.reverse;
732738

733739
Object.extend(arrayProto, {
734740
_each: _each,
735-
741+
736742
map: map,
737743
collect: map,
738744
select: filter,
@@ -742,7 +748,7 @@ Array.from = $A;
742748
any: some,
743749
every: every,
744750
all: every,
745-
751+
746752
clear: clear,
747753
first: first,
748754
last: last,

0 commit comments

Comments
 (0)