Improve NodeList detection for Safari's $A function. [#187 state:resolved]

This commit is contained in:
Andrew Dupont 2008-07-17 15:31:28 -05:00 committed by Tobie Langel
parent 5ddfad8a62
commit b7af8a745b
2 changed files with 9 additions and 3 deletions

View File

@ -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)

View File

@ -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;