Change onPiskelReady to support multiple callback

This commit is contained in:
Dávid Szabó 2016-08-24 22:43:16 +02:00
parent 9c6871effc
commit d01f4ef83e

View File

@ -9,7 +9,11 @@
version = ''; version = '';
} }
window.onPiskelReady = function () { if (!window.onPiskelReady) {
window.onPiskelReady = [];
}
window._onPiskelReady = function () {
var loadingMask = document.getElementById('loading-mask'); var loadingMask = document.getElementById('loading-mask');
loadingMask.style.opacity = 0; loadingMask.style.opacity = 0;
window.setTimeout(function () {loadingMask.parentNode.removeChild(loadingMask);}, 600); window.setTimeout(function () {loadingMask.parentNode.removeChild(loadingMask);}, 600);
@ -18,6 +22,11 @@
delete window.pskl_exports; delete window.pskl_exports;
delete window.loadDebugScripts; delete window.loadDebugScripts;
delete window.done; delete window.done;
// Run Piskel ready callbacks
for (var i in window.onPiskelReady) {
window.onPiskelReady[i]();
}
}; };
var prefixPath = function (path) { var prefixPath = function (path) {
@ -50,7 +59,7 @@
var scriptIndex = 0; var scriptIndex = 0;
window.loadNextScript = function () { window.loadNextScript = function () {
if (scriptIndex == window.pskl_exports.scripts.length) { if (scriptIndex == window.pskl_exports.scripts.length) {
window.onPiskelReady(); window._onPiskelReady();
} else { } else {
loadScript(window.pskl_exports.scripts[scriptIndex], 'loadNextScript()'); loadScript(window.pskl_exports.scripts[scriptIndex], 'loadNextScript()');
scriptIndex ++; scriptIndex ++;
@ -74,6 +83,6 @@
} }
loadStyle('css/piskel-style-packaged' + version + '.css'); loadStyle('css/piskel-style-packaged' + version + '.css');
loadScript(script, 'onPiskelReady()'); loadScript(script, "_onPiskelReady()");
} }
})(); })();