Sha256: 42dae544c8ead00bc4249a91b30a09edc4a540fd47c3c07526c770ad7a9aa349

Contents?: true

Size: 791 Bytes

Versions: 20

Compression:

Stored size: 791 Bytes

Contents

import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
  visitRecord(event) {
    if (event.type !== 'click') {
      return
    }

    const isLinkOrButton = event.target.closest('a, button')
    const isCheckbox = event.target.closest('input[type="checkbox"]')

    if (isLinkOrButton || isCheckbox) {
      return // Don't navigate if a link or button is clicked
    }

    const row = event.target.closest('tr')
    const url = row.dataset.visitPath

    if (!row || !url) {
      return
    }

    if (event.metaKey || event.ctrlKey) {
      this.#visitInNewTab(url)
    } else {
      this.#visitInSameTab(url)
    }
  }

  #visitInSameTab(url) {
    window.Turbo.visit(url)
  }

  #visitInNewTab(url) {
    window.open(url, '_blank').focus()
  }
}

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
avo-3.15.1 app/javascript/js/controllers/table_row_controller.js
avo-3.15.0 app/javascript/js/controllers/table_row_controller.js
avo-3.14.5 app/javascript/js/controllers/table_row_controller.js
avo-3.14.4 app/javascript/js/controllers/table_row_controller.js
avo-3.14.3 app/javascript/js/controllers/table_row_controller.js
avo-3.14.2 app/javascript/js/controllers/table_row_controller.js
avo-3.14.1 app/javascript/js/controllers/table_row_controller.js
avo-3.14.0 app/javascript/js/controllers/table_row_controller.js
avo-3.13.7 app/javascript/js/controllers/table_row_controller.js
avo-3.13.6 app/javascript/js/controllers/table_row_controller.js
avo-3.13.5 app/javascript/js/controllers/table_row_controller.js
avo-3.13.4 app/javascript/js/controllers/table_row_controller.js
avo-3.13.3 app/javascript/js/controllers/table_row_controller.js
avo-3.13.2 app/javascript/js/controllers/table_row_controller.js
avo-3.13.1 app/javascript/js/controllers/table_row_controller.js
avo-3.13.0 app/javascript/js/controllers/table_row_controller.js
avo-3.12.0 app/javascript/js/controllers/table_row_controller.js
avo-3.11.10 app/javascript/js/controllers/table_row_controller.js
avo-3.11.9 app/javascript/js/controllers/table_row_controller.js
avo-3.11.8 app/javascript/js/controllers/table_row_controller.js