diff --git a/assets/js/app.js b/assets/js/app.js index 04aa4b2..34316da 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -12,6 +12,19 @@ let execJS = (selector, attr) => { let Hooks = {} +Hooks.Flash = { + mounted(){ + let hide = () => liveSocket.execJS(this.el, this.el.getAttribute("phx-click")) + this.timer = setTimeout(() => hide(), 8000) + this.el.addEventListener("phx:hide-start", () => clearTimeout(this.timer)) + this.el.addEventListener("mouseover", () => { + clearTimeout(this.timer) + this.timer = setTimeout(() => hide(), 8000) + }) + }, + destroyed(){ clearTimeout(this.timer) } +} + Hooks.Menu = { getAttr(name){ let val = this.el.getAttribute(name) @@ -78,17 +91,6 @@ Hooks.Menu = { } } -Hooks.Flash = { - mounted(){ - let hide = () => this.el.click() - let timer = setTimeout(() => hide(), 8000) - this.el.addEventListener("mouseover", () => { - clearTimeout(timer) - timer = setTimeout(() => hide(), 8000) - }) - } -} - Hooks.AudioPlayer = { mounted(){ this.playbackBeganAt = null @@ -159,7 +161,7 @@ Hooks.AudioPlayer = { clearInterval(this.progressTimer) return } - this.progress.style.width = `${(this.player.currentTime / (this.player.duration) * 100)}%` + this.progress.style.width = `${(this.player.currentTime / (this.player.duration) * 100)}%` this.duration.innerText = this.formatTime(this.player.duration) this.currentTime.innerText = this.formatTime(this.player.currentTime) }, @@ -169,7 +171,7 @@ Hooks.AudioPlayer = { let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content") let liveSocket = new LiveSocket("/live", Socket, { - hooks: Hooks, + hooks: Hooks, params: {_csrf_token: csrfToken} }) diff --git a/lib/live_beats_web/live/live_helpers.ex b/lib/live_beats_web/live/live_helpers.ex index 467f6f4..c0b0690 100644 --- a/lib/live_beats_web/live/live_helpers.ex +++ b/lib/live_beats_web/live/live_helpers.ex @@ -22,9 +22,8 @@ defmodule LiveBeatsWeb.LiveHelpers do