'use strict'; /*@ Ox.App Basic application instance that communicates with a JSON API ([options]) -> App object load app loaded options Options object timeout request timeout type HTTP Request type, i.e. 'GET' or 'POST' url JSON API url self Shared private variable @*/ Ox.App = function(options) { var self = { options: Ox.extend({ name: 'App', timeout: 60000, type: 'POST', url: '/api/' }, options || {}), time: new Date() }, that = Ox.Element({}, Ox.extend({}, self)); //@ api api endpoint that.api = Ox.API({ type: self.options.type, timeout: self.options.timeout, url: self.options.url }, function() { that.api.init(getUserData(), function(result) { //Ox.UI.hideLoadingScreen(); that.triggerEvent({ load: result.data }); }); }); //@ localStorage Ox.localStorage instance that.localStorage = Ox.localStorage(self.options.name); function getUserData() { return { document: { referrer: document.referrer }, history: { length: history.length }, location: { href: location.href }, navigator: { cookieEnabled: navigator.cookieEnabled, plugins: Ox.toArray(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 } }; } /*@ options get/set options, see Ox.getset () -> get options (options) -> update/set options @*/ that.options = function() { return Ox.getset(self.options, Array.prototype.slice.call(arguments), self.change, that); }; return that; };