better Ox.documentReady

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

View file

@ -3,8 +3,7 @@
<head> <head>
<title>ox.js list demo</title> <title>ox.js list demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" href="../../build/css/ox.ui.css"/> <script type="text/javascript" src="../../build/js/Ox.js"></script>
<script type="text/javascript" src="../../build/js/OxUI.js"></script>
<script type="text/javascript" src="js/list.js"></script> <script type="text/javascript" src="js/list.js"></script>
</head> </head>
<body></body> <body></body>

View file

@ -1,6 +1,6 @@
Ox.UI(function() { Ox.load('UI', function() {
Ox.theme('modern'); Ox.Theme('modern');
var $treeList = new Ox.TreeList({ var $treeList = new Ox.TreeList({
items: [ items: [

View file

@ -3,8 +3,7 @@
<head> <head>
<title>OxJS Mouse Events Demo</title> <title>OxJS Mouse Events Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css" href="../../build/css/ox.ui.css"/> <script type="text/javascript" src="../../build/js/Ox.js"></script>
<script type="text/javascript" src="../../build/js/OxUI.js"></script>
<script type="text/javascript" src="js/mouse.js"></script> <script type="text/javascript" src="js/mouse.js"></script>
</head> </head>
<body></body> <body></body>

View file

@ -1,4 +1,4 @@
Ox.UI(function() { Ox.load('UI', function() {
var $target = Ox.Element() var $target = Ox.Element()
.css({ .css({
position: 'absolute', position: 'absolute',

View file

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

View file

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