2016-05-06 23:14:40 +08:00
|
|
|
|
|
|
|
import window from 'window';
|
|
|
|
import $ from '$';
|
2016-05-20 08:04:15 +08:00
|
|
|
import progressJs from 'progressJs';
|
2016-05-06 23:14:40 +08:00
|
|
|
|
|
|
|
import rainLoopStorage from 'Storage/RainLoop';
|
|
|
|
|
2016-05-20 08:04:15 +08:00
|
|
|
let rlAppDataStorage = null;
|
|
|
|
|
2016-05-06 23:14:40 +08:00
|
|
|
window.__rlah = () => {
|
|
|
|
return rainLoopStorage ? rainLoopStorage.getHash() : null;
|
|
|
|
};
|
|
|
|
|
2016-05-20 08:04:15 +08:00
|
|
|
window.__rlah_data = () => {
|
|
|
|
return rlAppDataStorage;
|
|
|
|
};
|
|
|
|
|
2016-05-06 23:14:40 +08:00
|
|
|
window.__rlah_set = () => {
|
|
|
|
if (rainLoopStorage)
|
|
|
|
{
|
|
|
|
rainLoopStorage.setHash();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
window.__rlah_clear = () => {
|
|
|
|
if (rainLoopStorage)
|
|
|
|
{
|
|
|
|
rainLoopStorage.clearHash();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-20 08:04:15 +08:00
|
|
|
function includeStyle(styles)
|
|
|
|
{
|
|
|
|
window.document.write(unescape('%3Csty' + 'le%3E' + styles + '"%3E%3C/' + 'sty' + 'le%3E'));
|
|
|
|
}
|
2016-05-06 23:14:40 +08:00
|
|
|
|
2016-05-20 08:04:15 +08:00
|
|
|
function includeScr(src)
|
|
|
|
{
|
|
|
|
window.document.write(unescape('%3Csc' + 'ript type="text/jav' + 'ascr' + 'ipt" data-cfasync="false" sr' + 'c="' + src + '"%3E%3C/' + 'scr' + 'ipt%3E'));
|
|
|
|
}
|
2016-05-07 22:42:36 +08:00
|
|
|
|
2016-05-20 08:04:15 +08:00
|
|
|
function includeLayout()
|
|
|
|
{
|
|
|
|
const
|
|
|
|
layout = require('Html/Layout.html'),
|
|
|
|
app = window.document.getElementById('rl-app')
|
|
|
|
;
|
|
|
|
|
|
|
|
if (app && layout)
|
|
|
|
{
|
|
|
|
app.innerHTML = layout.replace(/[\r\n\t]+/g, '');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function includeAppScr(data = {})
|
|
|
|
{
|
|
|
|
let src = './?/';
|
|
|
|
src += data.admin ? 'Admin' : '';
|
|
|
|
src += 'AppData@';
|
|
|
|
src += data.mobile ? 'mobile' : 'no-mobile';
|
|
|
|
src += data.mobileDevice ? '-1' : '-0';
|
|
|
|
src += '/';
|
|
|
|
|
|
|
|
includeScr(src + (window.__rlah ? window.__rlah() || '0' : '0') + '/' + window.Math.random().toString().substr(2) + '/');
|
|
|
|
}
|
2016-05-06 23:14:40 +08:00
|
|
|
|
2016-05-20 08:04:15 +08:00
|
|
|
function getRainloopBootData()
|
|
|
|
{
|
|
|
|
let result = {};
|
|
|
|
const meta = window.document.getElementById('app-boot-data');
|
2016-05-06 23:14:40 +08:00
|
|
|
|
2016-05-20 08:04:15 +08:00
|
|
|
if (meta && meta.getAttribute)
|
|
|
|
{
|
|
|
|
result = JSON.parse(meta.getAttribute('content')) || {};
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function showError(additionalError)
|
|
|
|
{
|
2016-05-06 23:14:40 +08:00
|
|
|
const
|
|
|
|
oR = window.document.getElementById('rl-loading'),
|
|
|
|
oL = window.document.getElementById('rl-loading-error'),
|
|
|
|
oLA = window.document.getElementById('rl-loading-error-additional')
|
|
|
|
;
|
|
|
|
|
|
|
|
if (oR)
|
|
|
|
{
|
|
|
|
oR.style.display = 'none';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oL)
|
|
|
|
{
|
|
|
|
oL.style.display = 'block';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oLA && additionalError)
|
|
|
|
{
|
|
|
|
oLA.style.display = 'block';
|
|
|
|
oLA.innerHTML = additionalError;
|
|
|
|
}
|
|
|
|
|
2016-05-20 08:04:15 +08:00
|
|
|
if (progressJs)
|
2016-05-06 23:14:40 +08:00
|
|
|
{
|
2016-05-20 08:04:15 +08:00
|
|
|
progressJs.set(100).end();
|
2016-05-06 23:14:40 +08:00
|
|
|
}
|
2016-05-20 08:04:15 +08:00
|
|
|
}
|
2016-05-06 23:14:40 +08:00
|
|
|
|
2016-05-20 08:04:15 +08:00
|
|
|
function showDescriptionAndLoading(description)
|
|
|
|
{
|
2016-05-06 23:14:40 +08:00
|
|
|
const
|
|
|
|
oE = window.document.getElementById('rl-loading'),
|
|
|
|
oElDesc = window.document.getElementById('rl-loading-desc')
|
|
|
|
;
|
|
|
|
|
|
|
|
if (oElDesc && description)
|
|
|
|
{
|
|
|
|
oElDesc.innerHTML = description;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oE && oE.style)
|
|
|
|
{
|
|
|
|
oE.style.opacity = 0;
|
|
|
|
window.setTimeout(() => {
|
|
|
|
oE.style.opacity = 1;
|
|
|
|
}, 300);
|
|
|
|
}
|
2016-05-20 08:04:15 +08:00
|
|
|
}
|
2016-05-06 23:14:40 +08:00
|
|
|
|
2016-05-20 08:04:15 +08:00
|
|
|
function runMainBoot(withError, additionalError)
|
|
|
|
{
|
|
|
|
if (window.__APP_BOOT && !withError)
|
|
|
|
{
|
2016-05-06 23:14:40 +08:00
|
|
|
window.__APP_BOOT(function (bV) {
|
2016-05-20 08:04:15 +08:00
|
|
|
if (!bV)
|
|
|
|
{
|
|
|
|
showError(additionalError);
|
2016-05-06 23:14:40 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2016-05-20 08:04:15 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
showError(additionalError);
|
|
|
|
}
|
|
|
|
}
|
2016-05-06 23:14:40 +08:00
|
|
|
|
2016-05-20 08:04:15 +08:00
|
|
|
function runApp()
|
|
|
|
{
|
|
|
|
const appData = window.__rlah_data();
|
2016-05-06 23:14:40 +08:00
|
|
|
|
2016-05-20 08:04:15 +08:00
|
|
|
if (window.jsloader && progressJs && appData && appData.TemplatesLink && appData.LangLink &&
|
|
|
|
appData.StaticLibJsLink && appData.StaticAppJsLink && appData.StaticEditorJsLink)
|
2016-05-06 23:14:40 +08:00
|
|
|
{
|
2016-05-20 08:04:15 +08:00
|
|
|
const p = progressJs;
|
2016-05-06 23:14:40 +08:00
|
|
|
|
|
|
|
p.setOptions({theme: 'rainloop'});
|
|
|
|
p.start().set(5);
|
|
|
|
|
2016-05-20 08:04:15 +08:00
|
|
|
const
|
|
|
|
libs = window.jsloader(appData.StaticLibJsLink).then(() => {
|
|
|
|
if (window.$)
|
|
|
|
{
|
|
|
|
if (!window.$('#rl-check').is(':visible'))
|
|
|
|
{
|
|
|
|
window.$('html').addClass('no-css');
|
|
|
|
throw new Error('no-css');
|
|
|
|
}
|
|
|
|
|
|
|
|
window.$('#rl-check').remove();
|
|
|
|
|
|
|
|
if (appData.IncludeBackground)
|
|
|
|
{
|
|
|
|
window.$('#rl-bg').attr('style', 'background-image: none !important;')
|
|
|
|
.backstretch(appData.IncludeBackground.replace('{{USER}}',
|
|
|
|
(window.__rlah ? (window.__rlah() || '0') : '0')), {fade: 100, centeredX: true, centeredY: true})
|
|
|
|
.removeAttr('style')
|
|
|
|
;
|
|
|
|
}
|
2016-05-06 23:14:40 +08:00
|
|
|
}
|
2016-05-20 08:04:15 +08:00
|
|
|
}),
|
|
|
|
common = window.Promise.all([
|
|
|
|
window.jsloader(appData.TemplatesLink),
|
|
|
|
window.jsloader(appData.LangLink)
|
|
|
|
])
|
|
|
|
;
|
|
|
|
|
|
|
|
window.Promise.all([libs, common])
|
|
|
|
.then(() => {
|
2016-05-06 23:14:40 +08:00
|
|
|
p.set(30);
|
2016-05-20 08:04:15 +08:00
|
|
|
return window.jsloader(appData.StaticAppJsLink);
|
|
|
|
}).then(() => {
|
2016-05-06 23:14:40 +08:00
|
|
|
p.set(50);
|
2016-05-20 08:04:15 +08:00
|
|
|
return appData.PluginsLink ? window.jsloader(appData.PluginsLink) : window.Promise.resolve();
|
|
|
|
}).then(() => {
|
2016-05-06 23:14:40 +08:00
|
|
|
p.set(70);
|
2016-05-20 08:04:15 +08:00
|
|
|
runMainBoot(false);
|
|
|
|
}).catch((e) => {
|
|
|
|
runMainBoot(true);
|
|
|
|
throw e;
|
|
|
|
}).then(() => {
|
|
|
|
return window.jsloader(appData.StaticEditorJsLink);
|
|
|
|
}).then(() => {
|
2016-05-06 23:14:40 +08:00
|
|
|
if (window.CKEDITOR && window.__initEditor) {
|
|
|
|
window.__initEditor();
|
|
|
|
window.__initEditor = null;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-05-20 08:04:15 +08:00
|
|
|
runMainBoot(true);
|
2016-05-06 23:14:40 +08:00
|
|
|
}
|
2016-05-20 08:04:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
window.__initAppData = function(data) {
|
|
|
|
|
|
|
|
rlAppDataStorage = data;
|
|
|
|
|
|
|
|
window.__rlah_set();
|
|
|
|
|
|
|
|
if (rlAppDataStorage.NewThemeLink)
|
|
|
|
{
|
|
|
|
window.document.getElementById('app-theme-link').href = rlAppDataStorage.NewThemeLink;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rlAppDataStorage.IncludeCss)
|
|
|
|
{
|
|
|
|
includeStyle(rlAppDataStorage.IncludeCss);
|
|
|
|
}
|
|
|
|
|
|
|
|
showDescriptionAndLoading(rlAppDataStorage ? (rlAppDataStorage.LoadingDescriptionEsc || '') : '');
|
|
|
|
|
|
|
|
runApp();
|
2016-05-06 23:14:40 +08:00
|
|
|
};
|
2016-05-20 08:04:15 +08:00
|
|
|
|
|
|
|
window.__runBoot = function() {
|
|
|
|
|
|
|
|
if (!window.navigator || !window.navigator.cookieEnabled)
|
|
|
|
{
|
|
|
|
window.document.location.replace('./?/NoCookie');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (includeLayout())
|
|
|
|
{
|
|
|
|
includeAppScr(getRainloopBootData());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|