diff --git a/src/core/frames/frame_redirector.ts b/src/core/frames/frame_redirector.ts index 96fb89bcc..4c83f5153 100644 --- a/src/core/frames/frame_redirector.ts +++ b/src/core/frames/frame_redirector.ts @@ -24,41 +24,41 @@ export class FrameRedirector implements LinkInterceptorDelegate, FormInterceptor } shouldInterceptLinkClick(element: Element, url: string) { - return this.shouldRedirect(element) + const frame = this.findFrameElement(element) + if (frame) { + return frame.delegate.shouldInterceptLinkClick(element, url) + } else { + return false + } } linkClickIntercepted(element: Element, url: string) { const frame = this.findFrameElement(element) if (frame) { - frame.setAttribute("reloadable", "") - frame.src = url + frame.delegate.linkClickIntercepted(element, url) } } shouldInterceptFormSubmission(element: HTMLFormElement, submitter?: HTMLElement) { - return this.shouldRedirect(element, submitter) + const frame = this.findFrameElement(element, submitter) + if (frame) { + return frame.delegate.shouldInterceptFormSubmission(element, submitter) + } else { + return false + } } formSubmissionIntercepted(element: HTMLFormElement, submitter?: HTMLElement) { const frame = this.findFrameElement(element, submitter) if (frame) { - frame.removeAttribute("reloadable") frame.delegate.formSubmissionIntercepted(element, submitter) } } - private shouldRedirect(element: Element, submitter?: HTMLElement) { - const frame = this.findFrameElement(element, submitter) - return frame ? frame != element.closest("turbo-frame") : false - } - private findFrameElement(element: Element, submitter?: HTMLElement) { const id = submitter?.getAttribute("data-turbo-frame") || element.getAttribute("data-turbo-frame") if (id && id != "_top") { - const frame = this.element.querySelector(`#${id}:not([disabled])`) - if (frame instanceof FrameElement) { - return frame - } + return this.element.querySelector(`turbo-frame#${id}:not([disabled])`) } } } diff --git a/src/elements/frame_element.ts b/src/elements/frame_element.ts index 59c8cc402..2f8d312a3 100644 --- a/src/elements/frame_element.ts +++ b/src/elements/frame_element.ts @@ -1,14 +1,15 @@ import { FetchResponse } from "../http/fetch_response" +import { FormInterceptorDelegate } from "../core/frames/form_interceptor" +import { LinkInterceptorDelegate } from "../core/frames/link_interceptor" export enum FrameLoadingStyle { eager = "eager", lazy = "lazy" } -export interface FrameElementDelegate { +export interface FrameElementDelegate extends LinkInterceptorDelegate, FormInterceptorDelegate { connect(): void disconnect(): void loadingStyleChanged(): void sourceURLChanged(): void disabledChanged(): void - formSubmissionIntercepted(element: HTMLFormElement, submitter?: HTMLElement): void loadResponse(response: FetchResponse): void isLoading: boolean }