app.launch
This commit is contained in:
parent
6117bc31c3
commit
1a1f8c9107
2 changed files with 85 additions and 17 deletions
|
@ -28,27 +28,33 @@ 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,
|
||||
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) {
|
||||
|
|
|
@ -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, {
|
||||
|
|
Loading…
Reference in a new issue