shift73k/assets/js/app.js

54 lines
1.8 KiB
JavaScript
Raw Permalink Normal View History

// We import the main SCSS file, which performs all other SCSS imports,
// and which vite.js will preprocess with sass.
import '../css/app.scss'
2020-09-12 18:43:17 -04:00
// Include phoenix_html to handle method=PUT/DELETE in forms and buttons.
import 'phoenix_html'
2021-02-25 16:03:03 -05:00
// import Socket for Phoenix Channels
import { Socket } from "phoenix";
// import topbar for load progress in live reloading / liveview
import topbar from "topbar";
// import LiveSocket for LiveView
import { LiveSocket } from "phoenix_live_view";
2020-09-12 18:43:17 -04:00
// Bootstrap v5 js imports
import 'bootstrap/js/dist/alert';
import 'bootstrap/js/dist/collapse';
import 'bootstrap/js/dist/dropdown';
// Bootstrap helpers
import './_hamburger-helper';
import "./_form-validity";
// Bootstrap-liveview helpers
import { AlertRemover } from "./_alert-remover";
import { BsModal } from "./_bs_modal";
2021-03-15 15:46:59 -04:00
import { BsCollapse } from "./_bs_collapse";
// LiveSocket setup
let Hooks = {};
Hooks.AlertRemover = AlertRemover;
Hooks.BsModal = BsModal;
2021-03-15 15:46:59 -04:00
Hooks.BsCollapse = BsCollapse;
let csrfToken = document
.querySelector("meta[name='csrf-token']")
.getAttribute("content");
let liveSocket = new LiveSocket("/live", Socket, {
params: { _csrf_token: csrfToken },
hooks: Hooks,
});
2020-09-12 18:43:17 -04:00
// Show progress bar on live navigation and form submits
topbar.config({ barColors: { 0: "#29d" }, shadowColor: "rgba(0, 0, 0, .3)" });
window.addEventListener("phx:page-loading-start", (info) => topbar.show());
window.addEventListener("phx:page-loading-stop", (info) => topbar.hide());
2020-09-12 18:43:17 -04:00
// connect if there are any LiveViews on the page
liveSocket.connect();
2020-09-12 18:43:17 -04:00
// expose liveSocket on window for web console debug logs and latency simulation:
// >> liveSocket.enableDebug()
// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
// >> liveSocket.disableLatencySim()
window.liveSocket = liveSocket;