1
0
Fork 0
forked from 0x2620/oxjs

less obscure Ox.map

This commit is contained in:
rolux 2012-05-22 16:29:37 +02:00
commit 12cf77cef5
21 changed files with 125 additions and 101 deletions

View file

@ -116,8 +116,9 @@ Ox.ArrayInput = function(options, self) {
function getValue() {
return Ox.map(self.$input, function($input) {
var value = $input.value();
return value === '' ? null : value;
return $input.value();
}).filter(function(value) {
return value !== '';
});
};

View file

@ -357,8 +357,6 @@ Ox.Input = function(options, self) {
}
newLength = newValue.length;
//Ox.Log('Form', 'selectEnd', selectEnd)
if (self.options.autocompleteReplace) {
value = self.options.value;
self.options.value = newValue;
@ -374,27 +372,32 @@ Ox.Input = function(options, self) {
}
if (self.options.autocompleteSelect) {
value = (self.options.autocompleteReplace ? value : self.options.value).toLowerCase();
value = (
self.options.autocompleteReplace
? value : self.options.value
).toLowerCase();
if (values.length) {
self.oldCursor = cursor();
self.oldValue = self.options.value;
self.$autocompleteMenu.options({
items: Ox.map(values, function(v, i) {
var ret = null;
items: Ox.filter(values, function(v, i) {
var ret = false;
if (
!self.options.autocompleteSelectMax ||
i < self.options.autocompleteSelectMax
) {
if (value == v.toLowerCase()) {
if (v.toLowerCase() === value) {
selected = i;
}
ret = {
id: v.toLowerCase().replace(/ /g, '_'), // fixme: need function to do lowercase, underscores etc?
title: self.options.autocompleteSelectHighlight ?
Ox.highlight(v, value, 'OxHighlight') : v
};
ret = true;
}
return ret;
}).map(function(v) {
return {
id: v.toLowerCase().replace(/ /g, '_'), // fixme: need function to do lowercase, underscores etc?
title: self.options.autocompleteSelectHighlight ?
Ox.highlight(v, value, 'OxHighlight') : v
};
})
});
if (!self.selectEventBound) {
@ -403,7 +406,6 @@ Ox.Input = function(options, self) {
});
self.selectEventBound = true;
}
Ox.Log('AUTO', 'show menu')
self.$autocompleteMenu.options({
selected: selected
}).showMenu();

View file

@ -45,8 +45,8 @@ Ox.OptionGroup = function(items, min, max, property) {
@*/
// FIXME: isn't value more useful in all cases?
this[property] = function() {
return Ox.map(items, function(item, i) {
return item[property] ? i : null;
return Ox.indicesOf(items, function(item) {
return item[property];
});
};

View file

@ -67,8 +67,10 @@ Ox.SelectInput = function(options, self) {
return value[value[0] == self.other ? 1 : 0]
},
split: function(value) {
return Ox.map(self.options.items, function(item, i) {
return i < item.length - 1 ? item.id : null;
return Ox.filter(self.options.items, function(item, i) {
return i < item.length - 1;
}).map(function(item) {
return item.id;
}).indexOf(value) > -1 ? [value, ''] : [self.other, value];
},
width: self.options.width
@ -89,8 +91,10 @@ Ox.SelectInput = function(options, self) {
function setValue(isOther) {
if (
(!self.options.value && isOther !== true)
|| Ox.map(self.options.items, function(item) {
return item.id != self.other ? item.id : null;
|| Ox.filter(self.options.items, function(item) {
return item.id != self.other;
}).map(function(item) {
return item.id;
}).indexOf(self.options.value) > -1
) {
self.$select.options({