@@ -105,3 +105,47 @@ export const tetherAttachements = [
105105 'left middle' ,
106106 'left bottom'
107107] ;
108+
109+ // https://github.com/twbs/bootstrap/blob/v4.0.0-alpha.4/js/src/modal.js#L436-L443
110+ export function getScrollbarWidth ( ) {
111+ let scrollDiv = document . createElement ( 'div' ) ;
112+ // .modal-scrollbar-measure styles // https://github.com/twbs/bootstrap/blob/v4.0.0-alpha.4/scss/_modal.scss#L106-L113
113+ scrollDiv . style . position = 'absolute' ;
114+ scrollDiv . style . top = '-9999px' ;
115+ scrollDiv . style . width = '50px' ;
116+ scrollDiv . style . height = '50px' ;
117+ scrollDiv . style . overflow = 'scroll' ;
118+ document . body . appendChild ( scrollDiv ) ;
119+ const scrollbarWidth = scrollDiv . offsetWidth - scrollDiv . clientWidth ;
120+ document . body . removeChild ( scrollDiv ) ;
121+ return scrollbarWidth ;
122+ }
123+
124+ export function setScrollbarWidth ( padding ) {
125+ document . body . style . paddingRight = padding > 0 ? `${ padding } px` : null ;
126+ }
127+
128+ export function isBodyOverflowing ( ) {
129+ return document . body . clientWidth < window . innerWidth ;
130+ }
131+
132+ export function getOriginalBodyPadding ( ) {
133+ return parseInt (
134+ window . getComputedStyle ( document . body , null ) . getPropertyValue ( 'padding-right' ) || 0 ,
135+ 10
136+ ) ;
137+ }
138+
139+ export function conditionallyUpdateScrollbar ( ) {
140+ const scrollbarWidth = getScrollbarWidth ( ) ;
141+ // https://github.com/twbs/bootstrap/blob/v4.0.0-alpha.4/js/src/modal.js#L420
142+ const fixedContent = document . querySelectorAll ( '.navbar-fixed-top, .navbar-fixed-bottom, .is-fixed' ) [ 0 ] ;
143+ const bodyPadding = fixedContent ? parseInt (
144+ fixedContent . style . paddingRight || 0 ,
145+ 10
146+ ) : 0 ;
147+
148+ if ( isBodyOverflowing ( ) ) {
149+ setScrollbarWidth ( bodyPadding + scrollbarWidth ) ;
150+ }
151+ }
0 commit comments