1
0
Fork 0
forked from 0x2620/oxjs

add Ox.ArrayInput, more Ox.ListMap UI

This commit is contained in:
rolux 2011-05-21 19:56:15 +02:00
commit 6a33b9cb97
8 changed files with 381 additions and 101 deletions

View file

@ -1,6 +1,6 @@
// vim: et:ts=4:sw=4:sts=4:ft=js
// OxJS (c) 2011 Ox2620, dual-licensed GPL/MIT, see http://oxjs.org for details
// OxJS (c) 2011 0x2620, dual-licensed GPL/MIT, see http://oxjs.org for details
/*
Some conventions:
@ -194,13 +194,18 @@ Ox.merge = function(arr) {
/*@
Ox.sort <f> Sorts an array, handling leading digits and ignoring capitalization
arr <a> Array
fn <f|u> Optional map function that returns the value for the array element
> Ox.sort(['10', '9', 'B', 'a'])
['9', '10', 'a', 'B']
> Ox.sort([{id: 0, name: '80 Days'}, {id: 1, name: '8 Women'}], function(v) {return v.name});
[{id: 1, name: '8 Women'}, {id: 0, name: '80 Days'}]
@*/
Ox.sort = function(arr) {
var len, matches = {}, sort = {};
Ox.sort = function(arr, fn) {
var len, matches = {}, sort = {},
values = fn ? arr.map(fn) : arr;
// find leading numbers
arr.forEach(function(val, i) {
values.forEach(function(val, i) {
var match = /^\d+/(val);
matches[val] = match ? match[0] : '';
});
@ -209,7 +214,7 @@ Ox.sort = function(arr) {
return val.length;
}));
// pad leading numbers, and make lower case
arr.forEach(function(val) {
values.forEach(function(val) {
sort[val] = (
matches[val] ?
Ox.pad(matches[val], len) + val.toString().substr(matches[val].length) :
@ -217,6 +222,8 @@ Ox.sort = function(arr) {
).toLowerCase();
});
return arr.sort(function(a, b) {
a = fn ? fn(a) : a;
b = fn ? fn(b) : b;
var ret = 0;
if (sort[a] < sort[b]) {
ret = -1;