File tree 4 files changed +22
-15
lines changed
4 files changed +22
-15
lines changed Original file line number Diff line number Diff line change @@ -424,7 +424,7 @@ export class FrameController {
424
424
425
425
#findFrameElement( element , submitter ) {
426
426
const id = getAttribute ( "data-turbo-frame" , submitter , element ) || this . element . getAttribute ( "target" )
427
- return getFrameElementById ( id ) ?? this . element
427
+ return FrameElement . getElementById ( id ) ?? this . element
428
428
}
429
429
430
430
async extractForeignFrameElement ( container ) {
@@ -468,7 +468,7 @@ export class FrameController {
468
468
}
469
469
470
470
if ( id ) {
471
- const frameElement = getFrameElementById ( id )
471
+ const frameElement = FrameElement . getElementById ( id )
472
472
if ( frameElement ) {
473
473
return ! frameElement . disabled
474
474
}
@@ -554,15 +554,6 @@ export class FrameController {
554
554
}
555
555
}
556
556
557
- function getFrameElementById ( id ) {
558
- if ( id != null ) {
559
- const element = document . getElementById ( id )
560
- if ( element instanceof FrameElement ) {
561
- return element
562
- }
563
- }
564
- }
565
-
566
557
function activateElement ( element , currentURL ) {
567
558
if ( element ) {
568
559
const src = element . getAttribute ( "src" )
Original file line number Diff line number Diff line change @@ -76,8 +76,9 @@ export class FrameRedirector {
76
76
#findFrameElement( element , submitter ) {
77
77
const id = submitter ?. getAttribute ( "data-turbo-frame" ) || element . getAttribute ( "data-turbo-frame" )
78
78
if ( id && id != "_top" ) {
79
- const frame = this . element . querySelector ( `#${ id } :not([disabled])` )
80
- if ( frame instanceof FrameElement ) {
79
+ const frame = FrameElement . getElementById ( id )
80
+
81
+ if ( frame && ! frame . disabled && this . element . contains ( frame ) ) {
81
82
return frame
82
83
}
83
84
}
Original file line number Diff line number Diff line change @@ -163,9 +163,9 @@ export class Session {
163
163
const frameTarget = element . getAttribute ( "data-turbo-frame" )
164
164
const frame = frameTarget == "_top" ?
165
165
null :
166
- document . getElementById ( frameTarget ) || findClosestRecursively ( element , "turbo-frame:not([disabled]) " )
166
+ FrameElement . getElementById ( frameTarget ) || findClosestRecursively ( element , "turbo-frame" )
167
167
168
- if ( isUnsafe || isStream || frame instanceof FrameElement ) {
168
+ if ( isUnsafe || isStream || ( frame && ! frame . disabled ) ) {
169
169
return false
170
170
} else {
171
171
const location = new URL ( element . href )
Original file line number Diff line number Diff line change @@ -28,6 +28,21 @@ export class FrameElement extends HTMLElement {
28
28
return [ "disabled" , "loading" , "src" ]
29
29
}
30
30
31
+ /**
32
+ * Returns the `<turbo-frame>` element located by its `[id]` attribute.
33
+ * Returns `null` when there is not element with a matching `[id]`, or when
34
+ * the element with a matching `[id]` is not a `<turbo-frame>`.
35
+ */
36
+ static getElementById ( id ) {
37
+ if ( id ) {
38
+ const element = document . getElementById ( id )
39
+
40
+ if ( element instanceof this ) {
41
+ return element
42
+ }
43
+ }
44
+ }
45
+
31
46
constructor ( ) {
32
47
super ( )
33
48
this . delegate = new FrameElement . delegateConstructor ( this )
You can’t perform that action at this time.
0 commit comments