From 6c0d7cd3ca05a7960ca01492cf53bbe06c3571f5 Mon Sep 17 00:00:00 2001 From: rolux Date: Sat, 23 Apr 2011 19:28:21 +0200 Subject: [PATCH] updating Ox.App --- source/js/Ox.App.js | 158 +++++++++++++++++--------------------------- source/js/OxUI.js | 26 +++----- 2 files changed, 69 insertions(+), 115 deletions(-) diff --git a/source/js/Ox.App.js b/source/js/Ox.App.js index 4696bca8..172299c4 100644 --- a/source/js/Ox.App.js +++ b/source/js/Ox.App.js @@ -5,7 +5,7 @@ Application ============================================================================ */ -// fixme: get rid og launch, fire load event +// fixme: get rid of launch, fire load event Ox.App = (function() { @@ -22,42 +22,75 @@ Ox.App = (function() { Methods api[action] make a request api.cancel cancel a request - launch launch the App options get or set options + Events + load app loaded ***/ return function(options) { options = options || {}; - var self = {}, - that = this; + var self = { + options: Ox.extend({ + timeout: 60000, + type: 'POST', + url: '/api/', + }, options || {}), + time: new Date() + }, + that = Ox.Element(); - self.time = +new Date(); + that.api = { + api: function(callback) { + Ox.Request.send({ + url: self.options.url, + data: { + action: 'api' + }, + callback: callback + }); + }, + cancel: function(id) { + Ox.Request.cancel(id); + } + }; - self.options = $.extend({ - timeout: 60000, - type: 'POST', - url: '/api/', - }, options); + $.ajaxSetup({ + timeout: self.options.timeout, + type: self.options.type, + url: self.options.url + }); - that.$element = new Ox.Element('body'); - - function getUserAgent() { - var userAgent = ''; - Ox.forEach(['Chrome', 'Firefox', 'Internet Explorer', 'Opera', 'Safari'], function(v) { - if (navigator.userAgent.indexOf(v) > -1) { - userAgent = v; - return false; - } + that.api.api(function(result) { + Ox.forEach(result.data.actions, function(val, key) { + that.api[key] = function(data, callback) { + if (arguments.length == 1 && Ox.isFunction(data)) { + callback = data; + data = {}; + } + return Ox.Request.send($.extend({ + url: self.options.url, + data: { + action: key, + data: JSON.stringify(data) + }, + callback: callback + }, !val.cache ? {age: 0}: {})); + }; }); - if (!userAgent && $.browser.mozilla) { - userAgent = 'Firefox'; - } - if (!userAgent && $.browser.webkit) { - userAgent = 'Chrome'; - } - return userAgent; - } + that.api.init(getUserData(), function(result) { + var $div = Ox.UI.$body.find('div'); + Ox.UI.$body.find('img').remove(); + $div.animate({ + opacity: 0 + }, 1000, function() { + $div.remove(); + }); + that.triggerEvent({ + load: result.data + }); + }); + }); function getUserData() { return { @@ -91,81 +124,10 @@ Ox.App = (function() { }; - that.api = { - api: function(callback) { - Ox.Request.send({ - url: self.options.url, - data: { - action: 'api' - }, - callback: callback - }); - }, - cancel: function(id) { - Ox.Request.cancel(id); - } - }; - that.bindEvent = function() { }; - // fixme: use $.when() - that.launch = function(callback) { - var time = +new Date(), - userAgent = getUserAgent(), - userAgents = ['Chrome', 'Firefox', 'Opera', 'Safari']; - $.ajaxSetup({ - timeout: self.options.timeour, - type: self.options.type, - url: self.options.url - }); - userAgents.indexOf(userAgent) > -1 ? start() : stop(); - function start() { - // fixme: rename config to site? - var counter = 0, config, user; - that.api.api(function(result) { - Ox.forEach(result.data.actions, function(val, key) { - that.api[key] = function(data, callback) { - if (arguments.length == 1 && Ox.isFunction(data)) { - callback = data; - data = {}; - } - return Ox.Request.send($.extend({ - url: self.options.url, - data: { - action: key, - data: JSON.stringify(data) - }, - callback: callback - }, !val.cache ? {age: 0}: {})); - }; - }); - that.api.init(getUserData(), function(result) { - config = result.data.config; - user = result.data.user; - // fixme: not generic - document.title = config.site.name; - $(function() { - var $div = Ox.UI.$body.find('div'); - Ox.UI.$body.find('img').remove(); - $div.animate({ - opacity: 0 - }, 1000, function() { - $div.remove(); - }); - // fixme: not generic enough, just pass data - callback({config: config, user: user}); - }); - }); - }); - } - function stop() { - that.request.send(self.options.init, getUserData(), function() {}); - } - return that; - }; - that.options = function() { return Ox.getset(self.options, Array.prototype.slice.call(arguments), self.change, that); }; diff --git a/source/js/OxUI.js b/source/js/OxUI.js index 0d3571c1..3a2b002a 100644 --- a/source/js/OxUI.js +++ b/source/js/OxUI.js @@ -32,9 +32,9 @@ Provides function Ox.UI([options], callback) that fires when } }, oxUIOptions = { - // 'icon', 'console' or 'none' - display: 'none', - theme: 'classic' + app: false, + display: 'none', // 'icon', 'console' or 'none' + theme: 'classic' // 'classic' or 'modern }; files.forEach(function(file, i) { @@ -161,7 +161,9 @@ Provides function Ox.UI([options], callback) that fires when 'Consolas', 'Lucida Console' ].join(', '), fontSize: '12px', - color: 'rgb(240, 240, 240)' + color: 'rgb(' + ( + oxUIOptions.theme == 'classic' ? '16, 16, 16' : '240, 240 240' + ) + ')' }) .html(str) .appendTo(element); @@ -376,7 +378,7 @@ Provides function Ox.UI([options], callback) that fires when $.when.apply(null, promises) .done(function() { var $div, error = $('.error').length; - if (!error) { + if (!error && !oxUIOptions.app) { $div = $('div'); $('img').remove(); $div.animate({ @@ -441,7 +443,7 @@ Provides function Ox.UI([options], callback) that fires when }; Ox.UI.elements = {}; - Ox.UI.DEFAULT_THEME = 'classic'; + Ox.UI.DEFAULT_THEME = 'classic'; // fixme: needed? Ox.UI.DIMENSIONS = { horizontal: ['width', 'height'], vertical: ['height', 'width'] @@ -456,23 +458,13 @@ Provides function Ox.UI([options], callback) that fires when filename = 'symbolRight.svg'; } return Ox.UI.PATH + filename.split('.').pop() + - '/ox.ui.' + Ox.UI.theme() + '/' + filename; + '/ox.ui.' + Ox.Theme() + '/' + filename; }; Ox.UI.IMAGE_CACHE = []; Ox.UI.PATH = $('script[src*="OxUI.js"]') .attr('src').replace('js/OxUI.js', ''); Ox.UI.SCROLLBAR_SIZE = $.browser.mozilla ? 16 : 12; // fixme: the follwing should be deprecated - Ox.UI.theme = function() { - var theme; - Ox.forEach(Ox.UI.$body.attr('class').split(' '), function(v) { - if (Ox.startsWith(v, 'OxTheme')) { - theme = v.replace('OxTheme', '').toLowerCase(); - return false; - } - }); - return theme || Ox.UI.DEFAULT_THEME; // fixme: shouldn't be neccessary - }; Ox.UI.getBarSize = function(size) { var sizes = { small: 20,