aboutsummaryrefslogtreecommitdiff
path: root/js/src/util/scrollbar.js
diff options
context:
space:
mode:
authorXhmikosR <[email protected]>2021-10-13 15:19:28 +0300
committerGitHub <[email protected]>2021-10-13 15:19:28 +0300
commite8f702666f285a3e69866ed1f8d29fa6eaaaeabb (patch)
tree944b2dc894f49f8278d41d096e4388e9ac83157b /js/src/util/scrollbar.js
parentdb44392bda22f3d5319d2880c992f76d27d2a60c (diff)
downloadbootstrap-e8f702666f285a3e69866ed1f8d29fa6eaaaeabb.tar.xz
bootstrap-e8f702666f285a3e69866ed1f8d29fa6eaaaeabb.zip
JS: minor refactoring (#35183)
* add missing comments * shorten block comments * reorder constants * reorder public/private methods * sort exports alphabetically in util/index.js * fix a couple of typos
Diffstat (limited to 'js/src/util/scrollbar.js')
-rw-r--r--js/src/util/scrollbar.js32
1 files changed, 21 insertions, 11 deletions
diff --git a/js/src/util/scrollbar.js b/js/src/util/scrollbar.js
index 16e14d1f3..55b7244ab 100644
--- a/js/src/util/scrollbar.js
+++ b/js/src/util/scrollbar.js
@@ -9,14 +9,23 @@ import SelectorEngine from '../dom/selector-engine'
import Manipulator from '../dom/manipulator'
import { isElement } from './index'
+/**
+ * Constants
+ */
+
const SELECTOR_FIXED_CONTENT = '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top'
const SELECTOR_STICKY_CONTENT = '.sticky-top'
+/**
+ * Class definition
+ */
+
class ScrollBarHelper {
constructor() {
this._element = document.body
}
+ // Public
getWidth() {
// https://developer.mozilla.org/en-US/docs/Web/API/Window/innerWidth#usage_notes
const documentWidth = document.documentElement.clientWidth
@@ -33,6 +42,18 @@ class ScrollBarHelper {
this._setElementAttributes(SELECTOR_STICKY_CONTENT, 'marginRight', calculatedValue => calculatedValue - width)
}
+ reset() {
+ this._resetElementAttributes(this._element, 'overflow')
+ this._resetElementAttributes(this._element, 'paddingRight')
+ this._resetElementAttributes(SELECTOR_FIXED_CONTENT, 'paddingRight')
+ this._resetElementAttributes(SELECTOR_STICKY_CONTENT, 'marginRight')
+ }
+
+ isOverflowing() {
+ return this.getWidth() > 0
+ }
+
+ // Private
_disableOverFlow() {
this._saveInitialAttribute(this._element, 'overflow')
this._element.style.overflow = 'hidden'
@@ -53,13 +74,6 @@ class ScrollBarHelper {
this._applyManipulationCallback(selector, manipulationCallBack)
}
- reset() {
- this._resetElementAttributes(this._element, 'overflow')
- this._resetElementAttributes(this._element, 'paddingRight')
- this._resetElementAttributes(SELECTOR_FIXED_CONTENT, 'paddingRight')
- this._resetElementAttributes(SELECTOR_STICKY_CONTENT, 'marginRight')
- }
-
_saveInitialAttribute(element, styleProp) {
const actualValue = element.style[styleProp]
if (actualValue) {
@@ -90,10 +104,6 @@ class ScrollBarHelper {
}
}
}
-
- isOverflowing() {
- return this.getWidth() > 0
- }
}
export default ScrollBarHelper