Sha256: a755b8f2a413995bd6cc77a028389d00109921dd364509018ff55d19e652f48f

Contents?: true

Size: 801 Bytes

Versions: 4

Compression:

Stored size: 801 Bytes

Contents

import ApplicationController from './application_controller'

import { visit } from '@hotwired/turbo'
import Modal from '../core/modal'

export default class extends ApplicationController {
  follow (e) {
    if (this.ignoreElement(e.target) || !this.url) {
      return
    }

    if (this.isModal) {
      Modal.load(this.url)
    } else if (e.metaKey || e.ctrlKey) {
      window.open(this.url, '_blank')
    } else {
      visit(this.url)
    }
  }

  get url () {
    if (this.element.dataset.url === 'auto') {
      return this.element.querySelector('td:not(.table-actions) a').href
    } else {
      return this.element.dataset.url
    }
  }

  get isModal () {
    return this.element.dataset.modal
  }

  ignoreElement (node) {
    return node.matches('a, input, button, .select-row')
  }
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
trestle-0.10.1 frontend/js/controllers/follow_url_controller.js
trestle-0.10.0 frontend/js/controllers/follow_url_controller.js
trestle-0.10.0.pre2 frontend/js/controllers/follow_url_controller.js
trestle-0.10.0.pre frontend/js/controllers/follow_url_controller.js