Sha256: cd48d067be1eb104d18f9e6c85c50f941e24561eff422d6cb887c19aab301d82

Contents?: true

Size: 1 KB

Versions: 11

Compression:

Stored size: 1 KB

Contents

import { Controller } from "@hotwired/stimulus"
import { useClickOutside } from 'stimulus-use'

// simple controller to hide/show the filter modal
export default class extends Controller {
  static targets = ["frame"]

  static values = {
    src: String,
    isOpen: {type: Boolean, default: false}
  }

  connect() {
    useClickOutside(this)
    this.boundHandleKeyUp = this.handleKeyUp.bind(this)
    document.addEventListener("keyup", this.boundHandleKeyUp)
  }

  disconnect() {
    document.removeEventListener("keyup", this.boundHandleKeyUp)
  }

  show(event) {
    event.preventDefault()
    this.frameTarget.src = this.srcValue;
    this.isOpenValue = true
  }

  hide(event) {
    if (this.isOpenValue) {
      event?.preventDefault()
      event?.stopPropagation()
      this.frameTarget.innerHTML = "";
      this.isOpenValue = false
    }
  }

  clickOutside(event) {
    this.hide(event)
  }

  handleKeyUp(event) {
    if (event.key === "Escape" || event.key === "Esc") {
      this.hide(event)
    }
  }
}

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
refine-rails-2.13.3 app/javascript/controllers/refine/popup-controller.js
refine-rails-2.13.2 app/javascript/controllers/refine/popup-controller.js
refine-rails-2.13.1 app/javascript/controllers/refine/popup-controller.js
refine-rails-2.13.0 app/javascript/controllers/refine/popup-controller.js
refine-rails-2.12.2 app/javascript/controllers/refine/popup-controller.js
refine-rails-2.12.1 app/javascript/controllers/refine/popup-controller.js
refine-rails-2.12.0 app/javascript/controllers/refine/popup-controller.js
refine-rails-2.11.12 app/javascript/controllers/refine/popup-controller.js
refine-rails-2.11.11 app/javascript/controllers/refine/popup-controller.js
refine-rails-2.11.10 app/javascript/controllers/refine/popup-controller.js
refine-rails-2.11.9 app/javascript/controllers/refine/popup-controller.js