| 1 | /*! Fiesta 1.2.0 | MPL-2.0 | https://fiesta.rastrillo.org */ |
| 2 | (function () { |
| 3 | "use strict"; |
| 4 | |
| 5 | if (window.CSS && CSS.supports && CSS.supports("position-area: block-end") && CSS.supports("position-try-fallbacks: flip-block")) return; |
| 6 | |
| 7 | document.documentElement.setAttribute("data-rst-flip-menus", ""); |
| 8 | |
| 9 | var DROPDOWN = "[rst-dropdown],.rst-dropdown"; |
| 10 | var PANEL = ":scope > [rst-dropdown-menu], :scope > .rst-dropdown__menu"; |
| 11 | var open = []; |
| 12 | function overflow(r, w) { |
| 13 | return Math.max(0, -r.left) + Math.max(0, r.right - w); |
| 14 | } |
| 15 | function place(d) { |
| 16 | var p = d.querySelector(PANEL), w, before; |
| 17 | if (!p || getComputedStyle(p).position !== "absolute") return; |
| 18 | d.classList.remove("is-flip-inline"); |
| 19 | w = document.documentElement.clientWidth; |
| 20 | before = overflow(p.getBoundingClientRect(), w); |
| 21 | if (!before) return; |
| 22 | d.classList.add("is-flip-inline"); |
| 23 | if (overflow(p.getBoundingClientRect(), w) >= before) d.classList.remove("is-flip-inline"); |
| 24 | } |
| 25 | function replace() { |
| 26 | open = open.filter(function (d) { return d.open && d.isConnected; }); |
| 27 | open.forEach(place); |
| 28 | if (!open.length) removeEventListener("resize", replace); |
| 29 | } |
| 30 | document.addEventListener("toggle", function (e) { |
| 31 | var d = e.target; |
| 32 | if (!d.matches || !d.matches(DROPDOWN)) return; |
| 33 | if (!d.open) return replace(); |
| 34 | place(d); |
| 35 | if (open.indexOf(d) < 0) open.push(d); |
| 36 | addEventListener("resize", replace, { passive: true }); |
| 37 | }, true); |
| 38 | })(); |
| 39 | |