merging changes

This commit is contained in:
rolux 2011-02-28 11:03:01 +01:00
parent 7cbbab915a
commit 62e6c0d84c
3 changed files with 112 additions and 43 deletions

View file

@ -252,13 +252,13 @@ Lists
border-color: rgb(192, 192, 192); border-color: rgb(192, 192, 192);
} }
.OxThemeClassic .OxTextList .OxBody .OxItem .OxCell { .OxThemeClassic .OxTextList .OxBody .OxItem .OxCell {
border-right: 1px solid rgb(232, 232, 232); border-color: rgb(232, 232, 232);
} }
.OxThemeClassic .OxTextList .OxItem.OxSelected .OxCell { .OxThemeClassic .OxTextList .OxItem.OxSelected .OxCell {
border-right: 1px solid rgb(216, 216, 216); border-color: rgb(216, 216, 216);
} }
.OxThemeClassic .OxTextList .OxFocus .OxItem.OxSelected .OxCell { .OxThemeClassic .OxTextList .OxFocus .OxItem.OxSelected .OxCell {
border-right: 1px solid rgb(200, 200, 200); border-color: rgb(200, 200, 200);
color: rgb(0, 0, 0); color: rgb(0, 0, 0);
} }
.OxThemeClassic .OxTextList .OxBody .OxItem .OxLine { .OxThemeClassic .OxTextList .OxBody .OxItem .OxLine {

View file

@ -215,6 +215,17 @@ Ox.clone = function(obj) {
return Ox.isArray(obj) ? obj.slice() : Ox.extend({}, obj); return Ox.isArray(obj) ? obj.slice() : Ox.extend({}, obj);
}; };
Ox.compact = function(arr) {
/*
returns an array without null or undefined values
>>> Ox.compact([null,,1,,2,,3])
[1, 2, 3]
*/
return Ox.map(arr, function(val) {
return Ox.isUndefined(val) ? null : val;
});
}
Ox.count = function(arr) { Ox.count = function(arr) {
/* /*
Ox.count(['foo', 'bar', 'foo']).foo Ox.count(['foo', 'bar', 'foo']).foo
@ -342,17 +353,17 @@ Ox.forEach = function(obj, fn) {
like $.each(), unlike [].forEach() like $.each(), unlike [].forEach()
The arguments of the iterator function are (value, key), The arguments of the iterator function are (value, key),
like [].forEach(), unlike $.each() like [].forEach(), unlike $.each()
>>> Ox.forEach('foo', function(v, i) {})
'foo'
>>> Ox.forEach([0, 1, 2], function(v, i) {}) >>> Ox.forEach([0, 1, 2], function(v, i) {})
[0, 1, 2] [0, 1, 2]
>>> Ox.forEach({a: 1, b: 2, c: 3}, function(v, k) {}).a >>> Ox.forEach({a: 1, b: 2, c: 3}, function(v, k) {}).a
1 1
>>> Ox.forEach('foo', function(v, i) {})
'foo'
*/ */
var key, isArray = Ox.isArray(obj); var isObject = Ox.isObject(obj), key;
for (key in obj) { for (key in obj) {
key = isArray ? parseInt(key) : key; key = isObject ? key : parseInt(key);
if (fn(obj[key], key) === false) { if (hasOwnProperty.call(obj, key) && fn(obj[key], key) === false) {
break; break;
} }
} }
@ -401,11 +412,13 @@ Ox.isEqual = function(obj0, obj1) {
true true
>>> Ox.isEqual(NaN, NaN) >>> Ox.isEqual(NaN, NaN)
false false
>>> Ox.isEqual('', '')
true
>>> Ox.isEqual([1, 2, 3], [1, 2, 3]) >>> Ox.isEqual([1, 2, 3], [1, 2, 3])
true true
>>> Ox.isEqual({a: 1, b: [2, 3], c: {d: '4'}}, {a: 1, b: [2, 3], c: {d: '4'}}) >>> Ox.isEqual({a: 1, b: [2, 3], c: {d: '4'}}, {a: 1, b: [2, 3], c: {d: '4'}})
true true
>>> Ox.isEqual(function() { return; }, function() { return; }); >>> Ox.isEqual(function(arg) { return arg; }, function(arg) { return arg; });
true true
*/ */
var ret = false; var ret = false;
@ -434,14 +447,20 @@ Ox.isEqual = function(obj0, obj1) {
Ox.keys = function(obj) { Ox.keys = function(obj) {
/* /*
>>> Ox.keys('123')
[0, 1, 2]
>>> Ox.keys([1, 2, 3])
[0, 1, 2]
>>> Ox.keys({a: 1, b: 2, c: 3}) >>> Ox.keys({a: 1, b: 2, c: 3})
["a", "b", "c"] ["a", "b", "c"]
>>> Ox.keys([,])
[0]
*/ */
var keys = []; var keys = [];
Ox.forEach(obj, function(v, k) { Ox.forEach(obj, function(v, k) {
keys.push(k); keys.push(k);
}); });
return keys; return keys.sort();
}; };
Ox.length = function(obj) { Ox.length = function(obj) {
@ -450,12 +469,10 @@ Ox.length = function(obj) {
3 3
>>> Ox.length({"a": 1, "b": 2, "c": 3}) >>> Ox.length({"a": 1, "b": 2, "c": 3})
3 3
>>> Ox.length([,])
1
*/ */
var length = 0; return Ox.isArray(obj) ? obj.length : Ox.values(obj).length;
Ox.forEach(obj, function() {
length++;
});
return length;
}; };
Ox.makeArray = function(arg) { Ox.makeArray = function(arg) {
@ -498,22 +515,26 @@ Ox.makeObject = function() {
return obj; return obj;
}; };
Ox.map = function(arr, fn) { Ox.map = function(obj, fn) {
/* /*
Ox.map() works for arrays and strings, like $.map(), unlike [].map() Ox.map() works for arrays, objects and strings,
unlike [].map()
>>> Ox.map([1, 1, 1], function(v, i) { return v == i; }) >>> Ox.map([1, 1, 1], function(v, i) { return v == i; })
[false, true, false] [false, true, false]
>>> Ox.map({a: 'a', b: 'a', c: 'a'}, function(v, k) { return v == k; }).a
true
>>> Ox.map("111", function(v, i) { return v == i; }) >>> Ox.map("111", function(v, i) { return v == i; })
[false, true, false] [false, true, false]
>>> Ox.map(new Array(3), function(v, i) { return i; }) >>> Ox.map([,], function(v, i) { return i; })
[0, 1, 2] [0]
*/ */
var i, len = arr.length, val, ret = []; var isObject = Ox.isObject(obj),
for (i = 0; i < len; i++) { ret = isObject ? {} : []
if ((val = fn(arr[i], i)) !== null) { Ox.forEach(obj, function(val, key) {
ret.push(val); if ((v = fn(val, key)) !== null) {
} ret[isObject ? key : ret.length] = v;
} }
});
return ret; return ret;
}; };
@ -629,6 +650,37 @@ Ox.some = function(obj, fn) {
return Ox.filter(Ox.values(obj), fn).length > 0; return Ox.filter(Ox.values(obj), fn).length > 0;
}; };
Ox.sort = function(arr) {
/*
>>> Ox.sort(['10', '9', 'B', 'a'])
['9', '10', 'a', 'B']
*/
var len, matches = {}, sort = {};
arr.forEach(function(val, i) {
var match = /^\d+/(val);
matches[val] = match ? match[0] : '';
});
len = Ox.max(Ox.map(matches, function(val) {
return val.length;
}));
arr.forEach(function(val) {
sort[val] = (
matches[val] ?
Ox.pad(matches[val], len) + val.toString().substr(matches[val].length) :
val
).toLowerCase();
});
return arr.sort(function(a, b) {
var ret = 0;
if (sort[a] < sort[b]) {
ret = -1;
} else if (sort[a] > sort[b]) {
ret = 1;
}
return ret;
});
};
Ox.sum = function(obj) { Ox.sum = function(obj) {
/* /*
>>> Ox.sum([-1, 0, 1]) >>> Ox.sum([-1, 0, 1])
@ -688,10 +740,14 @@ Ox.unserialize = function(str) {
Ox.values = function(obj) { Ox.values = function(obj) {
/* /*
>>> Ox.values({a: 1, b: 2, c: 3}) >>> Ox.values('123')
[1, 2, 3] ['1', '2', '3']
>>> Ox.values([1, 2, 3]) >>> Ox.values([1, 2, 3])
[1, 2, 3] [1, 2, 3]
>>> Ox.values({a: 1, b: 2, c: 3})
[1, 2, 3]
>>> Ox.values([1,])
[1]
*/ */
var values = []; var values = [];
Ox.forEach(obj, function(val) { Ox.forEach(obj, function(val) {

View file

@ -771,8 +771,11 @@ requires
}; };
Ox.UI = function() { Ox.UI = (function() {
return { return {
$body: $('body'),
$document: $(document),
$window: $(window),
path: function() { path: function() {
return oxui.path; return oxui.path;
}, },
@ -783,7 +786,7 @@ requires
} }
} }
}(); }());
/*** /***
Ox.URL Ox.URL
@ -861,6 +864,10 @@ requires
return function(options, self) { return function(options, self) {
if (!(this instanceof arguments.callee)) {
return new arguments.callee(options, self);
}
self = self || {}; self = self || {};
self.options = options || {}; self.options = options || {};
if (!self.$eventHandler) { if (!self.$eventHandler) {
@ -8751,10 +8758,12 @@ requires
.options(options || {}); .options(options || {});
if (self.options.data) { if (self.options.data) {
self.options.items = [parseData( self.options.items = [];
self.options.data.key, Ox.print('d', self.options.data, 'i', self.options.items)
self.options.data.value Ox.forEach(self.options.data, function(value, key) {
)]; self.options.items.push(parseData(key, value));
});
Ox.print('d', self.options.data, 'i', self.options.items)
} }
that.$element = new Ox.List({ that.$element = new Ox.List({
@ -8846,17 +8855,23 @@ requires
} }
function parseData(key, value) { function parseData(key, value) {
Ox.print('parseData', key, value)
var ret = { var ret = {
id: key, id: key,
title: key.split('.').pop() title: key.toString().split('.').pop()
}; },
if (Ox.isArray(value) || Ox.isObject(value)) { type = Ox.typeOf(value);
ret.items = [] if (type == 'array' || type == 'object') {
Ox.forEach(value, function(v, k) { ret.title += ': ' + Ox.toTitleCase(Ox.typeOf(value));
ret.items.push(parseData(key + '.' + k, v)); ret.items = Ox.map(Ox.sort(Ox.keys(value)), function(k) {
return parseData(key + '.' + k, value[k]);
}); });
} else { } else {
ret.title += ': ' + (Ox.isFunction(value) ? 'function' : value) ret.title += ': ' + (
type == 'function' ?
value.toString().split('{')[0] :
JSON.stringify(value)
)
} }
return ret; return ret;
} }
@ -8901,9 +8916,7 @@ requires
function toggleItems(event, data) { function toggleItems(event, data) {
data.ids.forEach(function(id, i) { data.ids.forEach(function(id, i) {
var item = getItemById(id); var item = getItemById(id);
Ox.print('item', item, !!item.items, data.expanded != !!item.expanded)
if (item.items && data.expanded != !!item.expanded) { if (item.items && data.expanded != !!item.expanded) {
Ox.print('ITEM', item)
toggleItem(item, data.expanded); toggleItem(item, data.expanded);
} }
}); });
@ -9504,7 +9517,7 @@ requires
} }
function getPlaceByLatLng(latlng, bounds, callback) { function getPlaceByLatLng(latlng, bounds, callback) {
//Ox.print('ll b', latlng, bounds) Ox.print('ll b', latlng, bounds)
var callback = arguments.length == 3 ? callback : bounds, var callback = arguments.length == 3 ? callback : bounds,
bounds = arguments.length == 3 ? bounds : null; bounds = arguments.length == 3 ? bounds : null;
self.geocoder.geocode({ self.geocoder.geocode({