2022-05-13 08:07:23 +02:00
/ * !
2022-10-03 09:44:02 +02:00
* Bootstrap scrollbar . js v5 . 2.2 ( https : //getbootstrap.com/)
2022-05-13 08:07:23 +02:00
* Copyright 2011 - 2022 The Bootstrap Authors ( https : //github.com/twbs/bootstrap/graphs/contributors)
* Licensed under MIT ( https : //github.com/twbs/bootstrap/blob/main/LICENSE)
* /
( function ( global , factory ) {
typeof exports === 'object' && typeof module !== 'undefined' ? module . exports = factory ( require ( '../dom/selector-engine' ) , require ( '../dom/manipulator' ) , require ( './index' ) ) :
typeof define === 'function' && define . amd ? define ( [ '../dom/selector-engine' , '../dom/manipulator' , './index' ] , factory ) :
( global = typeof globalThis !== 'undefined' ? globalThis : global || self , global . Scrollbar = factory ( global . SelectorEngine , global . Manipulator , global . Index ) ) ;
} ) ( this , ( function ( SelectorEngine , Manipulator , index ) { 'use strict' ;
const _interopDefaultLegacy = e => e && typeof e === 'object' && 'default' in e ? e : { default : e } ;
const SelectorEngine _ _default = /*#__PURE__*/ _interopDefaultLegacy ( SelectorEngine ) ;
const Manipulator _ _default = /*#__PURE__*/ _interopDefaultLegacy ( Manipulator ) ;
/ * *
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
2022-10-03 09:44:02 +02:00
* Bootstrap ( v5 . 2.2 ) : util / scrollBar . js
2022-05-13 08:07:23 +02:00
* Licensed under MIT ( https : //github.com/twbs/bootstrap/blob/main/LICENSE)
* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
* /
/ * *
* Constants
* /
const SELECTOR _FIXED _CONTENT = '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top' ;
const SELECTOR _STICKY _CONTENT = '.sticky-top' ;
const PROPERTY _PADDING = 'padding-right' ;
const PROPERTY _MARGIN = 'margin-right' ;
/ * *
* 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 ;
return Math . abs ( window . innerWidth - documentWidth ) ;
}
hide ( ) {
const width = this . getWidth ( ) ;
this . _disableOverFlow ( ) ; // give padding to element to balance the hidden scrollbar width
this . _setElementAttributes ( this . _element , PROPERTY _PADDING , calculatedValue => calculatedValue + width ) ; // trick: We adjust positive paddingRight and negative marginRight to sticky-top elements to keep showing fullwidth
this . _setElementAttributes ( SELECTOR _FIXED _CONTENT , PROPERTY _PADDING , calculatedValue => calculatedValue + width ) ;
this . _setElementAttributes ( SELECTOR _STICKY _CONTENT , PROPERTY _MARGIN , calculatedValue => calculatedValue - width ) ;
}
reset ( ) {
this . _resetElementAttributes ( this . _element , 'overflow' ) ;
this . _resetElementAttributes ( this . _element , PROPERTY _PADDING ) ;
this . _resetElementAttributes ( SELECTOR _FIXED _CONTENT , PROPERTY _PADDING ) ;
this . _resetElementAttributes ( SELECTOR _STICKY _CONTENT , PROPERTY _MARGIN ) ;
}
isOverflowing ( ) {
return this . getWidth ( ) > 0 ;
} // Private
_disableOverFlow ( ) {
this . _saveInitialAttribute ( this . _element , 'overflow' ) ;
this . _element . style . overflow = 'hidden' ;
}
_setElementAttributes ( selector , styleProperty , callback ) {
const scrollbarWidth = this . getWidth ( ) ;
const manipulationCallBack = element => {
if ( element !== this . _element && window . innerWidth > element . clientWidth + scrollbarWidth ) {
return ;
}
this . _saveInitialAttribute ( element , styleProperty ) ;
const calculatedValue = window . getComputedStyle ( element ) . getPropertyValue ( styleProperty ) ;
element . style . setProperty ( styleProperty , ` ${ callback ( Number . parseFloat ( calculatedValue ) ) } px ` ) ;
} ;
this . _applyManipulationCallback ( selector , manipulationCallBack ) ;
}
_saveInitialAttribute ( element , styleProperty ) {
const actualValue = element . style . getPropertyValue ( styleProperty ) ;
if ( actualValue ) {
Manipulator _ _default . default . setDataAttribute ( element , styleProperty , actualValue ) ;
}
}
_resetElementAttributes ( selector , styleProperty ) {
const manipulationCallBack = element => {
const value = Manipulator _ _default . default . getDataAttribute ( element , styleProperty ) ; // We only want to remove the property if the value is `null`; the value can also be zero
if ( value === null ) {
element . style . removeProperty ( styleProperty ) ;
return ;
}
Manipulator _ _default . default . removeDataAttribute ( element , styleProperty ) ;
element . style . setProperty ( styleProperty , value ) ;
} ;
this . _applyManipulationCallback ( selector , manipulationCallBack ) ;
}
_applyManipulationCallback ( selector , callBack ) {
if ( index . isElement ( selector ) ) {
callBack ( selector ) ;
return ;
}
for ( const sel of SelectorEngine _ _default . default . find ( selector , this . _element ) ) {
callBack ( sel ) ;
}
}
}
return ScrollBarHelper ;
} ) ) ;
//# sourceMappingURL=scrollbar.js.map