Commit eb695fd6 authored by Tae Hoon's avatar Tae Hoon

refactor using Set

parent d3a6c030
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment