1
0
Fork 0
forked from 0x2620/oxjs

better Ox.documentReady

This commit is contained in:
rolux 2011-04-25 12:07:09 +02:00
commit ecde8e7f87
6 changed files with 31 additions and 19 deletions

View file

@ -43,6 +43,8 @@ Ox.load.UI = function(options, callback) {
function showScreen() {
console.log('showScreen')
var body = Ox.element('body'),
css = {
position: 'absolute',
@ -154,10 +156,17 @@ Ox.load.UI = function(options, callback) {
Ox.loadFile(Ox.PATH + 'js/jquery/jquery.js', function() {
initUI();
$.getJSON(Ox.PATH + 'json/Ox.UI.json', function(files) {
var counter = 0;
var promises = [];
files.forEach(function(file) {
var dfd = new $.Deferred();
Ox.loadFile(Ox.PATH + file, function() {
++counter == files.length && Ox.documentReady(function() {
dfd.resolve();
});
promises.push(dfd.promise())
});
$.when.apply(null, promises)
.done(function() {
$(function() {
var $div;
Ox.Theme(options.theme);
if (browserSupported && options.showScreen && options.hideScreen) {
@ -171,8 +180,10 @@ Ox.load.UI = function(options, callback) {
}
callback(browserSupported);
});
})
.fail(function() {
throw new Error('File not found.')
});
});
});
});

View file

@ -1237,19 +1237,22 @@ Ox.canvas = function() {
Ox.documentReady = (function() {
var callbacks = [];
document.addEventListener('DOMContentLoaded', ready, false);
function ready() {
document.removeEventListener('DOMContentLoaded', ready, false);
callbacks.forEach(function(callback) {
callback();
});
delete callbacks;
}
document.onreadystatechange = function() {
if (document.readyState == 'complete') {
Ox.print('document has become ready', callbacks);
callbacks.forEach(function(callback) {
callback();
});
delete callbacks;
}
};
return function(callback) {
if (document.readyState == 'complete') {
Ox.print('document is ready')
callback();
} else {
callbacks.push(callback);
callbacks.push(callback);
Ox.print('document is not ready', callbacks)
}
}
}());