From 23188c161f5b624b04d0ae4b5966d13d48b34c46 Mon Sep 17 00:00:00 2001 From: OFF0 Date: Sat, 11 Mar 2023 11:54:55 +0100 Subject: [PATCH] utils: move lock and unlock scroll functions to utils --- src/main.js | 5 +---- src/utils/dom.ts | 6 ++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main.js b/src/main.js index 940d882..9efb74a 100644 --- a/src/main.js +++ b/src/main.js @@ -1,6 +1,6 @@ import {generatePrivateKey, getEventHash, getPublicKey, nip19, signEvent} from 'nostr-tools'; import {zeroLeadingBitsCount} from './utils/crypto'; -import {elem, elemCanvas, elemShrink, parseTextContent} from './utils/dom'; +import {elem, elemCanvas, elemShrink, lockScroll, parseTextContent, unlockScroll} from './utils/dom'; import {bounce, dateTime, formatTime} from './utils/time'; import {getHost, getNoxyUrl, isWssUrl} from './utils/url'; import {sub24hFeed, subNote, subProfile} from './subscriptions' @@ -463,9 +463,6 @@ function appendReplyForm(el) { requestAnimationFrame(() => writeInput.focus()); } -const lockScroll = () => document.body.style.overflow = 'hidden'; -const unlockScroll = () => document.body.style.removeProperty('overflow'); - let fitlerDifficulty = JSON.parse(localStorage.getItem('filter_difficulty')) ?? 0; const filterDifficultyInput = document.querySelector('#filterDifficulty'); const filterDifficultyDisplay = document.querySelector('[data-display="filter_difficulty"]'); diff --git a/src/utils/dom.ts b/src/utils/dom.ts index 7b3c41b..06b8cd0 100644 --- a/src/utils/dom.ts +++ b/src/utils/dom.ts @@ -56,6 +56,12 @@ export const elem = ( return el; }; +/** freeze global page scrolling */ +export const lockScroll = () => document.body.style.overflow = 'hidden'; + +/** free global page scrolling */ +export const unlockScroll = () => document.body.style.removeProperty('overflow'); + export const isValidURL = (url: URL) => { if (!['http:', 'https:'].includes(url.protocol)) { return false;