Sha256: 7e0a8b460653816b26af04f97efae2e48346d5f3280902a640927c947bf3e854
Contents?: true
Size: 740 Bytes
Versions: 9
Compression:
Stored size: 740 Bytes
Contents
import { Controller } from "@hotwired/stimulus"; import { Turbo } from "@hotwired/turbo"; export default class TurboCollectionController extends Controller { static values = { url: String, sort: String, }; urlValueChanged(url) { Turbo.navigator.history.replace(this.#url(url)); } sortValueChanged(sort) { document.querySelectorAll(this.#sortSelector).forEach((input) => { if (input) input.value = sort; }); } get #sortSelector() { return "input[name='sort']"; } #url(relativeUrl) { const frame = this.element.closest("turbo-frame"); if (frame) { return new URL(relativeUrl, frame.baseURI); } else { return new URL(relativeUrl, window.location.href); } } }
Version data entries
9 entries across 9 versions & 1 rubygems