2020-08-10 16:40:25 +08:00
|
|
|
|
|
|
|
(win => {
|
|
|
|
|
|
|
|
const
|
2020-09-06 17:13:43 +08:00
|
|
|
doc = document,
|
2020-09-13 20:13:16 +08:00
|
|
|
eId = id => doc.getElementById(id),
|
|
|
|
app = eId('rl-app'),
|
2020-09-04 18:05:17 +08:00
|
|
|
options = app && app.dataset.boot && JSON.parse(app.dataset.boot) || {},
|
2020-09-03 22:34:23 +08:00
|
|
|
|
|
|
|
Storage = type => {
|
|
|
|
let name = type+'Storage';
|
|
|
|
try {
|
2020-09-22 15:50:52 +08:00
|
|
|
win[name].setItem(name, '');
|
|
|
|
win[name].getItem(name);
|
|
|
|
win[name].removeItem(name);
|
2020-09-03 22:34:23 +08:00
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
const cookieName = encodeURIComponent(name+('session' === type ? win.name || (win.name = Date.now()) : ''));
|
|
|
|
|
|
|
|
// initialise if there's already data
|
2020-09-06 17:13:43 +08:00
|
|
|
let data = doc.cookie.match('(^|;) ?'+cookieName+'=([^;]*)(;|$)');
|
2020-09-03 22:34:23 +08:00
|
|
|
data = data ? decodeURIComponent(data[2]) : null;
|
|
|
|
data = data ? JSON.parse(data) : {};
|
|
|
|
|
|
|
|
win[name] = {
|
|
|
|
getItem: key => data[key] === undefined ? null : data[key],
|
|
|
|
setItem: function (key, value) {
|
|
|
|
data[key] = ''+value; // forces the value to a string
|
2020-09-06 17:13:43 +08:00
|
|
|
doc.cookie = cookieName+'='+encodeURIComponent(JSON.stringify(data))
|
2020-09-03 22:34:23 +08:00
|
|
|
+"; expires="+('local' === type ? (new Date(Date.now()+(365*24*60*60*1000))).toGMTString() : '')
|
|
|
|
+"; path=/; samesite=strict";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2021-02-04 22:03:11 +08:00
|
|
|
return win[name];
|
2020-09-03 22:34:23 +08:00
|
|
|
},
|
|
|
|
STORAGE_KEY = '__rlA',
|
|
|
|
TIME_KEY = '__rlT',
|
|
|
|
AUTH_KEY = 'AuthAccountHash',
|
2021-02-04 22:03:11 +08:00
|
|
|
storage = Storage('session'),
|
2020-09-03 22:34:23 +08:00
|
|
|
timestamp = () => Math.round(Date.now() / 1000),
|
2021-02-04 22:03:11 +08:00
|
|
|
setTimestamp = () => storage.setItem(TIME_KEY, timestamp()),
|
2020-09-03 22:34:23 +08:00
|
|
|
|
|
|
|
showError = () => {
|
2020-09-13 20:13:16 +08:00
|
|
|
eId('rl-loading').hidden = true;
|
|
|
|
eId('rl-loading-error').hidden = false;
|
2020-09-03 22:34:23 +08:00
|
|
|
p.end();
|
|
|
|
},
|
|
|
|
|
|
|
|
loadScript = src => {
|
|
|
|
if (!src) {
|
|
|
|
throw new Error('src should not be empty.');
|
|
|
|
}
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const script = doc.createElement('script');
|
2020-09-23 17:20:00 +08:00
|
|
|
script.onload = () => {
|
|
|
|
p.set(pStep += step);
|
|
|
|
resolve();
|
|
|
|
};
|
2020-09-03 22:34:23 +08:00
|
|
|
script.onerror = () => reject(new Error(src));
|
|
|
|
script.src = src;
|
2020-09-23 17:20:00 +08:00
|
|
|
// script.async = true;
|
2020-09-03 22:34:23 +08:00
|
|
|
doc.head.append(script);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-09-23 17:20:00 +08:00
|
|
|
step = 100 / 7,
|
2020-09-03 22:34:23 +08:00
|
|
|
p = win.progressJs = {
|
2020-09-04 18:05:17 +08:00
|
|
|
set: percent => progress.style.width = Math.min(percent, 100) + '%',
|
2020-09-03 22:34:23 +08:00
|
|
|
end: () => {
|
|
|
|
if (container) {
|
2020-09-04 18:05:17 +08:00
|
|
|
p.set(100);
|
2020-09-03 23:14:44 +08:00
|
|
|
setTimeout(() => {
|
|
|
|
container.remove();
|
|
|
|
container = progress = null;
|
|
|
|
}, 600);
|
2020-09-03 22:34:23 +08:00
|
|
|
}
|
|
|
|
}
|
2020-08-10 16:40:25 +08:00
|
|
|
};
|
|
|
|
|
2020-09-05 18:22:46 +08:00
|
|
|
if (!navigator || !navigator.cookieEnabled) {
|
2020-09-13 20:13:16 +08:00
|
|
|
doc.location.href = './?/NoCookie';
|
2020-09-05 18:22:46 +08:00
|
|
|
}
|
2020-09-03 22:34:23 +08:00
|
|
|
|
2020-09-23 17:20:00 +08:00
|
|
|
let pStep = 0,
|
2021-02-04 22:03:11 +08:00
|
|
|
container = eId('progressjs'),
|
|
|
|
progress = container.querySelector('.progressjs-inner'),
|
2020-08-10 16:40:25 +08:00
|
|
|
|
2020-09-23 17:20:00 +08:00
|
|
|
RL_APP_DATA = {};
|
2020-08-10 16:40:25 +08:00
|
|
|
|
2020-09-04 18:05:17 +08:00
|
|
|
win.rl = {
|
2020-09-03 22:34:23 +08:00
|
|
|
hash: {
|
|
|
|
// getHash
|
2021-02-04 22:03:11 +08:00
|
|
|
get: () => storage.getItem(STORAGE_KEY) || null,
|
2020-09-03 22:34:23 +08:00
|
|
|
// setHash
|
|
|
|
set: () => {
|
2021-02-04 22:03:11 +08:00
|
|
|
storage.setItem(STORAGE_KEY, RL_APP_DATA && RL_APP_DATA[AUTH_KEY]
|
2020-09-23 17:20:00 +08:00
|
|
|
? RL_APP_DATA[AUTH_KEY] : '');
|
2020-09-03 22:34:23 +08:00
|
|
|
setTimestamp();
|
|
|
|
},
|
|
|
|
// clearHash
|
|
|
|
clear: () => {
|
2021-02-04 22:03:11 +08:00
|
|
|
storage.setItem(STORAGE_KEY, '');
|
2020-09-03 22:34:23 +08:00
|
|
|
setTimestamp();
|
|
|
|
},
|
|
|
|
// checkTimestamp
|
|
|
|
check: () => {
|
2021-02-04 22:03:11 +08:00
|
|
|
if (timestamp() > (parseInt(storage.getItem(TIME_KEY) || 0, 10) || 0) + 3600000) {
|
2020-09-03 22:34:23 +08:00
|
|
|
// 60m
|
2020-09-04 18:05:17 +08:00
|
|
|
rl.hash.clear();
|
2020-09-03 22:34:23 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2020-08-10 16:40:25 +08:00
|
|
|
}
|
2020-09-03 22:34:23 +08:00
|
|
|
},
|
2020-09-23 17:20:00 +08:00
|
|
|
data: () => RL_APP_DATA,
|
2020-09-04 18:05:17 +08:00
|
|
|
adminArea: () => options.admin,
|
|
|
|
settings: {
|
2020-09-23 17:20:00 +08:00
|
|
|
get: name => null == RL_APP_DATA[name] ? null : RL_APP_DATA[name],
|
|
|
|
set: (name, value) => RL_APP_DATA[name] = value,
|
2020-09-04 18:05:17 +08:00
|
|
|
app: name => {
|
2020-09-23 17:20:00 +08:00
|
|
|
const APP_SETTINGS = RL_APP_DATA.System || {};
|
2020-09-04 18:05:17 +08:00
|
|
|
return null == APP_SETTINGS[name] ? null : APP_SETTINGS[name];
|
|
|
|
},
|
2020-09-23 17:20:00 +08:00
|
|
|
capa: name => null != name && Array.isArray(RL_APP_DATA.Capa) && RL_APP_DATA.Capa.includes(name)
|
2020-09-04 18:05:17 +08:00
|
|
|
},
|
|
|
|
setWindowTitle: title => {
|
|
|
|
title = null == title ? '' : '' + title;
|
2020-09-23 17:20:00 +08:00
|
|
|
if (RL_APP_DATA.Title) {
|
|
|
|
title += (title ? ' - ' : '') + RL_APP_DATA.Title;
|
2020-09-04 18:05:17 +08:00
|
|
|
}
|
2020-09-06 17:13:43 +08:00
|
|
|
doc.title = null == title ? '' : '' + title;
|
2020-09-23 17:20:00 +08:00
|
|
|
},
|
2016-05-06 23:14:40 +08:00
|
|
|
|
2020-09-23 17:20:00 +08:00
|
|
|
initData: appData => {
|
|
|
|
RL_APP_DATA = appData;
|
2020-08-12 06:25:36 +08:00
|
|
|
|
2020-09-23 17:20:00 +08:00
|
|
|
rl.hash.set();
|
2020-08-12 06:25:36 +08:00
|
|
|
|
2020-09-23 17:20:00 +08:00
|
|
|
if (appData) {
|
|
|
|
if (appData.NewThemeLink) {
|
|
|
|
eId('app-theme-link').href = appData.NewThemeLink;
|
|
|
|
}
|
2020-08-12 06:25:36 +08:00
|
|
|
|
2020-09-23 17:20:00 +08:00
|
|
|
loadScript(appData.StaticLibJsLink)
|
|
|
|
.then(() => Promise.all([loadScript(appData.TemplatesLink), loadScript(appData.LangLink)]))
|
|
|
|
.then(() => loadScript(appData.StaticAppJsLink))
|
|
|
|
.then(() => appData.PluginsLink ? loadScript(appData.PluginsLink) : Promise.resolve())
|
|
|
|
.then(() =>
|
|
|
|
// Enable the old CKEditor?
|
|
|
|
(appData.Auth && appData.StaticEditorJsLink)
|
|
|
|
? loadScript(appData.StaticEditorJsLink)
|
|
|
|
: Promise.resolve()
|
|
|
|
)
|
|
|
|
.then(() => win.__APP_BOOT ? win.__APP_BOOT(showError) : showError())
|
|
|
|
.catch(e => {
|
2020-09-22 15:50:52 +08:00
|
|
|
showError();
|
2020-08-12 06:25:36 +08:00
|
|
|
throw e;
|
|
|
|
});
|
2020-09-23 17:20:00 +08:00
|
|
|
} else {
|
|
|
|
showError();
|
|
|
|
}
|
2020-08-12 06:25:36 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-09-06 17:13:43 +08:00
|
|
|
p.set(1);
|
|
|
|
|
|
|
|
Storage('local');
|
|
|
|
|
|
|
|
// init section
|
|
|
|
setInterval(setTimestamp, 60000); // 1m
|
|
|
|
|
2020-09-14 18:39:30 +08:00
|
|
|
[eId('app-css'),eId('app-theme-link')].forEach(css => css.href = css.dataset.href);
|
2020-09-06 17:13:43 +08:00
|
|
|
|
|
|
|
loadScript('./?/'
|
|
|
|
+ (options.admin ? 'Admin' : '')
|
|
|
|
+ 'AppData@'
|
|
|
|
+ (options.mobile ? 'mobile' : 'no-mobile')
|
|
|
|
+ (options.mobileDevice ? '-1' : '-0')
|
|
|
|
+ '/'
|
|
|
|
+ (rl.hash.get() || '0')
|
|
|
|
+ '/'
|
|
|
|
+ Math.random().toString().substr(2)
|
|
|
|
+ '/').then(() => {});
|
2020-08-10 16:40:25 +08:00
|
|
|
|
2020-09-05 18:22:46 +08:00
|
|
|
})(this);
|