In Ox.api, add support for values that are arrays

This commit is contained in:
rolux 2012-10-26 17:27:15 +02:00
parent 909184fbba
commit 2223fcfd2b

View file

@ -363,10 +363,18 @@ Ox.api = function(items, options) {
test = { test = {
'=': function(a, b) { '=': function(a, b) {
return Ox.isArray(b) ? a >= b[0] && a < b[1] return Ox.isArray(b) ? a >= b[0] && a < b[1]
: Ox.isArray(a) ? a.some(function(value) {
return value.indexOf(b) > -1;
})
: Ox.isString(a) ? a.indexOf(b) > -1 : Ox.isString(a) ? a.indexOf(b) > -1
: a === b; : a === b;
}, },
'==': function(a, b) { return a === b; }, '==': function(a, b) {
return Ox.isArray(a) ? a.some(function(value) {
return value === b;
})
: a === b;
},
'<': function(a, b) { return a < b; }, '<': function(a, b) { return a < b; },
'<=': function(a, b) { return a <= b; }, '<=': function(a, b) { return a <= b; },
'>': function(a, b) { return a > b; }, '>': function(a, b) { return a > b; },
@ -376,6 +384,10 @@ Ox.api = function(items, options) {
}; };
if (Ox.isString(itemValue)) { if (Ox.isString(itemValue)) {
itemValue = itemValue.toLowerCase(); itemValue = itemValue.toLowerCase();
} else if (Ox.isArray(itemValue) && Ox.isString(itemValue[0])) {
itemValue = itemValue.map(function(value) {
return value.toLowerCase();
});
} }
if (api.enums[key] && ( if (api.enums[key] && (
operator.indexOf('<') > -1 operator.indexOf('<') > -1