oxjs/source/Ox.UI/js/Core/Ox.App.js

90 lines
2.4 KiB
JavaScript
Raw Normal View History

2011-07-29 18:48:43 +00:00
// vim: et:ts=4:sw=4:sts=4:ft=javascript
2011-04-22 22:03:10 +00:00
2011-11-05 16:46:53 +00:00
'use strict';
2011-05-16 08:24:46 +00:00
/*@
Ox.App <f> Basic application instance that communicates with a JSON API
() -> <f> App object
(options) -> <f> App object
options <o> Options object
timeout <n> request timeout
2011-05-16 10:49:48 +00:00
type <s> HTTP Request type, i.e. 'GET' or 'POST'
2011-05-16 08:24:46 +00:00
url <s> JSON API url
self <o> Shared private variable
load <!> app loaded
@*/
2011-04-22 22:03:10 +00:00
Ox.App = function(options) {
2011-04-22 22:03:10 +00:00
2011-09-17 11:49:29 +00:00
var self = {
options: Ox.extend({
timeout: 60000,
type: 'POST',
url: '/api/'
2011-09-17 11:49:29 +00:00
}, options || {}),
time: new Date()
},
that = Ox.Element({}, Ox.extend({}, self));
2011-04-22 22:03:10 +00:00
2011-12-21 15:40:06 +00:00
that.api = Ox.API({
2011-09-17 11:49:29 +00:00
type: self.options.type,
timeout: self.options.timeout,
2011-09-17 11:49:29 +00:00
url: self.options.url
}, function() {
2011-09-17 11:49:29 +00:00
that.api.init(getUserData(), function(result) {
//Ox.UI.hideLoadingScreen();
that.triggerEvent({
load: result.data
2011-04-23 17:28:21 +00:00
});
});
2011-09-17 11:49:29 +00:00
});
2011-04-22 22:03:10 +00:00
2011-09-17 11:49:29 +00:00
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
}
2011-04-22 22:03:10 +00:00
};
2011-09-17 11:49:29 +00:00
}
2011-04-22 22:03:10 +00:00
2011-09-17 11:49:29 +00:00
/*@
change <f> change key/value
(key, value) -> <u> currently not implemented
@*/
self.setOption = 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);
};
2011-04-22 22:03:10 +00:00
2011-09-17 11:49:29 +00:00
return that;
2011-04-22 22:03:10 +00:00
};