From 5569f7a797dc42b4b3ab39b2578daf9956ccd587 Mon Sep 17 00:00:00 2001 From: rolux Date: Sun, 5 Sep 2010 02:31:58 +0200 Subject: [PATCH] app.launch --- build/js/ox.js | 26 +++++++++------- build/js/ox.ui.js | 76 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 85 insertions(+), 17 deletions(-) diff --git a/build/js/ox.js b/build/js/ox.js index 5ede579..8491deb 100644 --- a/build/js/ox.js +++ b/build/js/ox.js @@ -27,28 +27,34 @@ Core functions Ox.getset = function(obj, args, callback, context) { /* generic getter and setter function - Ox.getset(obj) returns obj - Ox.getset(obj, str) returns obj.str - Ox.getset(obj, {key: val, ...}, callback, context) sets obj.key to val, - calls callback(key, val), - returns context + Ox.getset(obj) returns obj + Ox.getset(obj, [key]) returns obj.key + Ox.getset(obj, [key, val], callback, context) + Ox.getset(obj, [{key: val, ...}], callback, context) sets obj.key to val, + calls callback(key, val), + returns context */ var obj_ = obj, - args = args || {}, - callback = callback || function() {}, + args_ = {}, + args = args || [], + callback = callback || {}, context = context || {}, length = args.length, ret; if (length == 0) { // getset() ret = obj; - } else if (length == 1 && typeof arguments[0] == "string") { + } else if (length == 1 && Ox.isString(args[0])) { // getset(str) ret = obj[args[0]] } else { // getset(str, val) or getset({str: val, ...}) - // translate (str, val) to ({str: val}) - args = Ox.makeObject(args); + if (length == 1) { + args = args[0]; + } else { + args_[args[0]] = args[1]; + args = args_; + } obj = $.extend(obj, args); $.each(args, function(key, value) { if (!obj_ || !obj_[key] || obj_[key] !== value) { diff --git a/build/js/ox.ui.js b/build/js/ox.ui.js index 39a125d..1025128 100644 --- a/build/js/ox.ui.js +++ b/build/js/ox.ui.js @@ -137,25 +137,86 @@ requires that = this; self.options = $.extend({ - requestTimeout: oxui.requestTimeout, - requestType: oxui.requestType, - requestURL: oxui.requestURL + id: '', + init: '', + name: '', + requestTimeout: 15000, + requestType: 'POST', + requestURL: '', }, options); + function getUserData() { + //return {}; + return { + navigator: { + cookieEnabled: navigator.cookieEnabled, + plugins: $.map(navigator.plugins, function(plugin, i) { + return plugin.name; + }), + userAgent: navigator.userAgent + }, + screen: screen, + window: { + innerHeight: window.innerHeight, + innerWidth: window.innerWidth, + outerHeight: window.outerHeight, + outerWidth: window.outerWidth, + screenLeft: window.screenLeft, + screenTop: window.screenTop + } + }; + } + + function loadImages(callback) { + $.getJSON(oxui.path + 'json/ox.ui.images.json', function(data) { + var counter = 0, + length = data.length; + data.forEach(function(src, i) { + image = new Image() + image.src = oxui.path + src; + image.onload = function() { + (++counter == length) && callback(); + } + }); + }); + } + self.change = function(key, value) { }; - that.launch = function() { + that.launch = function(callback) { + var time = +new Date(); + document.title = self.options.name; $.ajaxSetup({ timeout: self.options.requestTimeout, type: self.options.requestType, url: self.options.requestURL }); + loadImages(function() { + window.google = function() {}; + $.getScript('http://maps.google.com/maps/api/js?callback=google&sensor=false', function() { + $.getJSON(self.options.config, function(data) { + var config = data; + that.request(self.options.init, $.extend(getUserData(), { + time: (+new Date() - time) / 1000 + }), function(data) { + Ox.print('!!!', data) + var user = data.data.user + $body.empty(); + callback({ + config: config, + user: user + }); + }); + }); + }); + }); + return that; }; that.options = function() { - return Ox.getset(self.options, Array.slice.call(arguments), self.change, that); + return Ox.getset(self.options, Array.prototype.slice.call(arguments), self.change, that); }; that.request = function(action, data, callback) { @@ -1735,7 +1796,8 @@ requires }, 200); center(); reset(); - that.gainFocus(); + // fixme: reenable, but implement preview-style dialog + //that.gainFocus(); $window.bind('mouseup', mouseupLayer) return that; }; @@ -2246,7 +2308,7 @@ requires ), function(v, i) { return v + (i < self.options.checkboxes.length - 1 ? 10 : 0); }) - }) + }); $.each(self.options.checkboxes, function(position, checkbox) { var id = self.options.id + Ox.toTitleCase(checkbox.id) self.$checkboxes[position] = new Ox.Checkbox($.extend(checkbox, {