mirror of
https://github.com/twbs/bootstrap.git
synced 2025-09-29 06:49:06 +02:00
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
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user