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