Sha256: bcbae75ff2fe8dfaf7d5fde8426b125fcbac48c4759c5abf77cf05c2a3e46fd8

Contents?: true

Size: 852 Bytes

Versions: 3

Compression:

Stored size: 852 Bytes

Contents

import { Controller } from "@hotwired/stimulus";

export default class extends Controller {
  static targets = ["dialog", "content", "title", "titleSource", "turboFrame"];

  initialize() {
    this.loadingIndicator = this.turboFrameTarget.innerHTML;
  }

  open(e) {
    e.preventDefault();
    const link = e.currentTarget;
    this.dialogTarget.showModal();
    this.turboFrameTarget.src = link.href;
  }

  safeClose(e) {
    if (this.contentTarget.contains(e.target)) return;
    this.close();
  }

  close(e) {
    this.dialogTarget.close();
    this.resetContent();
  }

  titleSourceTargetConnected(e) {
    const title = e.textContent;
    this.setTitle(title);
  }

  resetContent() {
    this.turboFrameTarget.innerHTML = this.loadingIndicator;
    this.setTitle("");
  }

  setTitle(value) {
    this.titleTarget.textContent = value;
  }
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rosetta-rails-0.2.1 app/assets/javascripts/rosetta/controllers/dialog_controller.js
rosetta-rails-0.2.0 app/assets/javascripts/rosetta/controllers/dialog_controller.js
rosetta-rails-0.1.1 app/assets/javascripts/rosetta/controllers/dialog_controller.js