1import Base from "controllers/base"; 2import { enableScroll } from "lib/scroll"; 3 4// Attach to a <dialog class="modal"> alongside the modal controller. Keeps the 5// modal open across a Turbo back/forward restore: it's recorded (and closed) 6// right before the page is cached, then reopened when that snapshot returns. 7export default class extends Base { 8 mount() { 9 this.on("turbo:before-cache", document, this.onBeforeCache); 10 11 if (this.element.dataset.restoreOpen === "true") { 12 delete this.element.dataset.restoreOpen; 13 this.reopen(); 14 } 15 } 16 17 onBeforeCache() { 18 if (this.element.open) { 19 // Mark for restore, then close natively so the cached snapshot is inert. 20 this.element.dataset.restoreOpen = "true"; 21 this.element.close(); 22 enableScroll(); // clear the body scroll lock before we leave the page 23 } else { 24 delete this.element.dataset.restoreOpen; 25 } 26 } 27 28 reopen() { 29 // Defer a frame so the sibling modal controller is connected first. 30 requestAnimationFrame(() => { 31 const modal = this.application.getControllerForElementAndIdentifier( 32 this.element, 33 "modal", 34 ); 35 modal ? modal.open() : this.element.showModal(); 36 }); 37 } 38};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.