Skip to content

Self-hosted project management for devs and their clients: tickets, time tracking, docs and meetings, with an AI assistant that cites its sources. AGPL-3.0.

868 B
Raw Blame
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  static targets = ["overlay", "image"]

  open(event) {
    event.preventDefault()
    const src = event.params.src
    if (!src) return

    this.imageTarget.src = src
    this.overlayTarget.classList.remove("hidden")
    this.overlayTarget.classList.add("flex")
    document.body.classList.add("overflow-hidden")
  }

  close() {
    this.overlayTarget.classList.add("hidden")
    this.overlayTarget.classList.remove("flex")
    document.body.classList.remove("overflow-hidden")
  }

  // Escape owner (lib/escape_owner.js): the lane behind stays open while this is true.
  ownsEscape() {
    return this.hasOverlayTarget && !this.overlayTarget.classList.contains("hidden")
  }

  // Close on Escape key
  keydown(event) {
    if (event.key === "Escape") this.close()
  }
}