Ox.values: make sure that for nodelists, this returns an array, not a nodelist; Ox.contains: make sure this works for nodelists too

This commit is contained in:
rolux 2014-08-21 13:05:27 +02:00
parent 835c4c92b7
commit d030b8d764

View file

@ -59,10 +59,11 @@ Ox.contains <f> Tests if a collection contains a value
> Ox.contains('foobar', 'bar') > Ox.contains('foobar', 'bar')
true true
@*/ @*/
// FIXME: a shorter name would be nice (but IE8 doesn't like 'in')
Ox.contains = function(collection, value) { Ox.contains = function(collection, value) {
var type = Ox.typeOf(collection);
return ( return (
Ox.isObject(collection) ? Ox.values(collection) : collection type == 'nodelist' || type == 'object'
? Ox.values(collection) : collection
).indexOf(value) > -1; ).indexOf(value) > -1;
}; };
@ -581,7 +582,7 @@ Ox.values <f> Returns the values of a collection
Ox.values = function(collection) { Ox.values = function(collection) {
var ret, type = Ox.typeOf(collection); var ret, type = Ox.typeOf(collection);
if (type == 'array' || type == 'nodelist') { if (type == 'array' || type == 'nodelist') {
ret = Ox.clone(collection); ret = Ox.slice(collection);
} else if (type == 'object' || type == 'storage') { } else if (type == 'object' || type == 'storage') {
ret = []; ret = [];
Ox.forEach(collection, function(value) { Ox.forEach(collection, function(value) {