Files
lucent-laravel/front/js/bootstrap.js
T

52 lines
1.4 KiB
JavaScript
Raw Normal View History

2023-10-02 23:10:49 +03: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.
*/
import axios from "axios";
2024-08-14 22:04:34 +03:00
import {loadHtmxFormsBehaviour} from "./htmx-form.js";
loadHtmxFormsBehaviour();
2023-10-02 23:10:49 +03:00
window.axios = axios;
2023-11-17 21:22:26 +02:00
export const axiosInstance = axios;
2023-10-02 23:10:49 +03:00
window.axios.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest";
window.axios.interceptors.request.use(
function (config) {
let list;
list = document.querySelectorAll(".btn-spinner");
2023-11-17 21:22:26 +02:00
for (let i = 0; i < list.length; ++i) {
2023-10-02 23:10:49 +03:00
list[i].classList.add("spinner-on");
list[i].disabled = true;
}
return config;
},
function (error) {
return Promise.reject(error);
}
);
window.axios.interceptors.response.use(
function (response) {
let list;
list = document.querySelectorAll(".btn-spinner");
2023-11-17 21:22:26 +02:00
for (let i = 0; i < list.length; ++i) {
2023-10-02 23:10:49 +03:00
list[i].classList.remove("spinner-on");
list[i].disabled = false;
}
return response;
},
function (error) {
let list;
list = document.querySelectorAll(".btn-spinner");
2023-11-17 21:22:26 +02:00
for (let i = 0; i < list.length; ++i) {
2023-10-02 23:10:49 +03:00
list[i].classList.remove("spinner-on");
list[i].disabled = false;
}
return Promise.reject(error);
}
);