better Ox.documentReady
This commit is contained in:
parent
e7b870d3cb
commit
ecde8e7f87
6 changed files with 31 additions and 19 deletions
|
@ -3,8 +3,7 @@
|
|||
<head>
|
||||
<title>ox.js list demo</title>
|
||||
<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/OxUI.js"></script>
|
||||
<script type="text/javascript" src="../../build/js/Ox.js"></script>
|
||||
<script type="text/javascript" src="js/list.js"></script>
|
||||
</head>
|
||||
<body></body>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
Ox.UI(function() {
|
||||
Ox.load('UI', function() {
|
||||
|
||||
Ox.theme('modern');
|
||||
Ox.Theme('modern');
|
||||
|
||||
var $treeList = new Ox.TreeList({
|
||||
items: [
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
<head>
|
||||
<title>OxJS Mouse Events Demo</title>
|
||||
<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/OxUI.js"></script>
|
||||
<script type="text/javascript" src="../../build/js/Ox.js"></script>
|
||||
<script type="text/javascript" src="js/mouse.js"></script>
|
||||
</head>
|
||||
<body></body>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
Ox.UI(function() {
|
||||
Ox.load('UI', function() {
|
||||
var $target = Ox.Element()
|
||||
.css({
|
||||
position: 'absolute',
|
||||
|
|
|
@ -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.')
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}());
|
||||
|
|
Loading…
Reference in a new issue