snappymail/dev/bootstrap.js

87 lines
2.4 KiB
JavaScript
Raw Normal View History

2016-06-07 05:57:52 +08:00
import window from 'window';
import { detectDropdownVisibility, createCommandLegacy, domReady } 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
window.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;
}
if (window.getSelection) {
window.getSelection().removeAllRanges();
} else if (window.document.selection && window.document.selection.clear) {
window.document.selection.clear();
}
event.preventDefault();
}
}
});
window.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;
rl.createCommand = createCommandLegacy;
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.addHook = Plugins.addHook;
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 = () => {
window.setTimeout(() => {
$htmlCL.remove('no-js', 'rl-booted-trigger');
$htmlCL.add('rl-booted');
2020-03-16 04:14:52 +08:00
App.bootstart();
}, Enums.Magics.Time10ms);
};
2016-06-07 05:57:52 +08:00
window.__APP_BOOT = (fErrorCallback) => {
2016-08-30 06:10:24 +08:00
domReady(() => {
2016-06-16 07:36:44 +08:00
window.setTimeout(() => {
if (window.rainloopTEMPLATES && window.rainloopTEMPLATES[0]) {
2016-08-30 06:10:24 +08:00
window.document.getElementById('rl-templates').innerHTML = window.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;
2016-08-24 06:17:50 +08:00
}, Enums.Magics.Time10ms);
2016-06-07 05:57:52 +08:00
});
2015-11-19 01:32:29 +08:00
};
2016-04-21 01:12:51 +08:00
};