This commit is contained in:
Sanj 2011-12-30 21:45:02 +05:30
commit 6789df65e6
18 changed files with 369 additions and 164 deletions

View file

@ -22,9 +22,7 @@ Ox.API = function(options, callback) {
api: function(callback) {
Ox.Request.send({
url: self.options.url,
data: {
action: 'api'
},
data: {action: 'api'},
callback: callback
});
},

View file

@ -18,6 +18,7 @@ Ox.App = function(options) {
var self = {
options: Ox.extend({
name: 'App',
timeout: 60000,
type: 'POST',
url: '/api/'
@ -39,6 +40,8 @@ Ox.App = function(options) {
});
});
that.localStorage = Ox.localStorage(self.options.name);
function getUserData() {
return {
document: {

View file

@ -119,9 +119,7 @@ Ox.Theme = (function() {
});
});
}
if (localStorage) {
localStorage.OxTheme = theme;
}
Ox.localStorage('Ox')('theme', theme);
return that;
}

View file

@ -88,7 +88,11 @@ Ox.CheckboxGroup = function(options, self) {
self.options.value = self.optionGroup.value();
that.triggerEvent('change', {
title: Ox.isString(self.options.value)
? Ox.getObjectById(self.options.checkboxes, self.options.value).title
? (
self.options.value
? Ox.getObjectById(self.options.checkboxes, self.options.value).title
: ''
)
: self.options.value.map(function(value) {
return Ox.getObjectById(self.options.checkboxes, value).title;
}),

View file

@ -25,7 +25,10 @@ Ox.Form = function(options, self) {
items: [],
// FIXME: don't pass function,
// listen to event instead!
submit: null
submit: null,
validate: function(valid) {
return Ox.every(valid);
}
})
.options(options || {}) // fixme: the || {} can be done once, in the options function
.addClass('OxForm');
@ -33,20 +36,14 @@ Ox.Form = function(options, self) {
Ox.extend(self, {
$items: [],
$messages: [],
formIsValid: false,
itemIds: [],
itemIsValid: []
});
self.options.items.forEach(function(item, i) {
var validateItem = item.options('validate');
if (validateItem) {
validateItem(item.value(), function(data) {
self.itemIsValid[i] = data.valid;
});
} else {
self.itemIsValid[i] = item.value !== '';
}
validateItem(i, function(valid) {
self.itemIsValid[i] = valid;
});
self.itemIds[i] = item.options('id') || item.id;
self.$items[i] = Ox.FormItem({element: item}).appendTo(that);
item.bindEvent({
@ -79,6 +76,9 @@ Ox.Form = function(options, self) {
id: self.itemIds[i],
data: data
});
validateItem(i, function(valid) {
validateForm(i, valid);
});
},
submit: function(data) {
self.formIsValid && that.submit();
@ -95,6 +95,8 @@ Ox.Form = function(options, self) {
});
});
self.formIsValid = self.options.validate(self.itemIsValid);
function getItemIndexById(id) {
return self.itemIds.indexOf(id);
}
@ -107,8 +109,7 @@ Ox.Form = function(options, self) {
function validateForm(pos, valid) {
self.itemIsValid[pos] = valid;
Ox.Log('Form', 'VALID???', self.itemIsValid)
if (Ox.every(self.itemIsValid) != self.formIsValid) {
if (self.options.validate(self.itemIsValid) != self.formIsValid) {
self.formIsValid = !self.formIsValid;
that.triggerEvent('validate', {
valid: self.formIsValid
@ -116,6 +117,18 @@ Ox.Form = function(options, self) {
}
}
function validateItem(pos, callback) {
var item = self.options.items[pos],
validate = item.options('validate');
if (validate) {
validate(item.value(), function(data) {
callback(data.valid);
});
} else {
callback(item.value && !Ox.isEmpty(item.value));
}
}
that.addItem = function(pos, item) {
Ox.Log('Form', 'addItem', pos)
self.options.items.splice(pos, 0, item);
@ -138,6 +151,10 @@ Ox.Form = function(options, self) {
self.options.submit(that.values(), submitCallback);
};
that.valid = function() {
return self.formIsValid;
};
that.values = function() { // fixme: can this be private?
/*
get/set form values
@ -147,9 +164,8 @@ Ox.Form = function(options, self) {
var values = {};
if (arguments.length == 0) {
self.$items.forEach(function($item, i) {
//Ox.print('??????-??', self.itemIds[i], self.$items[i].value(), Ox.typeOf(self.$items[i].value()))
values[self.itemIds[i]] = self.$items[i].value();
//fixme: make the following work
//values[self.itemIds[i]] = self.$items[i].value();
});
//Ox.Log('Form', 'VALUES', values)
return values;
@ -157,7 +173,7 @@ Ox.Form = function(options, self) {
Ox.Log('Form', 'SET FORM VALUES', arguments[0])
Ox.forEach(arguments[0], function(value, key) {
var index = getItemIndexById(key);
//index > -1 && Ox.Log('Form', ':::::::', key, value)
index > -1 && Ox.Log('Form', ':::::::', key, value)
index > -1 && self.options.items[index].value(value);
});
return that;

View file

@ -115,11 +115,7 @@ Ox.FormElementGroup = function(options, self) {
that.value = function() {
var values = self.options.elements.map(function(element) {
var ret = null;
['checked', 'selected', 'value'].forEach(function(v) {
element[v] && (ret = element[v]());
});
return ret;
return element.value();
});
return self.options.joinValues
? self.options.joinValues(values)

View file

@ -45,19 +45,9 @@ Ox.FormPanel = function(options, self) {
width: 240
}
],
items: function(data, callback) {
setTimeout(function() {
callback({
data: {
items: Ox.isEmpty(data)
? self.sections.length
: self.options.form.map(function(section) {
return {title: section.title, valid: section.valid};
})
}
});
}, 250);
},
items: self.options.form.map(function(section) {
return {title: section.title, valid: false};
}),
max: 1,
min: 1,
selected: [self.sections[0].id],
@ -90,7 +80,7 @@ Ox.FormPanel = function(options, self) {
.append(
$('<div>')
.css({marginBottom: '8px', fontWeight: 'bold'})
.html(section.title)
.html((i + 1) + '. ' + section.title)
)
.append(
$('<div>')
@ -99,27 +89,22 @@ Ox.FormPanel = function(options, self) {
)
.append(
self.$forms[i] = Ox.Form({
items: section.items
items: section.items,
validate: section.validate
})
.bindEvent({
change: function(data) {
var valid;
if (section.validate) {
valid = section.validate(section.title, data);
self.$list.value(section.title, 'valid', valid);
that.triggerEvent('validate', {
title: section.title,
data: {valid: valid}
});
}
//var valid = section.validate(section.title, data);
//self.$list.value(section.title, 'valid', valid);
//that.triggerEvent('change', data);
Ox.Log('FORM', '---CHANGE---', data, self.$forms[i].valid())
self.$list.value(section.title, 'valid', self.$forms[i].valid());
that.triggerEvent('change', {
section: section.title,
data: data
});
},
validate: function(data) {
self.$list.value(section.title, 'valid', data.valid);
that.triggerEvent('validate', {
title: section.title,
section: section.title,
data: data
});
}
@ -129,6 +114,11 @@ Ox.FormPanel = function(options, self) {
.appendTo(self.$section);
});
self.$forms.forEach(function($form, i) {
Ox.print(self.sections[i], 'valid', $form.valid());
self.$list.value(self.sections[i], 'valid', $form.valid());
});
self.$sections[0].show();
that.$element = Ox.SplitPanel({
@ -157,6 +147,44 @@ Ox.FormPanel = function(options, self) {
return index;
}
that.renderPrintVersion = function(title) {
var $printVersion = $('<div>').css({overflowY: 'auto'});
$printVersion.append(
$('<div>')
.addClass('OxFormSectionTitle')
.css({
height: '16px',
padding: '16px 16px 8px 16px',
fontWeight: 'bold'
})
.html(title)
);
self.$sections.forEach(function($section, i) {
// jQuery bug: textarea html/val does not survive cloning
// http://bugs.jquery.com/ticket/3016
var $clone = $section.clone(true),
textareas = {
section: $section.find('textarea'),
clone: $clone.find('textarea')
};
textareas.section.each(function(i) {
$(textareas.clone[i]).val($(this).val());
});
$printVersion
.append(
$('<div>').css({
height: '1px',
margin: '8px 0 8px 0',
background: 'rgb(128, 128, 128)'
})
)
.append(
$clone.show()
);
});
return $printVersion;
};
that.values = function() {
var values = {};
self.options.form.forEach(function(section, i) {

View file

@ -869,7 +869,7 @@ Ox.Input = function(options, self) {
that.clearInput = function() {
clear();
return that;
}
};
/*@
focusInput <f> Focus input element
@ -1654,6 +1654,7 @@ Ox.InputElement_ = function(options, self) {
self.options.autosuggestSubmit && submit();
}
// FIXME: make this public!
function cursor(start, end) {
/*
cursor() returns [start, end]

View file

@ -15,11 +15,8 @@ Ox.ObjectArrayInput = function(options, self) {
.options(options || {})
.addClass('OxObjectArrayInput');
if (self.options.value.length == 0) {
self.options.value = [{}];
self.options.inputs.forEach(function(input) {
self.options.value[0][input.options.id] = '';
});
if (Ox.isEmpty(self.options.value)) {
self.options.value = [getDefaultValue()];
}
self.$element = [];
@ -28,11 +25,10 @@ Ox.ObjectArrayInput = function(options, self) {
self.$addButton = [];
self.buttonWidth = self.options.width / 2 - 4;
self.options.value.forEach(function(value, i) {
addInput(i, value);
});
setValue(self.options.value);
function addInput(index, value) {
Ox.print('ADD INPUT', index, value)
self.$element.splice(index, 0, Ox.Element()
.css({
width: self.options.width + 'px',
@ -50,11 +46,16 @@ Ox.ObjectArrayInput = function(options, self) {
.bindEvent(input.events || {});
}),
labelWidth: self.options.labelWidth,
value: value,
width: self.options.width
})
.bindEvent({
change: function(data) {
// ...
var index = $(this).parent().data('index');
self.options.value[index] = self.$input[index].value();
that.triggerEvent('change', {
value: self.options.value
});
}
})
.appendTo(self.$element[index])
@ -70,6 +71,10 @@ Ox.ObjectArrayInput = function(options, self) {
var index = $(this).parent().data('index');
if (self.$input.length > 1) {
removeInput(index);
self.options.value = getValue();
that.triggerEvent('change', {
value: self.options.value
});
}
}
})
@ -84,7 +89,11 @@ Ox.ObjectArrayInput = function(options, self) {
.bind({
click: function() {
var index = $(this).parent().data('index');
addInput(index + 1);
addInput(index + 1, getDefaultValue());
self.options.value = getValue();
that.triggerEvent('change', {
value: self.options.value
});
}
})
.appendTo(self.$element[index])
@ -92,6 +101,20 @@ Ox.ObjectArrayInput = function(options, self) {
updateInputs();
}
function getDefaultValue() {
var value = {};
self.options.inputs.forEach(function(input) {
value[input.options.id] = '';
});
return value;
}
function getValue() {
return self.$input.map(function($input) {
return $input.value();
});
}
function removeInput(index) {
[
'input', 'removeButton', 'addButton', 'element'
@ -103,6 +126,16 @@ Ox.ObjectArrayInput = function(options, self) {
updateInputs();
}
function setValue(value) {
while (self.$element.length) {
removeInput(0);
}
value.forEach(function(value, i) {
addInput(i, value);
});
}
function updateInputs() {
var length = self.$element.length;
self.$element.forEach(function($element, i) {
@ -121,17 +154,10 @@ Ox.ObjectArrayInput = function(options, self) {
self.setOption = function(key, value) {
if (key == 'value') {
// ...
setValue(value);
}
};
// FIXME: remove
that.value = function() {
return self.$input.map(function($input) {
return $input.value();
});
};
return that;
};

View file

@ -7,6 +7,7 @@ Ox.ObjectInput = function(options, self) {
.defaults({
elements: [],
labelWidth: 128,
value: {},
width: 256
})
.options(options || {})
@ -16,6 +17,12 @@ Ox.ObjectInput = function(options, self) {
height: self.options.elements.length * 24 - 8 + 'px'
});
if (Ox.isEmpty(self.options.value)) {
self.options.value = getValue();
} else {
setValue(self.options.value);
}
self.options.elements.forEach(function($element) {
$element.options({
labelWidth: self.options.labelWidth,
@ -23,10 +30,7 @@ Ox.ObjectInput = function(options, self) {
})
.bindEvent({
change: function(data) {
self.options.value = {};
self.options.elements.forEach(function(element) {
self.options.value[element.options('id')] = element.value();
});
self.options.value = getValue();
that.triggerEvent('change', {
value: self.options.value
});
@ -35,9 +39,23 @@ Ox.ObjectInput = function(options, self) {
.appendTo(that);
});
function getValue() {
var value = {};
self.options.elements.forEach(function(element) {
value[element.options('id')] = element.value();
});
return value;
}
function setValue(value) {
self.options.elements.forEach(function(element) {
element.value(value[element.options('id')]);
});
}
self.setOption = function(key, value) {
if (key == 'value') {
// ...
setValue(value);
}
};

View file

@ -110,8 +110,7 @@ Ox.Select = function(options, self) {
width: getTitleWidth() + 'px'
})
.html(
self.options.title
|| getItem(self.options.value).title
self.options.title || getItem(self.options.value).title
)
.appendTo(that);
}
@ -153,14 +152,15 @@ Ox.Select = function(options, self) {
function changeMenu(data) {
self.options.value = self.optionGroup.value();
self.$title && self.$title.html(
self.options.title ? self.options.title : getItem(self.options.value).title
self.options.title || getItem(self.options.value).title
);
that.triggerEvent('change', {
title: Ox.isArray(self.options.value)
? self.options.value.map(function(value) {
return getItem(value).title;
})
: getItem(self.options.value).title,
title: Ox.isEmpty(self.options.value) ? ''
: Ox.isArray(self.options.value)
? self.options.value.map(function(value) {
return getItem(value).title;
})
: getItem(self.options.value).title,
value: self.options.value
});
}
@ -207,15 +207,13 @@ Ox.Select = function(options, self) {
self.$button.options({title: value});
}
} else if (key == 'width') {
Ox.Log('Form', 'SETTING WIDTH OPTION', value);
that.css({width: value - 2 + 'px'});
self.$title.css({width: getTitleWidth() + 'px'});
} else if (key == 'value') {
Ox.Log('Form', 'SETTING VALUE OPTION', value);
if (self.options.type == 'text' && !self.options.title) {
self.$title.html(getItem(value).title);
}
Ox.toArray(value).forEach(function(value) {
value !== '' && Ox.toArray(value).forEach(function(value) {
self.$menu.checkItem(value);
});
self.options.value = self.optionGroup.value();

View file

@ -10,7 +10,7 @@ Ox.SelectInput = function(options, self) {
label: '',
labelWidth: 128,
max: 1,
min: 1,
min: 0,
placeholder: '',
title: '',
value: options.max == 1 ? '' : [],
@ -27,28 +27,14 @@ Ox.SelectInput = function(options, self) {
labelWidth: self.options.labelWidth,
max: self.options.max,
min: self.options.min,
title: self.options.title,
title: getTitle(),
value: self.options.value,
width: self.options.width
})
.bindEvent({
change: function(data) {
if (self.options.title) {
self.$select.options({
title: Ox.getObjectById(self.options.items, data.value).title
});
}
if (data.value != self.other) {
self.$select.options({width: self.options.width})
.removeClass('OxOverlapRight')
self.$input.hide();
self.options.value = data.value
} else {
self.$select.options({width: self.otherWidth})
.addClass('OxOverlapRight');
self.$input.show().focusInput(true);
self.options.value = self.$input.value();
}
self.options.value = getValue();
setValue(self.isOther);
}
});
@ -63,11 +49,14 @@ Ox.SelectInput = function(options, self) {
})
.hide();
setValue();
that = Ox.FormElementGroup({
elements: [
self.$select,
self.$input
],
id: self.options.id,
join: function(value) {
return value[value[0] == self.other ? 1 : 0]
},
@ -79,8 +68,62 @@ Ox.SelectInput = function(options, self) {
width: self.options.width
});
function getTitle() {
var value = self.$select ? self.$select.value() : self.options.value;
return Ox.isEmpty(value)
? self.options.title
: Ox.getObjectById(self.options.items, value).title;
}
function getValue() {
self.isOther = self.$select.value() == self.other;
return !self.isOther ? self.$select.value() : self.$input.value();
}
function setValue(isOther) {
Ox.print('SET VALUE', isOther)
if (
(!self.options.value && isOther !== true)
|| Ox.map(self.options.items, function(item) {
return item.id != self.other ? item.id : null;
}).indexOf(self.options.value) > -1
) {
self.$select.options({
title: !self.options.value
? self.options.title
: Ox.getObjectById(self.options.items, self.options.value).title,
value: self.options.value,
width: self.options.width
})
.removeClass('OxOverlapRight');
self.$input.hide().value('');
} else {
self.$select.options({
title: Ox.getObjectById(self.options.items, self.other).title,
value: self.other,
width: self.otherWidth
})
.addClass('OxOverlapRight');
self.$input.show().value(self.options.value);
}
self.$select.options({title: getTitle()});
}
self.setOption = function(key, value) {
// ...
if (key == 'value') {
setValue();
}
};
that.value = function() {
if (arguments.length == 0) {
return getValue();
} else {
self.options.value = arguments[0];
Ox.print('SOV:::', self.options.value)
setValue();
return that;
}
};
return that;

View file

@ -14,33 +14,44 @@ Ox.Spreadsheet = function(options, self) {
rowTitleType: 'str',
rowTitleWidth: 128,
title: '',
value: []
value: {}
})
.options(options || {})
.addClass('OxSpreadsheet');
self.values = [];
self.options.rows.forEach(function(row, r) {
self.values.push([]);
self.options.columns.forEach(function(column, c) {
self.values[r].push(0);
if (Ox.isEmpty(self.options.value)) {
self.options.value = {
columns: [],
rows: [],
values: []
}
Ox.loop(4, function(i) {
self.options.value.columns.push('');
self.options.value.rows.push('');
self.options.value.values.push([0, 0, 0, 0]);
});
});
self.sums = getSums();
} else if (Ox.isEmpty(self.options.value.values)) {
self.options.value.rows.forEach(function(row, r) {
self.options.value.values.push([]);
self.options.value.columns.forEach(function(column, c) {
self.options.value.values[r].push(0);
});
});
}
renderSpreadsheet();
function addColumn(index) {
self.options.columns.splice(index, 0, '');
self.values.forEach(function(columns) {
self.options.value.columns.splice(index, 0, '');
self.options.value.values.forEach(function(columns) {
columns.splice(index, 0, 0);
});
renderSpreadsheet();
}
function addRow(index) {
self.options.rows.splice(index, 0, '');
self.values.splice(index, 0, Ox.repeat([0], self.columns));
self.options.value.rows.splice(index, 0, '');
self.options.value.values.splice(index, 0, Ox.repeat([0], self.columns));
renderSpreadsheet();
}
@ -50,7 +61,7 @@ Ox.Spreadsheet = function(options, self) {
row: Ox.repeat([0], self.rows),
sheet: 0
};
self.values.forEach(function(columns, r) {
self.options.value.values.forEach(function(columns, r) {
columns.forEach(function(value, c) {
sums.column[c] += value;
sums.row[r] += value;
@ -61,23 +72,23 @@ Ox.Spreadsheet = function(options, self) {
}
function removeColumn(index) {
self.options.columns.splice(index, 1);
self.values.forEach(function(columns) {
self.options.value.columns.splice(index, 1);
self.options.value.values.forEach(function(columns) {
columns.splice(index, 1);
});
renderSpreadsheet();
}
function removeRow(index) {
self.options.rows.splice(index, 1);
self.values.splice(index, 1);
self.options.value.rows.splice(index, 1);
self.options.value.values.splice(index, 1);
renderSpreadsheet();
}
function renderSpreadsheet() {
self.columns = self.options.columns.length;
self.rows = self.options.rows.length;
self.columns = self.options.value.columns.length;
self.rows = self.options.value.rows.length;
self.sums = getSums();
self.$input = {};
@ -88,9 +99,9 @@ Ox.Spreadsheet = function(options, self) {
height: 16 * (self.rows + 2) + 'px'
});
Ox.merge([self.options.title], Ox.clone(self.options.rows), ['Total']).forEach(function(row, r) {
Ox.merge([self.options.title], Ox.clone(self.options.value.rows), ['Total']).forEach(function(row, r) {
r--;
Ox.merge([''], Ox.clone(self.options.columns), ['Total']).forEach(function(column, c) {
Ox.merge([''], Ox.clone(self.options.value.columns), ['Total']).forEach(function(column, c) {
c--;
if (r == -1) {
if (c == -1 || c == self.columns) {
@ -131,7 +142,7 @@ Ox.Spreadsheet = function(options, self) {
})
.bindEvent({
change: function(data) {
self.options.columns[c] = data.value;
self.options.value.columns[c] = data.value;
triggerChangeEvent();
}
})
@ -169,7 +180,7 @@ Ox.Spreadsheet = function(options, self) {
})
.bindEvent({
change: function(data) {
self.options.rows[r] = data.value;
self.options.value.rows[r] = data.value;
triggerChangeEvent();
}
})
@ -197,13 +208,13 @@ Ox.Spreadsheet = function(options, self) {
value: isSheetSum ? self.sums.sheet
: isColumnSum ? self.sums.column[c]
: isRowSum ? self.sums.row[r]
: self.values[r][c],
: self.options.value.values[r][c],
width: self.options.columnWidth
})
.appendTo(that);
!isSum && self.$input[id].bindEvent({
change: function(data) {
self.values[r][c] = parseInt(data.value);
self.options.value.values[r][c] = parseInt(data.value);
self.sums = getSums();
self.$input[c + ',' + self.rows].value(self.sums.column[c]);
self.$input[self.columns + ',' + r].value(self.sums.row[r]);
@ -220,18 +231,10 @@ Ox.Spreadsheet = function(options, self) {
function triggerChangeEvent() {
that.triggerEvent('change', {
value: that.value()
value: self.options.value
});
}
that.value = function() {
return {
columns: self.options.columns,
rows: self.options.rows,
values: self.values
};
};
return that;
};

View file

@ -65,6 +65,7 @@
'Check', 'Embed', 'Bracket',
'Upload', 'Download',
'Copyright', 'NoCopyright',
'List', 'Grid', 'Map', 'Calendar',
'Click', 'Delete', 'Edit', 'Find', 'Flag', 'Icon', 'Like',
'Mail', 'Publish', 'Set', 'Star', 'User', 'View', 'Loading'
].forEach(function(symbol) {

View file

@ -643,7 +643,9 @@ Ox.some <f> Tests if one or more elements of a collection satisfy a given condit
true
@*/
Ox.some = function(obj, fn) {
return Ox.filter(Ox.values(obj), fn).length > 0;
return Ox.filter(Ox.values(obj), fn || function(v) {
return v;
}).length > 0;
};
/*@

View file

@ -125,13 +125,56 @@ Ox.load = function() {
});
};
/*@
Ox.localStorage <o> localStorage wrapper
() -> <o> key:value pairs
(key) -> <*> value
(key, val) -> <f> localStorage object
({key, val}) -> <f> localStorage object
@*/
Ox.localStorage = function(namespace) {
// Ox.Log calls this before Ox.isUndefined is defined
if (localStorage === void 0) {
localStorage = {};
}
function storage(key, val) {
var ret, value;
if (arguments.length == 0) {
ret = {};
Ox.forEach(localStorage, function(val, key) {
if (Ox.startsWith(key, namespace + '.')) {
ret[key.substr(namespace.length + 1)] = JSON.parse(val);
}
});
} else if (arguments.length == 1 && !Ox.isObject(key)) {
value = localStorage[namespace + '.' + key];
ret = Ox.isUndefined(value) ? void 0 : JSON.parse(value);
} else {
args = Ox.makeObject(arguments);
Ox.forEach(args, function(val, key) {
localStorage[namespace + '.' + key] = JSON.stringify(val);
});
ret = this;
}
return ret;
};
storage.delete = function(key) {
var keys = arguments.length == 0
? Object.keys(storage())
: [key];
keys.forEach(function(key) {
delete localStorage[namespace + '.' + key];
});
};
return storage;
};
/*@
Ox.Log <f> Logging module
@*/
Ox.Log = (function() {
var log = localStorage && localStorage.OxLog
? JSON.parse(localStorage.OxLog)
: {filter: [], filterEnabled: true},
var storage = Ox.localStorage('Ox'),
log = storage('Log') || {filter: [], filterEnabled: true},
that = function() {
var ret;
if (arguments.length == 0) {
@ -141,16 +184,11 @@ Ox.Log = (function() {
}
return ret;
};
function save() {
if (localStorage) {
localStorage.OxLog = JSON.stringify(log);
}
}
that.filter = function(val) {
if (!Ox.isUndefined(val)) {
that.filter.enable();
log.filter = Ox.toArray(val);
save();
storage('Log', log);
}
return log.filter;
};
@ -159,11 +197,11 @@ Ox.Log = (function() {
};
that.filter.disable = function() {
log.filterEnabled = false;
save();
storage('Log', log);
};
that.filter.enable = function() {
log.filterEnabled = true;
save();
storage('Log', log);
};
that.filter.remove = function(val) {
val = Ox.toArray(val);
@ -176,9 +214,7 @@ Ox.Log = (function() {
if (!log.filterEnabled || log.filter.indexOf(args[0]) > -1) {
date = new Date();
args.unshift(
Ox.formatDate(date, '%H:%M:%S.') + (+date).toString().substr(-3)/*,
(arguments.callee.caller && arguments.callee.caller.name)
|| '(anonymous)'*/
Ox.formatDate(date, '%H:%M:%S.') + (+date).toString().substr(-3)
);
window.console && window.console.log.apply(window.console, args);
ret = args.join(' ');

View file

@ -137,6 +137,36 @@ Ox.isEqual = function(a, b) {
return isEqual;
};
/*@
Ox.isFalsy <f> Returns true for undefined, null, false, 0, '', [], {}
(value) -> <b> True if the value is falsy
value <*> Any value
> Ox.isFalsy(void 0)
true
> Ox.isFalsy(null)
true
> Ox.isFalsy(false)
true
> Ox.isFalsy(0)
true
> Ox.isFalsy('')
true
> Ox.isFalsy([])
true
> Ox.isFalsy({})
true
> Ox.isFalsy(NaN)
false
> Ox.isFalsy(function() {})
false
> Ox.isFalsy(/ /)
false
@*/
Ox.isFalsy = function(val) {
return (!val && !Ox.isNaN(val))
|| (Ox.isEmpty(val) && !Ox.isFunction(val));
};
/*@
Ox.isFunction <f> Tests if a value is a function
(value) -> <b> True if the value is a function
@ -261,8 +291,7 @@ Ox.isUndefined <f> Tests if a value is undefined
@*/
Ox.isUndefined = function(val) {
// fixme: val === void 0 is also nice
return typeof val == 'undefined';
return val === void 0;
};
/*@

View file

@ -32,7 +32,7 @@ def build_oxjs(geo):
for theme in ['classic', 'modern']:
path = source_path + 'Ox.UI/themes/' + theme + '/svg/'
for filename in os.listdir(path):
if not filename[0] in '._':
if not filename[0] in '._' and not filename.endswith('~'):
key = theme + '/' + filename[:-4]
imageURLs[key] = os.path.join(path, filename).replace(source_path, '')
data = re.sub('\n\s+', '', read_file(path + filename))
@ -46,7 +46,8 @@ def build_oxjs(geo):
ui_files = {'build': [], 'dev': []}
for path, dirnames, filenames in os.walk(source_path):
for filename in filenames:
if not '_' in path and not filename[0] in '._'\
if not '_' in path and not filename[0] in '._' \
and not filename.endswith('~') \
and (geo or not '/Ox.Geo/' in path):
# write copies in build path
source = os.path.join(path, filename)
@ -77,6 +78,7 @@ def build_oxjs(geo):
write_link(link_source, link_target)
# Ox.js
# FIXME: Document what exactly the following dependecies are!
filenames = [
['Fallback.js', 'Core.js'],
['Collection.js', 'Math.js']
@ -90,7 +92,9 @@ def build_oxjs(geo):
data[1].append(js_dir + filename)
filenames = filenames[0] + filenames[1]
for filename in os.listdir(source_path + js_dir):
if not filename in filenames:
if not filename in filenames \
and not filename.startswith('.') \
and not filename.endswith('~'):
filenames.append(filename)
for filename in filenames:
js += read_file(source_path + js_dir + filename) + '\n'
@ -109,6 +113,7 @@ def build_oxjs(geo):
# svgs are loaded as URLs or dataURLs
# browser images appear before load
if path != root and not '_' in path and not filename[0] in '._'\
and not filename.endswith('~') \
and not 'jquery' in filename\
and not ('/themes/' in path and filename.endswith('.css'))\
and not filename.endswith('.svg')\