Improve NodeList detection for Safari's $A function. [#187 state:resolved]
This commit is contained in:
parent
5ddfad8a62
commit
b7af8a745b
|
@ -1,3 +1,5 @@
|
|||
* Improve NodeList detection for Safari's $A function. [Garrett Smith, jddalton]
|
||||
|
||||
* Use different tactic to sniff for Opera in order to avoid false positives in IE. [Tobie Langel, jddalton]
|
||||
|
||||
* Rename variable in Form.Element.Serializers.select. (jddalton)
|
||||
|
|
10
src/array.js
10
src/array.js
|
@ -8,9 +8,13 @@ function $A(iterable) {
|
|||
|
||||
if (Prototype.Browser.WebKit) {
|
||||
$A = function(iterable) {
|
||||
if (!iterable) return [];
|
||||
if (!(Object.isFunction(iterable) && iterable == '[object NodeList]') &&
|
||||
iterable.toArray) return iterable.toArray();
|
||||
if (!iterable) return [];
|
||||
// In Safari, only use the `toArray` method if it's not a NodeList.
|
||||
// A NodeList is a function, has an function `item` property, and a numeric
|
||||
// `length` property. Adapted from Google Doctype.
|
||||
if (!(typeof iterable === 'function' && typeof iterable.length ===
|
||||
'number' && typeof iterable.item === 'function') && iterable.toArray)
|
||||
return iterable.toArray();
|
||||
var length = iterable.length || 0, results = new Array(length);
|
||||
while (length--) results[length] = iterable[length];
|
||||
return results;
|
||||
|
|
Loading…
Reference in New Issue