Add delayed top bar (#973)

This commit is contained in:
José Valim 2022-02-03 15:05:16 +01:00 committed by GitHub
parent 0f4ef593bc
commit aafa5cc642
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -69,8 +69,20 @@ topbar.config({
barColors: { 0: "#b2c1ff" },
shadowColor: "rgba(0, 0, 0, .3)",
});
window.addEventListener("phx:page-loading-start", () => topbar.show());
window.addEventListener("phx:page-loading-stop", () => topbar.hide());
let topBarScheduled = null;
window.addEventListener("phx:page-loading-start", () => {
if (!topBarScheduled) {
topBarScheduled = setTimeout(() => topbar.show(), 200);
}
});
window.addEventListener("phx:page-loading-stop", () => {
clearTimeout(topBarScheduled);
topBarScheduled = null;
topbar.hide();
});
// connect if there are any LiveViews on the page
liveSocket.connect();