refactor using Set
This commit is contained in:
parent
d3a6c030f8
commit
eb695fd61d
@ -2,18 +2,16 @@ import * as bodyScrollLock from 'body-scroll-lock'
|
||||
|
||||
let previousNavPaddingRight
|
||||
let previousAppBgWrapperRight
|
||||
let lockerEls = []
|
||||
const lockerEls = new Set([])
|
||||
|
||||
const disableBodyScroll = (el) => {
|
||||
const scrollBarGap = window.innerWidth - document.documentElement.clientWidth
|
||||
bodyScrollLock.disableBodyScroll(el, {
|
||||
reserveScrollBarGap: true
|
||||
})
|
||||
if (!lockerEls.includes(el)) {
|
||||
lockerEls.push(el)
|
||||
}
|
||||
lockerEls.add(el)
|
||||
setTimeout(() => {
|
||||
if (lockerEls.length <= 1) {
|
||||
if (lockerEls.size <= 1) {
|
||||
// If previousNavPaddingRight is already set, don't set it again.
|
||||
if (previousNavPaddingRight === undefined) {
|
||||
const navEl = document.getElementById('nav')
|
||||
@ -32,11 +30,9 @@ const disableBodyScroll = (el) => {
|
||||
}
|
||||
|
||||
const enableBodyScroll = (el) => {
|
||||
if (lockerEls.includes(el)) {
|
||||
lockerEls = lockerEls.filter(e => e !== el)
|
||||
}
|
||||
lockerEls.delete(el)
|
||||
setTimeout(() => {
|
||||
if (lockerEls.length === 0) {
|
||||
if (lockerEls.size === 0) {
|
||||
if (previousNavPaddingRight !== undefined) {
|
||||
document.getElementById('nav').style.paddingRight = previousNavPaddingRight
|
||||
// Restore previousNavPaddingRight to undefined so disableBodyScroll knows it can be set again.
|
||||
|
Loading…
Reference in New Issue
Block a user