piskel/piskel-boot.js

77 lines
2.3 KiB
JavaScript
Raw Normal View History

2013-08-11 03:26:38 +04:00
(function () {
window.onPiskelReady = function () {
var loadingMask = document.getElementById('loading-mask');
loadingMask.style.opacity = 0;
window.setTimeout(function () {loadingMask.parentNode.removeChild(loadingMask);}, 600)
pskl.app.init();
// cleanup
delete window.exports;
delete window.loadDebugScripts;
delete window.done;
};
2013-12-19 02:22:25 +04:00
var prefixPath = function (path) {
if (window.pskl && window.pskl.appEngineToken_) {
return '../' + path;
} else {
return path;
}
};
2013-08-11 03:26:38 +04:00
var loadScript = function (src, callback) {
2013-12-19 02:22:25 +04:00
src = prefixPath(src);
2013-08-11 03:26:38 +04:00
var script = window.document.createElement('script');
script.setAttribute('src',src);
script.setAttribute('onload',callback);
window.document.body.appendChild(script);
};
2013-12-19 02:22:25 +04:00
var loadStyle = function (src) {
src = prefixPath(src);
var link = document.createElement('link');
link.setAttribute('href', src);
link.setAttribute('rel', 'stylesheet');
link.setAttribute('type', 'text/css');
document.head.appendChild(link);
};
2013-08-11 03:26:38 +04:00
if (window.location.href.indexOf("debug") != -1) {
window.exports = {};
var scriptIndex = 0;
window.loadNextScript = function () {
if (scriptIndex == window.exports.scripts.length) {
window.onPiskelReady();
2013-08-11 03:26:38 +04:00
} else {
loadScript(window.exports.scripts[scriptIndex], "loadNextScript()");
2013-08-11 03:26:38 +04:00
scriptIndex ++;
}
};
loadScript("piskel-script-list.js", "loadNextScript()");
2013-12-19 02:22:25 +04:00
window.loadStyles = function () {
var styles = window.exports.styles;
for (var i = 0 ; i < styles.length ; i++) {
loadStyle(styles[i]);
}
};
loadScript("piskel-style-list.js", "loadStyles()");
2013-08-11 03:26:38 +04:00
} else {
var script;
if (window.location.href.indexOf("pack") != -1) {
script = "build/piskel-packaged.js";
} else {
script = "build/piskel-packaged-min.js";
}
2013-12-19 02:22:25 +04:00
loadStyle('build/piskel-style-packaged.css');
2013-08-11 03:26:38 +04:00
var loaderInterval = window.setInterval(function () {
2013-12-06 01:12:48 +04:00
if (document.querySelectorAll("[data-iframe-loader]").length === 0) {
2013-08-11 03:26:38 +04:00
window.clearInterval(loaderInterval);
loadScript(script, "onPiskelReady()");
2013-08-11 03:26:38 +04:00
} else {
console.log("waiting for templates to load ....");
}
}, 100);
}
})();