diff options
author | Yamagishi Kazutoshi <ykzts@desire.sh> | 2019-09-29 21:30:58 +0900 |
---|---|---|
committer | Thibaut Girka <thib@sitedethib.com> | 2019-10-06 00:32:06 +0200 |
commit | 7d79e1f31c02ea1e1d742aff8b00f45a1ba0e67b (patch) | |
tree | 76ad33a78cfd415439fbec0e9f8852224d30309c /app/javascript/flavours/glitch/util | |
parent | 4b181eba13464287184a90f65e7012ce40b4e3d7 (diff) |
[Glitch] Do not add margin light when opening modal on mobile
Port 0a49b26793d467589be09305e15ff9cc97cdd200 to glitch-soc Signed-off-by: Thibaut Girka <thib@sitedethib.com>
Diffstat (limited to 'app/javascript/flavours/glitch/util')
-rw-r--r-- | app/javascript/flavours/glitch/util/scrollbar.js | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/app/javascript/flavours/glitch/util/scrollbar.js b/app/javascript/flavours/glitch/util/scrollbar.js new file mode 100644 index 000000000..6529b7906 --- /dev/null +++ b/app/javascript/flavours/glitch/util/scrollbar.js @@ -0,0 +1,36 @@ +import { isMobile } from 'flavours/glitch/util/is_mobile'; + +/** @type {number | null} */ +let cachedScrollbarWidth = null; + +/** + * @return {number} + */ +const getActualScrollbarWidth = () => { + const outer = document.createElement('div'); + outer.style.visibility = 'hidden'; + outer.style.overflow = 'scroll'; + document.body.appendChild(outer); + + const inner = document.createElement('div'); + outer.appendChild(inner); + + const scrollbarWidth = outer.offsetWidth - inner.offsetWidth; + outer.parentNode.removeChild(outer); + + return scrollbarWidth; +}; + +/** + * @return {number} + */ +export const getScrollbarWidth = () => { + if (cachedScrollbarWidth !== null) { + return cachedScrollbarWidth; + } + + const scrollbarWidth = isMobile(window.innerWidth) ? 0 : getActualScrollbarWidth(); + cachedScrollbarWidth = scrollbarWidth; + + return scrollbarWidth; +}; |