Files
firefly-iii/resources/assets/v2/boot/bootstrap.js

71 lines
2.3 KiB
JavaScript
Raw Normal View History

2023-08-15 13:51:38 +02:00
/*
* bootstrap.js
* Copyright (c) 2023 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2023-07-11 11:45:55 +02:00
/**
* We'll load the axios HTTP library which allows us to easily issue requests
* to our Laravel back-end. This library automatically handles sending the
* CSRF token as a header based on the value of the "XSRF" token cookie.
*/
2023-07-23 07:10:31 +02:00
// import things
2023-07-11 11:45:55 +02:00
import axios from 'axios';
2023-07-23 07:10:31 +02:00
import store from "store";
import observePlugin from 'store/plugins/observe';
2023-07-22 16:42:33 +02:00
import Alpine from "alpinejs";
2023-08-15 13:52:30 +02:00
import * as bootstrap from 'bootstrap'
2023-07-23 07:10:31 +02:00
store.addPlugin(observePlugin);
window.store = store;
// import even more
2023-08-15 13:51:38 +02:00
import {getVariable} from "../store/get-variable.js";
import {getViewRange} from "../support/get-viewrange.js";
2023-07-22 16:42:33 +02:00
// wait for 3 promises, because we need those later on.
window.bootstrapped = false;
Promise.all([
getVariable('viewRange'),
getVariable('darkMode'),
2023-07-23 07:10:31 +02:00
getVariable('locale'),
getVariable('language'),
2023-07-22 16:42:33 +02:00
]).then((values) => {
2023-07-23 07:10:31 +02:00
if (!store.get('start') || !store.get('end')) {
2023-07-22 16:42:33 +02:00
// calculate new start and end, and store them.
const range = getViewRange(values[0], new Date);
store.set('start', range.start);
store.set('end', range.end);
}
2023-07-24 18:58:35 +02:00
// save local in window.__ something
2023-08-12 07:53:11 +02:00
window.__localeId__ = values[2];
store.set('language', values[3]);
store.set('locale', values[3]);
2023-07-24 18:58:35 +02:00
2023-07-22 16:42:33 +02:00
const event = new Event('firefly-iii-bootstrapped');
document.dispatchEvent(event);
window.bootstrapped = true;
});
2023-07-11 11:45:55 +02:00
window.axios = axios;
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
2023-07-22 16:42:33 +02:00
window.Alpine = Alpine