piskel/piskel-boot-0.1.0.js

83 lines
2.5 KiB
JavaScript
Raw Normal View History

(function () {
2014-07-12 02:22:15 +04:00
var version = '-2014-07-12-12-20';
2014-07-08 22:07:38 +04:00
var versionHasNotBeenReplaced = version.indexOf('@@') === 0;
if (versionHasNotBeenReplaced) {
version = '';
}
2014-03-30 05:12:56 +04:00
window.onPiskelReady = function () {
var loadingMask = document.getElementById('loading-mask');
loadingMask.style.opacity = 0;
2014-07-08 22:07:38 +04:00
window.setTimeout(function () {loadingMask.parentNode.removeChild(loadingMask);}, 600);
2014-03-30 05:12:56 +04:00
pskl.app.init();
// cleanup
2014-05-17 02:04:55 +04:00
delete window.pskl_exports;
2014-03-30 05:12:56 +04:00
delete window.loadDebugScripts;
delete window.done;
};
var prefixPath = function (path) {
if (window.pskl && window.pskl.appEngineToken_) {
return '../' + path;
} else {
return path;
}
};
var loadScript = function (src, callback) {
2014-03-30 05:12:56 +04:00
src = prefixPath(src);
var script = window.document.createElement('script');
script.setAttribute('src',src);
script.setAttribute('onload',callback);
window.document.body.appendChild(script);
};
2014-03-30 05:12:56 +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);
};
2014-07-08 22:07:38 +04:00
if (window.location.href.indexOf('debug') != -1) {
2014-05-17 02:04:55 +04:00
window.pskl_exports = {};
var scriptIndex = 0;
window.loadNextScript = function () {
2014-05-17 02:04:55 +04:00
if (scriptIndex == window.pskl_exports.scripts.length) {
2014-03-30 05:12:56 +04:00
window.onPiskelReady();
} else {
2014-07-08 22:07:38 +04:00
loadScript(window.pskl_exports.scripts[scriptIndex], 'loadNextScript()');
scriptIndex ++;
}
};
2014-07-08 22:07:38 +04:00
loadScript('piskel-script-list.js', 'loadNextScript()');
2014-03-30 05:12:56 +04:00
window.loadStyles = function () {
2014-05-17 02:04:55 +04:00
var styles = window.pskl_exports.styles;
2014-03-30 05:12:56 +04:00
for (var i = 0 ; i < styles.length ; i++) {
loadStyle(styles[i]);
}
};
2014-07-08 22:07:38 +04:00
loadScript('piskel-style-list.js', 'loadStyles()');
} else {
var script;
2014-07-08 22:07:38 +04:00
if (window.location.href.indexOf('pack') != -1) {
script = 'js/piskel-packaged' + version + '.js';
} else {
2014-07-08 22:07:38 +04:00
script = 'js/piskel-packaged-min' + version + '.js';
}
2014-07-08 22:07:38 +04:00
loadStyle('css/piskel-style-packaged' + version + '.css');
2014-03-30 05:12:56 +04:00
var loaderInterval = window.setInterval(function () {
2014-07-08 22:07:38 +04:00
if (document.querySelectorAll('[data-iframe-loader]').length === 0) {
window.clearInterval(loaderInterval);
2014-07-08 22:07:38 +04:00
loadScript(script, 'onPiskelReady()');
} else {
2014-07-08 22:07:38 +04:00
window.console.log('waiting for templates to load ....');
}
}, 100);
}
})();