Sha256: 273b5f57d3b1c0f32ac3e9cc4522071ab8da1b9b4bef96f69e7d4d4a307f7047

Contents?: true

Size: 1020 Bytes

Versions: 12

Compression:

Stored size: 1020 Bytes

Contents

class UnlinkButton extends HTMLButtonElement {
  constructor() {
    super()
    this.addEventListener("click", this)
    this.classList.add("icon_button")
    // Prevent accidental form submits if this component is wrapped inside a form
    this.setAttribute("type", "button")
    this.linked = this.linked
    this.innerHTML =
      '<alchemy-icon name="link-unlink" icon-style="m"></alchemy-icon>'
  }

  handleEvent(event) {
    if (this.linked) {
      this.linked = false
      this.blur()
      this.dispatchEvent(new CustomEvent("alchemy:unlink", { bubbles: true }))
    }
    event.preventDefault()
  }

  set linked(isLinked) {
    if (isLinked) {
      this.classList.replace("disabled", "linked")
      this.removeAttribute("tabindex")
    } else {
      this.classList.replace("linked", "disabled")
      this.setAttribute("tabindex", "-1")
    }
  }

  get linked() {
    return this.classList.contains("linked")
  }
}

customElements.define("alchemy-unlink-button", UnlinkButton, {
  extends: "button"
})

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
alchemy_cms-7.3.4 app/javascript/alchemy_admin/components/link_buttons/unlink_button.js
alchemy_cms-7.3.3 app/javascript/alchemy_admin/components/link_buttons/unlink_button.js
alchemy_cms-7.3.2 app/javascript/alchemy_admin/components/link_buttons/unlink_button.js
alchemy_cms-7.2.7 app/javascript/alchemy_admin/components/link_buttons/unlink_button.js
alchemy_cms-7.3.1 app/javascript/alchemy_admin/components/link_buttons/unlink_button.js
alchemy_cms-7.3.0 app/javascript/alchemy_admin/components/link_buttons/unlink_button.js
alchemy_cms-7.2.6 app/javascript/alchemy_admin/components/link_buttons/unlink_button.js
alchemy_cms-7.2.5 app/javascript/alchemy_admin/components/link_buttons/unlink_button.js
alchemy_cms-7.2.4 app/javascript/alchemy_admin/components/link_buttons/unlink_button.js
alchemy_cms-7.2.3 app/javascript/alchemy_admin/components/link_buttons/unlink_button.js
alchemy_cms-7.2.2 app/javascript/alchemy_admin/components/link_buttons/unlink_button.js
alchemy_cms-7.2.1 app/javascript/alchemy_admin/components/link_buttons/unlink_button.js