snappymail/dev/bootstrap.js

80 lines
2 KiB
JavaScript
Raw Normal View History

import { detectDropdownVisibility } from 'Common/Utils';
import { $html, $htmlCL, data as GlobalsData, bMobileDevice } from 'Common/Globals';
2016-06-16 07:36:44 +08:00
import * as Enums from 'Common/Enums';
import * as Plugins from 'Common/Plugins';
2019-07-05 03:19:24 +08:00
import { i18n } from 'Common/Translator';
import { EmailModel } from 'Model/Email';
2016-06-07 05:57:52 +08:00
2015-11-19 01:32:29 +08:00
export default (App) => {
2016-06-07 05:57:52 +08:00
GlobalsData.__APP__ = App;
2015-11-19 01:32:29 +08:00
addEventListener('keydown', event => {
event = event || window.event;
if (event && event.ctrlKey && !event.shiftKey && !event.altKey) {
const key = event.keyCode || event.which;
if (key === Enums.EventKeyCode.S) {
event.preventDefault();
return;
} else if (key === Enums.EventKeyCode.A) {
const sender = event.target || event.srcElement;
if (
sender &&
('true' === '' + sender.contentEditable || (sender.tagName && sender.tagName.match(/INPUT|TEXTAREA/i)))
) {
return;
}
getSelection().removeAllRanges();
event.preventDefault();
}
}
});
addEventListener('unload', () => {
2019-07-05 03:19:24 +08:00
GlobalsData.bUnload = true;
});
2015-11-19 01:32:29 +08:00
$htmlCL.add(bMobileDevice ? 'mobile' : 'no-mobile');
$html.on('click.dropdown.data-api', detectDropdownVisibility);
2015-11-19 01:32:29 +08:00
2016-06-07 05:57:52 +08:00
const rl = window.rl || {};
2015-11-19 01:32:29 +08:00
2016-06-17 07:23:49 +08:00
rl.i18n = i18n;
2015-11-19 01:32:29 +08:00
2016-06-16 07:36:44 +08:00
rl.addSettingsViewModel = Plugins.addSettingsViewModel;
rl.addSettingsViewModelForAdmin = Plugins.addSettingsViewModelForAdmin;
2015-11-19 01:32:29 +08:00
2016-06-16 07:36:44 +08:00
rl.settingsGet = Plugins.mainSettingsGet;
rl.pluginSettingsGet = Plugins.settingsGet;
rl.pluginRemoteRequest = Plugins.remoteRequest;
2015-11-19 01:32:29 +08:00
2016-06-07 05:57:52 +08:00
rl.EmailModel = EmailModel;
rl.Enums = Enums;
2015-11-19 01:32:29 +08:00
2016-06-07 05:57:52 +08:00
window.rl = rl;
2015-11-19 01:32:29 +08:00
2020-03-16 04:14:52 +08:00
const start = () => {
setTimeout(() => {
$htmlCL.remove('no-js', 'rl-booted-trigger');
$htmlCL.add('rl-booted');
2020-03-16 04:14:52 +08:00
App.bootstart();
2020-08-14 04:58:41 +08:00
}, 10);
2020-03-16 04:14:52 +08:00
};
window.__APP_BOOT = fErrorCallback => {
jQuery(() => {
setTimeout(() => {
if (window.rainloopTEMPLATES && rainloopTEMPLATES[0]) {
document.getElementById('rl-templates').innerHTML = rainloopTEMPLATES[0];
2020-03-16 04:14:52 +08:00
start();
2019-07-05 03:19:24 +08:00
} else {
2016-06-07 05:57:52 +08:00
fErrorCallback();
}
2015-11-19 01:32:29 +08:00
2016-06-07 05:57:52 +08:00
window.__APP_BOOT = null;
2020-08-14 04:58:41 +08:00
}, 10);
2016-06-07 05:57:52 +08:00
});
2015-11-19 01:32:29 +08:00
};
2016-04-21 01:12:51 +08:00
};