diff --git a/src/core/frames/frame_controller.ts b/src/core/frames/frame_controller.ts index b31a23a4a..eb4655dde 100644 --- a/src/core/frames/frame_controller.ts +++ b/src/core/frames/frame_controller.ts @@ -213,7 +213,7 @@ export class FrameController implements AppearanceObserverDelegate, FetchRequest private findFrameElement(element: Element) { const id = element.getAttribute("data-turbo-frame") || this.element.getAttribute("target") - return getFrameElementById(id) ?? this.element + return FrameElement.getElementById(document, id) ?? this.element } async extractForeignFrameElement(container: ParentNode): Promise { @@ -238,16 +238,11 @@ export class FrameController implements AppearanceObserverDelegate, FetchRequest if (!this.enabled || id == "_top") { return false + } else if (id) { + return !!FrameElement.getElementById(document, id) + } else { + return true } - - if (id) { - const frameElement = getFrameElementById(id) - if (frameElement) { - return !frameElement.disabled - } - } - - return true } // Computed properties @@ -277,15 +272,6 @@ export class FrameController implements AppearanceObserverDelegate, FetchRequest } } -function getFrameElementById(id: string | null) { - if (id != null) { - const element = document.getElementById(id) - if (element instanceof FrameElement) { - return element - } - } -} - function activateElement(element: Node | null) { if (element && element.ownerDocument !== document) { element = document.importNode(element, true) diff --git a/src/core/frames/frame_redirector.ts b/src/core/frames/frame_redirector.ts index 1310e3eab..cf8da9423 100644 --- a/src/core/frames/frame_redirector.ts +++ b/src/core/frames/frame_redirector.ts @@ -51,12 +51,6 @@ export class FrameRedirector implements LinkInterceptorDelegate, FormInterceptor } private findFrameElement(element: Element) { - const id = element.getAttribute("data-turbo-frame") - if (id && id != "_top") { - const frame = this.element.querySelector(`#${id}:not([disabled])`) - if (frame instanceof FrameElement) { - return frame - } - } + return FrameElement.getElementById(this.element, element.getAttribute("data-turbo-frame")) } } diff --git a/src/elements/frame_element.ts b/src/elements/frame_element.ts index c91e09edb..0dfab0990 100644 --- a/src/elements/frame_element.ts +++ b/src/elements/frame_element.ts @@ -23,6 +23,15 @@ export class FrameElement extends HTMLElement { return ["loading", "src"] } + static getElementById(container: Element | Document, id: string | null): FrameElement | undefined { + if (id && id != "_top") { + const frame = container.querySelector(`#${id}:not([disabled])`) + if (frame instanceof FrameElement) { + return frame + } + } + } + constructor() { super() this.delegate = new FrameElement.delegateConstructor(this)