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

@ -262,9 +262,7 @@ Ox.URL = function(options) {
parts.push(constructFind(state.find));
}
}
return '/' + Ox.map(parts, function(part) {
return part || null;
}).join('/');
return '/' + Ox.filter(parts).join('/');
}
function constructValue(str, key) {

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({

View file

@ -154,8 +154,8 @@ Ox.Chart = function(options, self) {
});
while (Ox.sum(widths) != totalWidth) {
max = Ox.max(widths);
maxKeys = Ox.map(Object.keys(widths), function(key) {
return widths[key] == max ? key : null;
maxKeys = Object.keys(widths).filter(function(key) {
return widths[key] == max;
});
widths[maxKeys[0]] += Ox.sum(widths) < totalWidth ? 1 : -1;
}

View file

@ -160,16 +160,13 @@ Ox.IconItem = function(options, self) {
text = Ox.isArray(text) ? text.join(', ') : text;
var lines = Ox.wordwrap(text, maxLength, '\n', true, false).split('\n');
return Ox.highlightHTML(
Ox.map(lines, function(line, i) {
if (i < maxLines - 1) {
return line;
} else if (i == maxLines - 1) {
return lines.length == maxLines ? line : Ox.truncate(lines.map(function(line, i) {
return i < maxLines - 1 ? null : line;
}).join(' '), maxLength, '...', 'center');
} else {
return null;
}
lines.slice(0, maxLines).map(function(line, i) {
return i < maxLines - 1 || lines.length == maxLines
? line
: Ox.truncate(
lines.slice(maxLines).join(' '),
maxLength, '...', 'center'
);
}).join(' <br/>'),
self.options.find, 'OxHighlight', ['br']
).replace(/ (<.*?>)?<br\/>/g, ' $1<br\/>');

View file

@ -183,8 +183,10 @@ Ox.TextList = function(options, self) {
max: -1,
min: 1,
type: 'image',
value: Ox.map(self.options.columns, function(column) {
return column.visible ? column.id : null;
value: Ox.filter(self.options.columns, function(column) {
return column.visible;
}).map(function(column) {
return column.id;
})
})
.bindEvent('change', changeColumns)

View file

@ -160,7 +160,7 @@ Ox.TreeList = function(options, self) {
if (type == 'array' || type == 'object') {
ret.title += Ox.toTitleCase(type)
+ ' <span class="OxLight">[' + Ox.len(value) + ']</span>';
ret.items = Ox.map(Ox.sort(Ox.keys(value)), function(k) {
ret.items = Ox.sort(Ox.keys(value).map(function(k) {
return parseData(k, value[k]);
});
} else {

View file

@ -328,7 +328,7 @@ Ox.AnnotationFolder = function(options, self) {
}
function getAnnotations() {
return Ox.map(self.options.items, function(item) {
return Ox.filter(self.options.items, function(item) {
return self.editing && item.id == self.options.selected || (
(
self.options.range == 'all' || (
@ -344,7 +344,7 @@ Ox.AnnotationFolder = function(options, self) {
self.options.users == 'all'
|| self.options.users.indexOf(item.user) > -1
)
) ? item : null;
);
});
}

View file

@ -425,11 +425,11 @@ Ox.VideoEditor = function(options, self) {
{key: 'G', action: 'Go to Next Result'},
{key: Ox.UI.symbols['return'], action: 'Edit/Submit'},
{key: Ox.UI.symbols.escape, action: 'Cancel/Deselect'}
], Ox.map(self.options.layers, function(layer, i) {
], Ox.filter(self.options.layers.map(function(layer, i) {
return layer.editable
? {key: i + 1, action: 'Add ' + layer.item}
: null;
})).forEach(function(shortcut) {
}))).forEach(function(shortcut) {
self.$keyboardShortcuts.append(
$('<div>').css({display: 'table-row'})
.append(

View file

@ -1175,14 +1175,27 @@ Ox.VideoPlayer = function(options, self) {
var results = [];
if (query.length) {
query = query.toLowerCase();
results = Ox.map(self.options.annotations, function(annotation) {
results = Ox.filter(self.options.annotations, function(annotation) {
return Ox.decodeHTML(Ox.stripTags(
annotation.text.toLowerCase()
)).indexOf(query) > -1 ? {
)).indexOf(query) > -1;
}).map(function(annotation) {
return {
id: annotation.id,
'in': annotation['in'],
out: annotation.out
} : null;
};
})
results = Ox.filter(self.options.annotations, function(annotation) {
return Ox.decodeHTML(Ox.stripTags(
annotation.text.toLowerCase()
)).indexOf(query) > -1;
}).map(function(annotation) {
return {
id: annotation.id,
'in': annotation['in'],
out: annotation.out
};
});
}
//Ox.print('FIND RESULTS:', results);

View file

@ -496,9 +496,7 @@ Ox.Dialog = function(options, self) {
function setButtons() {
var buttonsLeft,
buttonsRight,
index = Ox.map(self.options.buttons, function(v, i) {
return Ox.isEmpty(v) ? i : null;
})[0];
index = Ox.indexOf(self.options.buttons, Ox.isEmpty);
if (index) {
buttonsLeft = Ox.sub(self.options.buttons, 0, index);
buttonsRight = Ox.sub(self.options.buttons, index + 1);