-- Copyright 2026 Joshua Rich . -- SPDX-License-Identifier: AGPL-3.0-or-later -- GetQueryParam will fetch the value of the given query parameter. If no query parameter exists with the given name, an -- empty string is returned. def GetQueryParam(name) make a URLSearchParams from the search of the document's location called query if query.has(name) set value to the query.get(name) return value else return '' end end -- loadingButton defines a behavior that will disable a button while a request it triggered is in process. def loadingButton behavior LoadingButton on htmx:beforeRequest from me add .in-flight-request to me set my.disabled to true on htmx:afterRequest from me remove .in-flight-request from me set my.disabled to false end end -- revealAtBottom defines a behavior that will reveal the element when the user scrolls to the bottom of a page. def revealAtBottom behavior RevealAtBottom on load or scroll from window if (window.scrollY + window.innerHeight) >= document.body.scrollHeight remove .hidden from me add .flex to me end end end -- handleReadStatus defines a behavior that toggles the value of an input that indicates the read status of an object. def handleReadStatus behavior HandleReadStatus on htmx:afterRequest(successful) tell the previous get your value if your value equals 'read' set your value to 'unread' else set your value to 'read' end halt the event's bubbling on htmx:afterRequest(failed) toggle @checked on me end end