kopia lustrzana https://github.com/shoelace-style/shoelace
Switch lock array to set operations (#131)
* Switch lock array to set operations * Remove falsy/null check from lockBodyScrolling functionpull/132/head
rodzic
27cf48849c
commit
2821cacb37
|
@ -1,25 +1,23 @@
|
|||
import { getOffset } from './offset';
|
||||
|
||||
let locks = [];
|
||||
const locks = new Set();
|
||||
|
||||
//
|
||||
// Prevents body scrolling. Keeps track of which elements requested a lock so multiple levels of locking are possible
|
||||
// without premature unlocking.
|
||||
//
|
||||
export function lockBodyScrolling(lockingEl: HTMLElement) {
|
||||
if (lockingEl && !locks.includes(lockingEl)) {
|
||||
locks.push(lockingEl);
|
||||
document.body.classList.add('sl-scroll-lock');
|
||||
}
|
||||
locks.add(lockingEl);
|
||||
document.body.classList.add('sl-scroll-lock');
|
||||
}
|
||||
|
||||
//
|
||||
// Unlocks body scrolling. Scrolling will only be unlocked once all elements that requested a lock call this method.
|
||||
//
|
||||
export function unlockBodyScrolling(lockingEl: HTMLElement) {
|
||||
locks = locks.filter(el => el !== lockingEl);
|
||||
locks.delete(lockingEl);
|
||||
|
||||
if (locks.length === 0) {
|
||||
if (locks.size === 0) {
|
||||
document.body.classList.remove('sl-scroll-lock');
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue