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);
}
.OxThemeClassic .OxTextList .OxBody .OxItem .OxCell {
border-right: 1px solid rgb(232, 232, 232);
border-color: rgb(232, 232, 232);
}
.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 {
border-right: 1px solid rgb(200, 200, 200);
border-color: rgb(200, 200, 200);
color: rgb(0, 0, 0);
}
.OxThemeClassic .OxTextList .OxBody .OxItem .OxLine {

View file

@ -215,6 +215,17 @@ Ox.clone = function(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(['foo', 'bar', 'foo']).foo
@ -342,17 +353,17 @@ Ox.forEach = function(obj, fn) {
like $.each(), unlike [].forEach()
The arguments of the iterator function are (value, key),
like [].forEach(), unlike $.each()
>>> Ox.forEach('foo', function(v, i) {})
'foo'
>>> Ox.forEach([0, 1, 2], function(v, i) {})
[0, 1, 2]
>>> Ox.forEach({a: 1, b: 2, c: 3}, function(v, k) {}).a
1
>>> Ox.forEach('foo', function(v, i) {})
'foo'
*/
var key, isArray = Ox.isArray(obj);
var isObject = Ox.isObject(obj), key;
for (key in obj) {
key = isArray ? parseInt(key) : key;
if (fn(obj[key], key) === false) {
key = isObject ? key : parseInt(key);
if (hasOwnProperty.call(obj, key) && fn(obj[key], key) === false) {
break;
}
}
@ -401,11 +412,13 @@ Ox.isEqual = function(obj0, obj1) {
true
>>> Ox.isEqual(NaN, NaN)
false
>>> Ox.isEqual('', '')
true
>>> Ox.isEqual([1, 2, 3], [1, 2, 3])
true
>>> Ox.isEqual({a: 1, b: [2, 3], c: {d: '4'}}, {a: 1, b: [2, 3], c: {d: '4'}})
true
>>> Ox.isEqual(function() { return; }, function() { return; });
>>> Ox.isEqual(function(arg) { return arg; }, function(arg) { return arg; });
true
*/
var ret = false;
@ -434,14 +447,20 @@ Ox.isEqual = function(obj0, obj1) {
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})
["a", "b", "c"]
>>> Ox.keys([,])
[0]
*/
var keys = [];
Ox.forEach(obj, function(v, k) {
keys.push(k);
});
return keys;
return keys.sort();
};
Ox.length = function(obj) {
@ -450,12 +469,10 @@ Ox.length = function(obj) {
3
>>> Ox.length({"a": 1, "b": 2, "c": 3})
3
>>> Ox.length([,])
1
*/
var length = 0;
Ox.forEach(obj, function() {
length++;
});
return length;
return Ox.isArray(obj) ? obj.length : Ox.values(obj).length;
};
Ox.makeArray = function(arg) {
@ -498,22 +515,26 @@ Ox.makeObject = function() {
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; })
[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; })
[false, true, false]
>>> Ox.map(new Array(3), function(v, i) { return i; })
[0, 1, 2]
>>> Ox.map([,], function(v, i) { return i; })
[0]
*/
var i, len = arr.length, val, ret = [];
for (i = 0; i < len; i++) {
if ((val = fn(arr[i], i)) !== null) {
ret.push(val);
var isObject = Ox.isObject(obj),
ret = isObject ? {} : []
Ox.forEach(obj, function(val, key) {
if ((v = fn(val, key)) !== null) {
ret[isObject ? key : ret.length] = v;
}
}
});
return ret;
};
@ -629,6 +650,37 @@ Ox.some = function(obj, fn) {
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([-1, 0, 1])
@ -688,10 +740,14 @@ Ox.unserialize = function(str) {
Ox.values = function(obj) {
/*
>>> Ox.values({a: 1, b: 2, c: 3})
[1, 2, 3]
>>> Ox.values('123')
['1', '2', '3']
>>> Ox.values([1, 2, 3])
[1, 2, 3]
>>> Ox.values({a: 1, b: 2, c: 3})
[1, 2, 3]
>>> Ox.values([1,])
[1]
*/
var values = [];
Ox.forEach(obj, function(val) {

View file

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