| 1 | /*! Fiesta 1.2.0 | MPL-2.0 | https://fiesta.rastrillo.org */ |
| 2 | (function () { |
| 3 | "use strict"; |
| 4 | |
| 5 | var ROOT = "[rst-shell-sidebar],[rst-shell-console],.rst-shell-sidebar,.rst-shell-console"; |
| 6 | var INDEX = '[rst-shell-sidebar~="index"],[rst-shell-console~="index"],.rst-shell-sidebar--index,.rst-shell-console--index'; |
| 7 | var PAGE = '[rst-shell-sidebar~="page"],[rst-shell-console~="page"],.rst-shell-sidebar--page,.rst-shell-console--page'; |
| 8 | var BACK = "[rst-shell-back] > a[href],.rst-shell__back > a[href]"; |
| 9 | var NAV = "[rst-shell-nav] a[href],.rst-shell__nav a[href]"; |
| 10 | var NARROW = "(max-width: 799.98px)"; |
| 11 | var RETURN = "rst-shell-return", WENT_BACK = "rst-shell-back"; |
| 12 | |
| 13 | function store(fn) { |
| 14 | try { return fn(window.sessionStorage); } catch (e) { return null; } |
| 15 | } |
| 16 | function take(key) { |
| 17 | return store(function (s) { var v = s.getItem(key); s.removeItem(key); return v; }); |
| 18 | } |
| 19 | function place(href) { |
| 20 | var u = new URL(href, location.href); |
| 21 | return u.origin === location.origin ? u.pathname + u.search : null; |
| 22 | } |
| 23 | function view(sel) { |
| 24 | var r = document.querySelector(ROOT); |
| 25 | return !!r && r.matches(sel); |
| 26 | } |
| 27 | |
| 28 | function returnFocus() { |
| 29 | if (document.prerendering || !view(INDEX)) return; |
| 30 | var rec = take(RETURN), links, hit = null, i, id; |
| 31 | if (!matchMedia(NARROW).matches) return; |
| 32 | links = document.querySelectorAll(NAV); |
| 33 | for (i = 0; rec && !hit && i < links.length; i++) { |
| 34 | if (place(links[i].href) === rec) hit = links[i]; |
| 35 | } |
| 36 | if (!hit && location.hash) { |
| 37 | try { id = decodeURIComponent(location.hash.slice(1)); } catch (e) { id = location.hash.slice(1); } |
| 38 | hit = document.getElementById(id); |
| 39 | if (hit && !hit.matches(NAV)) hit = null; |
| 40 | } |
| 41 | if (hit) hit.focus(); |
| 42 | } |
| 43 | |
| 44 | var observed = new WeakSet(); |
| 45 | function observeTransition(transition) { |
| 46 | if (!transition || observed.has(transition)) return; |
| 47 | observed.add(transition); |
| 48 | ["ready", "finished", "updateCallbackDone"].forEach(function (key) { |
| 49 | if (transition[key]) transition[key].catch(function (err) { |
| 50 | if (!(err instanceof DOMException) || |
| 51 | ["AbortError", "InvalidStateError", "TimeoutError"].indexOf(err.name) < 0) throw err; |
| 52 | }); |
| 53 | }); |
| 54 | } |
| 55 | |
| 56 | observeTransition(document.activeViewTransition); |
| 57 | |
| 58 | function reveal(e) { |
| 59 | observeTransition(e.viewTransition); |
| 60 | var back = take(WENT_BACK) === location.pathname + location.search, a = window.navigation && navigation.activation; |
| 61 | if (!back && a && a.navigationType === "traverse" && a.from && a.entry) back = a.entry.index < a.from.index; |
| 62 | returnFocus(); |
| 63 | if (e.viewTransition && e.viewTransition.types) e.viewTransition.types.add(back ? "back" : "forward"); |
| 64 | } |
| 65 | if ("onpagereveal" in window) window.addEventListener("pagereveal", reveal); |
| 66 | else window.addEventListener("pageshow", returnFocus); |
| 67 | |
| 68 | function leave(e) { |
| 69 | observeTransition(e.viewTransition); |
| 70 | if (view(PAGE)) store(function (s) { s.setItem(RETURN, location.pathname + location.search); }); |
| 71 | } |
| 72 | window.addEventListener("onpageswap" in window ? "pageswap" : "pagehide", leave); |
| 73 | |
| 74 | document.addEventListener("click", function (e) { |
| 75 | var a = e.target.closest && e.target.closest(BACK), nav = window.navigation, cur, prev, want; |
| 76 | if (!a || e.defaultPrevented || e.button !== 0 || e.ctrlKey || e.metaKey || e.shiftKey || e.altKey) return; |
| 77 | want = place(a.href); |
| 78 | if (want !== null) store(function (s) { s.setItem(WENT_BACK, want); }); |
| 79 | cur = nav && nav.currentEntry; |
| 80 | if (!cur || cur.index < 1) return; |
| 81 | prev = nav.entries()[cur.index - 1]; |
| 82 | if (want !== null && prev && !prev.sameDocument && prev.url && place(prev.url) === want) { |
| 83 | e.preventDefault(); |
| 84 | history.back(); |
| 85 | } |
| 86 | }); |
| 87 | })(); |
| 88 | |