This repository has been archived on 2025-07-20. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
analytics/datasette_plugin/script.js
AKP f20976eeab
Add Datasette config editor plugin
Signed-off-by: AKP <tom@tdpain.net>
2023-04-04 16:35:16 +01:00

26 lines
No EOL
850 B
JavaScript

{
const modalLoadURL = "{{#url}}"
const modalTargetID = "{{#id}}"
// Create edit button in page header
const pageHeader = document.querySelector("div.page-header")
const editElem = document.createElement("a")
editElem.href = "#"
editElem.innerText = "(edit)"
editElem.setAttribute("hx-get", modalLoadURL)
editElem.setAttribute("hx-target", "#" + modalTargetID)
pageHeader.appendChild(editElem)
// Create div to become the modal target
const modalTarget = document.createElement("div")
modalTarget.id = modalTargetID
document.body.appendChild(modalTarget)
// Load HTMX
// TODO: Bundle this and don't rely on a CDN somehow?
const htmxImport = document.createElement("script")
htmxImport.src = "https://unpkg.com/htmx.org@1.8.6"
document.body.appendChild(htmxImport)
}