app.launch

This commit is contained in:
rolux 2010-09-05 02:31:58 +02:00
parent 6117bc31c3
commit 1a1f8c9107
2 changed files with 85 additions and 17 deletions

View file

@ -28,27 +28,33 @@ Ox.getset = function(obj, args, callback, context) {
/* /*
generic getter and setter function generic getter and setter function
Ox.getset(obj) returns obj Ox.getset(obj) returns obj
Ox.getset(obj, str) returns obj.str Ox.getset(obj, [key]) returns obj.key
Ox.getset(obj, {key: val, ...}, callback, context) sets obj.key to val, Ox.getset(obj, [key, val], callback, context)
Ox.getset(obj, [{key: val, ...}], callback, context) sets obj.key to val,
calls callback(key, val), calls callback(key, val),
returns context returns context
*/ */
var obj_ = obj, var obj_ = obj,
args = args || {}, args_ = {},
callback = callback || function() {}, args = args || [],
callback = callback || {},
context = context || {}, context = context || {},
length = args.length, length = args.length,
ret; ret;
if (length == 0) { if (length == 0) {
// getset() // getset()
ret = obj; ret = obj;
} else if (length == 1 && typeof arguments[0] == "string") { } else if (length == 1 && Ox.isString(args[0])) {
// getset(str) // getset(str)
ret = obj[args[0]] ret = obj[args[0]]
} else { } else {
// getset(str, val) or getset({str: val, ...}) // getset(str, val) or getset({str: val, ...})
// translate (str, val) to ({str: val}) if (length == 1) {
args = Ox.makeObject(args); args = args[0];
} else {
args_[args[0]] = args[1];
args = args_;
}
obj = $.extend(obj, args); obj = $.extend(obj, args);
$.each(args, function(key, value) { $.each(args, function(key, value) {
if (!obj_ || !obj_[key] || obj_[key] !== value) { if (!obj_ || !obj_[key] || obj_[key] !== value) {

View file

@ -137,25 +137,86 @@ requires
that = this; that = this;
self.options = $.extend({ self.options = $.extend({
requestTimeout: oxui.requestTimeout, id: '',
requestType: oxui.requestType, init: '',
requestURL: oxui.requestURL name: '',
requestTimeout: 15000,
requestType: 'POST',
requestURL: '',
}, options); }, 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) { self.change = function(key, value) {
}; };
that.launch = function() { that.launch = function(callback) {
var time = +new Date();
document.title = self.options.name;
$.ajaxSetup({ $.ajaxSetup({
timeout: self.options.requestTimeout, timeout: self.options.requestTimeout,
type: self.options.requestType, type: self.options.requestType,
url: self.options.requestURL 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() { 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) { that.request = function(action, data, callback) {
@ -1735,7 +1796,8 @@ requires
}, 200); }, 200);
center(); center();
reset(); reset();
that.gainFocus(); // fixme: reenable, but implement preview-style dialog
//that.gainFocus();
$window.bind('mouseup', mouseupLayer) $window.bind('mouseup', mouseupLayer)
return that; return that;
}; };
@ -2246,7 +2308,7 @@ requires
), function(v, i) { ), function(v, i) {
return v + (i < self.options.checkboxes.length - 1 ? 10 : 0); return v + (i < self.options.checkboxes.length - 1 ? 10 : 0);
}) })
}) });
$.each(self.options.checkboxes, function(position, checkbox) { $.each(self.options.checkboxes, function(position, checkbox) {
var id = self.options.id + Ox.toTitleCase(checkbox.id) var id = self.options.id + Ox.toTitleCase(checkbox.id)
self.$checkboxes[position] = new Ox.Checkbox($.extend(checkbox, { self.$checkboxes[position] = new Ox.Checkbox($.extend(checkbox, {