keeweb/app/scripts/app.js

95 lines
2.8 KiB
JavaScript
Raw Normal View History

2015-10-17 23:49:24 +02:00
'use strict';
var AppModel = require('./models/app-model'),
AppView = require('./views/app-view'),
KeyHandler = require('./comp/key-handler'),
2015-11-17 22:49:12 +01:00
IdleTracker = require('./comp/idle-tracker'),
2016-03-26 21:12:56 +01:00
PopupNotifier = require('./comp/popup-notifier'),
2015-10-25 17:27:34 +01:00
Alerts = require('./comp/alerts'),
Updater = require('./comp/updater'),
2016-03-27 13:54:35 +02:00
AuthReceiver = require('./comp/auth-receiver'),
2016-04-17 12:28:23 +02:00
ExportApi = require('./comp/export-api'),
2015-12-17 19:25:25 +01:00
ThemeChanger = require('./util/theme-changer'),
Locale = require('./util/locale');
2015-10-17 23:49:24 +02:00
2016-07-17 13:30:38 +02:00
$(() => {
2016-06-16 19:00:24 +02:00
if (isPopup()) {
2016-03-27 18:03:58 +02:00
return AuthReceiver.receive();
2015-10-25 17:27:34 +01:00
}
2016-06-16 19:00:24 +02:00
loadMixins();
initModules();
2015-10-31 07:15:17 +01:00
var appModel = new AppModel();
ThemeChanger.setBySettings(appModel.settings);
2016-06-16 19:00:24 +02:00
var configParam = getConfigParam();
if (configParam) {
2016-07-17 13:30:38 +02:00
appModel.loadConfig(configParam, err => {
2016-06-16 19:00:24 +02:00
if (err) {
showSettingsLoadError();
} else {
ThemeChanger.setBySettings(appModel.settings);
showApp();
}
2015-10-17 23:49:24 +02:00
});
} else {
showApp();
}
2016-06-16 19:00:24 +02:00
function isPopup() {
return (window.parent !== window.top) || window.opener;
}
function loadMixins() {
require('./mixins/view');
require('./helpers');
}
function initModules() {
KeyHandler.init();
IdleTracker.init();
PopupNotifier.init();
window.kw = ExportApi;
}
function showSettingsLoadError() {
ThemeChanger.setBySettings(appModel.settings);
Alerts.error({
header: Locale.appSettingsError,
body: Locale.appSettingsErrorBody,
buttons: [],
esc: false, enter: false, click: false
});
}
2015-10-17 23:49:24 +02:00
function showApp() {
2016-06-16 19:00:24 +02:00
var skipHttpsWarning = localStorage.skipHttpsWarning || appModel.settings.get('skipHttpsWarning');
if (['https:', 'file:', 'app:'].indexOf(location.protocol) < 0 && !skipHttpsWarning) {
Alerts.error({ header: Locale.appSecWarn, icon: 'user-secret', esc: false, enter: false, click: false,
body: Locale.appSecWarnBody1 + '<br/><br/>' + Locale.appSecWarnBody2,
buttons: [
{ result: '', title: Locale.appSecWarnBtn, error: true }
],
complete: showView
});
} else {
showView();
}
}
function showView() {
2015-12-06 21:32:41 +01:00
new AppView({ model: appModel }).render();
2015-10-29 22:20:01 +01:00
Updater.init();
2015-10-17 23:49:24 +02:00
}
2016-06-16 19:00:24 +02:00
function getConfigParam() {
let metaConfig = document.head.querySelector('meta[name=kw-config]');
if (metaConfig && metaConfig.content) {
return metaConfig.content;
}
var match = location.search.match(/[?&]config=([^&]+)/i);
2016-06-16 19:00:24 +02:00
if (match && match[1]) {
return match[1];
}
}
2015-10-17 23:49:24 +02:00
});