8000 Javascript API - Custom DOM Events · Issue #94 · seanhess/hyperbole · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Javascript API - Custom DOM Events #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
seanhess opened this issue Mar 10, 2025 · 0 comments
Open

Javascript API - Custom DOM Events #94

seanhess opened this issue Mar 10, 2025 · 0 comments

Comments

@seanhess
Copy link
Owner
seanhess commented Mar 10, 2025

We need to be able to allow onmouseover onmouseleave, etc via the custom JS api. See #40

This probably requires #92

Phoenix LiveView Implementation

https://hexdocs.pm/phoenix_live_view/js-interop.html

<div id="woot" phx-hook="HoverHook"/>
import { Socket } from "phoenix";
import { LiveSocket } from "phoenix_live_view";

// Register hooks here
let Hooks = {};
Hooks.HoverHook = {
  mounted() {
    console.log("Hook mounted!");
    this.el.addEventListener("mouseenter", () => {
      this.pushEvent("mouse_enter", { id: this.el.id });
    });
    this.el.addEventListener("mouseleave", () => {
      this.pushEvent("mouse_leave", { id: this.el.id });
    });
  }
};

// Initialize LiveSocket with hooks
let liveSocket = new LiveSocket("/live", Socket, {
  hooks: Hooks, // Hooks get passed here
});
def handle_event("mouse_enter", %{"id" => id}, socket) do
  IO.puts("#{id} was hovered!")
  {:noreply, socket}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0