1
0
Fork 0
forked from 0x2620/oxjs

some bugfixes

This commit is contained in:
rlx 2011-09-17 11:49:29 +00:00
commit ef1fa5fe84
14 changed files with 228 additions and 229 deletions

View file

@ -15,121 +15,121 @@ Ox.App <f> Basic application instance that communicates with a JSON API
Ox.App = function(options) {
options = options || {};
var self = {
options: Ox.extend({
timeout: 60000,
type: 'POST',
url: '/api/',
}, options || {}),
time: new Date()
},
that = Ox.Element({}, self);
var self = {
options: Ox.extend({
timeout: 60000,
type: 'POST',
url: '/api/',
}, options || {}),
time: new Date()
},
that = Ox.Element({}, Ox.extend({}, self));
that.api = {
api: function(callback) {
Ox.Request.send({
url: self.options.url,
data: {
action: 'api'
},
callback: callback
that.api = {
api: function(callback) {
Ox.Request.send({
url: self.options.url,
data: {
action: 'api'
},
callback: callback
});
},
cancel: function(id) {
Ox.Request.cancel(id);
}
};
$.ajaxSetup({
timeout: self.options.timeout,
type: self.options.type,
url: self.options.url
});
/*@
api <o> bakcend API
[action] <f> all api requests available on backend
cancel <f> cancel a request
options <f> get or set options
@*/
that.api.api(function(result) {
Ox.print('RESULT', result)
Ox.forEach(result.data.actions, function(val, key) {
that.api[key] = function(/*data, age, callback*/) {
var data = {}, age = -1, callback = null;
Ox.forEach(arguments, function(argument) {
if (Ox.isObject(argument)) {
data = argument;
} else if (Ox.isNumber(argument)) {
age = argument;
} else if (Ox.isFunction(argument)) {
callback = argument;
}
});
return Ox.Request.send(Ox.extend({
age: age,
callback: callback,
data: {
action: key,
data: JSON.stringify(data)
},
url: self.options.url
}, !val.cache ? {age: 0}: {}));
};
});
that.api.init(getUserData(), function(result) {
//Ox.UI.hideLoadingScreen();
that.triggerEvent({
load: result.data
});
});
});
function getUserData() {
return {
document: {
referrer: document.referrer
},
cancel: function(id) {
Ox.Request.cancel(id);
history: {
length: history.length
},
navigator: {
cookieEnabled: navigator.cookieEnabled,
plugins: Ox.makeArray(navigator.plugins).map(function(plugin) {
return plugin.name;
}),
userAgent: navigator.userAgent
},
screen: screen,
time: (+new Date() - self.time) / 1000,
window: {
innerHeight: window.innerHeight,
innerWidth: window.innerWidth,
outerHeight: window.outerHeight,
outerWidth: window.outerWidth,
screenLeft: window.screenLeft,
screenTop: window.screenTop
}
};
}
$.ajaxSetup({
timeout: self.options.timeout,
type: self.options.type,
url: self.options.url
});
/*@
change <f> change key/value
(key, value) -> <u> currently not implemented
@*/
self.setOption = function(key, value) {
};
/*@
api <o> bakcend API
[action] <f> all api requests available on backend
cancel <f> cancel a request
options <f> get or set options
@*/
that.api.api(function(result) {
Ox.forEach(result.data.actions, function(val, key) {
that.api[key] = function(/*data, age, callback*/) {
var data = {}, age = -1, callback = null;
Ox.forEach(arguments, function(argument) {
if (Ox.isObject(argument)) {
data = argument;
} else if (Ox.isNumber(argument)) {
age = argument;
} else if (Ox.isFunction(argument)) {
callback = argument;
}
});
return Ox.Request.send(Ox.extend({
age: age,
callback: callback,
data: {
action: key,
data: JSON.stringify(data)
},
url: self.options.url
}, !val.cache ? {age: 0}: {}));
};
});
that.api.init(getUserData(), function(result) {
//Ox.UI.hideLoadingScreen();
that.triggerEvent({
load: result.data
});
});
});
/*@
options <f> get/set options, see Ox.getset
() -> <o> get options
(options) -> <o> update/set options
@*/
that.options = function() {
return Ox.getset(self.options, Array.prototype.slice.call(arguments), self.change, that);
};
function getUserData() {
return {
document: {
referrer: document.referrer
},
history: {
length: history.length
},
navigator: {
cookieEnabled: navigator.cookieEnabled,
plugins: Ox.makeArray(navigator.plugins).map(function(plugin) {
return plugin.name;
}),
userAgent: navigator.userAgent
},
screen: screen,
time: (+new Date() - self.time) / 1000,
window: {
innerHeight: window.innerHeight,
innerWidth: window.innerWidth,
outerHeight: window.outerHeight,
outerWidth: window.outerWidth,
screenLeft: window.screenLeft,
screenTop: window.screenTop
}
};
}
/*@
change <f> change key/value
(key, value) -> <u> currently not implemented
@*/
self.change = function(key, value) {
};
/*@
options <f> get/set options, see Ox.getset
() -> <o> get options
(options) -> <o> update/set options
@*/
that.options = function() {
return Ox.getset(self.options, Array.prototype.slice.call(arguments), self.change, that);
};
return that;
return that;
};