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
|
|
|
|
2011-06-19 17:48:32 +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({
|
2011-12-30 15:06:55 +00:00
|
|
|
name: 'App',
|
2011-09-17 11:49:29 +00:00
|
|
|
timeout: 60000,
|
|
|
|
type: 'POST',
|
2011-12-21 10:54:17 +00:00
|
|
|
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,
|
2011-12-21 10:54:17 +00:00
|
|
|
timeout: self.options.timeout,
|
2011-09-17 11:49:29 +00:00
|
|
|
url: self.options.url
|
2011-12-21 10:54:17 +00:00
|
|
|
}, 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-12-30 15:06:55 +00:00
|
|
|
that.localStorage = Ox.localStorage(self.options.name);
|
|
|
|
|
2011-09-17 11:49:29 +00:00
|
|
|
function getUserData() {
|
|
|
|
return {
|
|
|
|
document: {
|
|
|
|
referrer: document.referrer
|
|
|
|
},
|
|
|
|
history: {
|
|
|
|
length: history.length
|
|
|
|
},
|
2012-02-05 03:10:26 +00:00
|
|
|
location: {
|
|
|
|
href: location.href
|
|
|
|
},
|
2011-09-17 11:49:29 +00:00
|
|
|
navigator: {
|
|
|
|
cookieEnabled: navigator.cookieEnabled,
|
2012-05-19 08:40:59 +00:00
|
|
|
plugins: Ox.toArray(navigator.plugins).map(function(plugin) {
|
2011-09-17 11:49:29 +00:00
|
|
|
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
|
|
|
|
2011-06-19 17:48:32 +00:00
|
|
|
};
|