Skip to content

Commit 93c9341

Browse files
committed
fix(ElementsWindow): Focus element if element dom_id is in the url hash
Focus element editor and element in preview if URL contains hash to element editor. The link is coming from the assignment view when showing assigned files or pictures. Signed-off-by: Thomas von Deyen <vondeyen@blish.cloud> (cherry picked from commit 12180b3)
1 parent aba0dfe commit 93c9341

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)