Drop jQuery dependency

pull/2046/head
Simon Willison 2023-03-26 16:38:58 -07:00 zatwierdzone przez GitHub
rodzic db8cf899e2
commit c025b0180f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 15 dodań i 13 usunięć

Wyświetl plik

@ -8,7 +8,7 @@
{% block scripts %} {% block scripts %}
{{ super() }} {{ super() }}
<script> <script>
jQuery(function ($) { document.addEventListener("DOMContentLoaded", function() {
// Show banner linking to /stable/ if this is a /latest/ page // Show banner linking to /stable/ if this is a /latest/ page
if (!/\/latest\//.test(location.pathname)) { if (!/\/latest\//.test(location.pathname)) {
return; return;
@ -16,18 +16,20 @@ jQuery(function ($) {
var stableUrl = location.pathname.replace("/latest/", "/stable/"); var stableUrl = location.pathname.replace("/latest/", "/stable/");
// Check it's not a 404 // Check it's not a 404
fetch(stableUrl, { method: "HEAD" }).then((response) => { fetch(stableUrl, { method: "HEAD" }).then((response) => {
if (response.status == 200) { if (response.status === 200) {
var warning = $( var warning = document.createElement("div");
`<div class="admonition warning"> warning.className = "admonition warning";
<p class="first admonition-title">Note</p> warning.innerHTML = `
<p class="last"> <p class="first admonition-title">Note</p>
This documentation covers the <strong>development version</strong> of Datasette.</p> <p class="last">
<p>See <a href="${stableUrl}">this page</a> for the current stable release. This documentation covers the <strong>development version</strong> of Datasette.
</p> </p>
</div>` <p>
); See <a href="${stableUrl}">this page</a> for the current stable release.
warning.find("a").attr("href", stableUrl); </p>
$("article[role=main]").prepend(warning); `;
var mainArticle = document.querySelector("article[role=main]");
mainArticle.insertBefore(warning, mainArticle.firstChild);
} }
}); });
}); });