piskel/src/piskel-boot.js

98 lines
2.8 KiB
JavaScript
Raw Normal View History

2013-08-11 03:26:38 +04:00
(function () {
/**
* See @Gruntfile.js => after build, @@version is replaced by the build version
*/
var version = '@@version';
var versionHasNotBeenReplaced = version.indexOf('@@') === 0;
if (versionHasNotBeenReplaced) {
version = '';
}
2016-08-26 01:56:40 +03:00
if (!window.piskelReadyCallbacks) {
window.piskelReadyCallbacks = [];
}
window._onPiskelReady = function () {
var loadingMask = document.getElementById('loading-mask');
loadingMask.style.opacity = 0;
window.setTimeout(function () {loadingMask.parentNode.removeChild(loadingMask);}, 600);
pskl.app.init();
pskl._releaseVersion = '@@releaseVersion';
// cleanup
2014-04-11 03:12:01 +04:00
delete window.pskl_exports;
delete window.loadDebugScripts;
delete window.done;
// Run Piskel ready callbacks
2016-08-26 01:56:40 +03:00
for (var i = 0; i < window.piskelReadyCallbacks.length; i++) {
window.piskelReadyCallbacks[i]();
}
};
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);
};
if (window.location.href.indexOf('debug') != -1) {
2014-04-11 03:12:01 +04:00
window.pskl_exports = {};
2013-08-11 03:26:38 +04:00
var scriptIndex = 0;
window.loadNextScript = function () {
2014-04-11 03:12:01 +04:00
if (scriptIndex == window.pskl_exports.scripts.length) {
window._onPiskelReady();
2013-08-11 03:26:38 +04:00
} else {
loadScript(window.pskl_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
var styles;
2013-12-19 02:22:25 +04:00
window.loadStyles = function () {
styles = window.pskl_exports.styles;
2013-12-19 02:22:25 +04:00
for (var i = 0 ; i < styles.length ; i++) {
loadStyle(styles[i]);
}
};
window.reloadStyles = function () {
for (var i = 0 ; i < styles.length ; i++) {
document.querySelector('link[href="' + styles[i] + '"]').remove();
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 = 'js/piskel-packaged' + version + '.js';
2013-08-11 03:26:38 +04:00
} else {
script = 'js/piskel-packaged-min' + version + '.js';
2013-08-11 03:26:38 +04:00
}
2013-12-19 02:22:25 +04:00
loadStyle('css/piskel-style-packaged' + version + '.css');
2016-08-26 01:56:40 +03:00
loadScript(script, '_onPiskelReady()');
2013-08-11 03:26:38 +04:00
}
})();