Skip to content

Commit ffd46f8

Browse files
authored
Merge pull request #3521 from AlchemyCMS/backport/8.0-stable/pr-3518
[8.0-stable] fix(ElementsWindow): Focus element if element dom_id is in the url hash
2 parents 3c9c25e + 93c9341 commit ffd46f8

File tree

2 files changed

+431
-3
lines changed

2 files changed

+431
-3
lines changed

app/javascript/alchemy_admin/components/elements_window.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import SortableElements from "alchemy_admin/sortable_elements"
2+
import { ElementEditor } from "alchemy_admin/components/element_editor"
23

34
class ElementsWindow extends HTMLElement {
45
#visible = true
@@ -15,9 +16,7 @@ class ElementsWindow extends HTMLElement {
1516
this.toggle()
1617
})
1718
if (window.location.hash) {
18-
document
19-
.querySelector(window.location.hash)
20-
?.trigger("FocusElementEditor.Alchemy")
19+
this.focusElementEditor(window.location.hash)
2120
}
2221
SortableElements()
2322
this.resize()
@@ -64,6 +63,16 @@ class ElementsWindow extends HTMLElement {
6463
}
6564
}
6665

66+
// Focus element editor and element in preview if URL contains hash to element editor.
67+
// The link is coming from the assignment view when showing assigned files or pictures.
68+
focusElementEditor(dom_id) {
69+
const el = document.querySelector(dom_id)
70+
71+
if (el instanceof ElementEditor) {
72+
el.focusElement() && el.focusElementPreview()
73+
}
74+
}
75+
6776
get collapseButton() {
6877
return this.querySelector("#collapse-all-elements-button")
6978
}

0 commit comments

Comments
 (0)