mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2024-11-21 23:57:30 +00:00
Set and preserve focus when showing post overlay
This commit is contained in:
parent
c5bd24f9d4
commit
f14837be44
@ -5,6 +5,7 @@ import {quota} from "./quota.js"
|
|||||||
/** @type {PostOverlay[]} */
|
/** @type {PostOverlay[]} */
|
||||||
const postOverlays = []
|
const postOverlays = []
|
||||||
const titleHistory = []
|
const titleHistory = []
|
||||||
|
const focusHistory = []
|
||||||
titleHistory.push(document.title)
|
titleHistory.push(document.title)
|
||||||
const shortcodeDataMap = new Map()
|
const shortcodeDataMap = new Map()
|
||||||
|
|
||||||
@ -28,6 +29,10 @@ window.addEventListener("popstate", event => {
|
|||||||
titleHistory.pop()
|
titleHistory.pop()
|
||||||
document.title = titleHistory.slice(-1)[0]
|
document.title = titleHistory.slice(-1)[0]
|
||||||
}
|
}
|
||||||
|
if (focusHistory.length) {
|
||||||
|
const item = focusHistory.pop()
|
||||||
|
item.focus()
|
||||||
|
}
|
||||||
if (postOverlays.length) {
|
if (postOverlays.length) {
|
||||||
popOverlay()
|
popOverlay()
|
||||||
} else {
|
} else {
|
||||||
@ -38,6 +43,7 @@ window.addEventListener("popstate", event => {
|
|||||||
|
|
||||||
function pushOverlay(overlay) {
|
function pushOverlay(overlay) {
|
||||||
postOverlays.push(overlay)
|
postOverlays.push(overlay)
|
||||||
|
focusHistory.push(document.activeElement)
|
||||||
document.body.style.overflowY = "hidden"
|
document.body.style.overflowY = "hidden"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,6 +88,9 @@ class PostOverlay extends ElemJS {
|
|||||||
this.html(html)
|
this.html(html)
|
||||||
this.loaded = true
|
this.loaded = true
|
||||||
this.removeClass("loading")
|
this.removeClass("loading")
|
||||||
|
setTimeout(() => {
|
||||||
|
this.element.focus()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
showError() {
|
showError() {
|
||||||
|
Loading…
Reference in New Issue
Block a user