Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 54 additions & 7 deletions docs/_overrides/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,19 @@
: document.querySelector("[data-aaasm-outdated]");
if (!host) return;

// Derive the current version directory and the versions.json URL from the
// page location: mike serves each version under /<base>/<version>/, with
// versions.json one level up at /<base>/versions.json.
var path = window.location.pathname.replace(/\/+$/, "");
var segments = path.split("/");
var current = segments.pop() || "";
var versionsUrl = segments.join("/") + "/versions.json";
// mike serves each version under /<base>/<version>/, with versions.json
// one level up at /<base>/versions.json. mkdocs renders `base_url` so it
// points at the deploy root (the current version directory) from *any*
// page depth, so the deploy-root versions.json is reliably one level
// above it. Resolving the bare relative `base_url` against `location`
// yields an absolute URL; popping only the page's last path segment (the
// previous approach) 404s on deep pages.
var versionRoot = new URL("{{ base_url }}/", window.location);
var versionsUrl = new URL("../versions.json", versionRoot).toString();

// The current version id is the last path segment of the deploy root.
var current =
versionRoot.pathname.replace(/\/+$/, "").split("/").pop() || "";

fetch(versionsUrl, { cache: "no-store" })
.then(function (r) { return r.ok ? r.json() : []; })
Expand Down Expand Up @@ -103,3 +109,44 @@
})();
</script>
{% endblock %}

{#-
Feedback widget decoupling (AAASM-3557, fixes the AAASM-3555 regression).

Material only reveals `form.md-feedback` (form.hidden = false) and wires the
πŸ‘/πŸ‘Ž click handlers from inside its generated `__md_analytics()`, which runs
only after analytics consent is granted. With opt-in consent (off by default)
ordinary visitors never see the widget.

This script reveals the widget for everyone and wires our own handlers so the
thank-you note / "open an issue" link works without consent. It deliberately
does NOT call gtag: when consent IS granted, Material's own handler sends the
GA `feedback` event. Keeping the event in Material's handler preserves the
GDPR posture (event stays consent-gated) and avoids double-counting.
-#}
{% block scripts %}
{{ super() }}
<script>
document$.subscribe(function () {
var form = document.forms.feedback;
if (!form) return;
form.hidden = false; // always reveal the widget
if (form.dataset.aaWired) return; // wire our handlers once per form
form.dataset.aaWired = "1";
form.querySelectorAll("[type=submit]").forEach(function (btn) {
btn.addEventListener("click", function (e) {
e.preventDefault();
var d = btn.getAttribute("data-md-value");
var note = form.querySelector(
".md-feedback__note [data-md-value='" + d + "']"
);
if (note) note.hidden = false; // show the thank-you / issue link
form.firstElementChild.disabled = true;
// Intentionally no gtag call here β€” Material's analytics handler
// (active only with consent) sends the GA `feedback` event. This
// keeps the event consent-gated and avoids double-counting.
});
});
});
</script>
{% endblock %}
13 changes: 13 additions & 0 deletions docs/_overrides/partials/javascripts/outdated.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{#-
Override of Material's partials/javascripts/outdated.html (AAASM-3557).

Material's generated script calls `new URL("{{ base_url }}")` with no base
argument. On many pages `base_url` is a bare relative value such as `.` or
`..`, which is not an absolute URL, so `new URL("..")` throws
`TypeError: Failed to construct 'URL': Invalid URL` on every page load.

The only change here is passing `location` as the base so the relative
`base_url` resolves against the current page. Behaviour is otherwise identical
to Material's generated script.
-#}
<script>var el=document.querySelector("[data-md-component=outdated]"),base=new URL("{{ base_url }}",location),outdated=__md_get("__outdated",sessionStorage,base);!0===outdated&&el&&(el.hidden=!1)</script>