PageSourceSearch

https://freshjots.com/assets/controllers/paired_download_controller-bad89cd9.js

js freshjots.com collected 2026-10-04 22:56:51 UTC 1,773 bytes, 42 lines download raw bytes

1import { Controller } from "@hotwired/stimulus"
2
3// Attached to the .txt download link. One click downloads two files: the note
4// itself (.txt -- the link's own href) and its notarization proof (proof.json).
5//
6// We take full control of the click rather than letting the link download the
7// .txt natively while JS fires the proof: when a native link download and a
8// JS-fired one happen in the same gesture the browser keeps only one (the .txt,
9// intercepted by Turbo Drive, loses). So we preventDefault and trigger BOTH as
10// separate downloads, each opted out of Turbo Drive (data-turbo="false") so the
11// browser downloads the attachment natively instead of Turbo trying to navigate
12// to it, and staggered slightly so the browser doesn't collapse the two into a
13// single download.
14//
15// Progressive enhancement: with JS off the action never runs, so the native
16// link still downloads the .txt (just not the proof).
17//
18// Delivering two loose files means the browser may show a one-time "allow
19// multiple downloads" prompt; that is inherent to the two-file approach.
20export default class extends Controller {
21  static values = { proofUrl: String }
22
23  trigger(event) {
24    const noteUrl = this.element.href
25    if (!this.hasProofUrlValue || !noteUrl) return // let the native link handle it
26
27    event.preventDefault()
28    this.download(noteUrl)
29    setTimeout(() => this.download(this.proofUrlValue), 150)
30  }
31
32  download(url) {
33    const link = document.createElement("a")
34    link.href = url
35    // Opt out of Turbo Drive so the browser downloads the attachment natively
36    // rather than letting Turbo's click listener try to navigate to the file.
37    link.dataset.turbo = "false"
38    document.body.appendChild(link)
39    link.click()
40    link.remove()
41  }
42}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.