@@ -796,6 +796,7 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
796796
797797 var Modal = function ( element , options ) {
798798 this . options = options
799+ this . $body = $ ( document . body )
799800 this . $element = $ ( element )
800801 this . $backdrop =
801802 this . isShown = null
@@ -829,6 +830,9 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
829830
830831 this . isShown = true
831832
833+ this . $body . addClass ( 'modal-open' )
834+
835+ this . setScrollbar ( )
832836 this . escape ( )
833837
834838 this . $element . on ( 'click.dismiss.bs.modal' , '[data-dismiss="modal"]' , $ . proxy ( this . hide , this ) )
@@ -837,7 +841,7 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
837841 var transition = $ . support . transition && that . $element . hasClass ( 'fade' )
838842
839843 if ( ! that . $element . parent ( ) . length ) {
840- that . $element . appendTo ( document . body ) // don't move modals dom position
844+ that . $element . appendTo ( that . $ body) // don't move modals dom position
841845 }
842846
843847 that . $element
@@ -877,6 +881,9 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
877881
878882 this . isShown = false
879883
884+ this . $body . removeClass ( 'modal-open' )
885+
886+ this . resetScrollbar ( )
880887 this . escape ( )
881888
882889 $ ( document ) . off ( 'focusin.bs.modal' )
@@ -934,7 +941,7 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
934941 var doAnimate = $ . support . transition && animate
935942
936943 this . $backdrop = $ ( '<div class="modal-backdrop ' + animate + '" />' )
937- . appendTo ( document . body )
944+ . appendTo ( this . $ body)
938945
939946 this . $element . on ( 'click.dismiss.bs.modal' , $ . proxy ( function ( e ) {
940947 if ( e . target !== e . currentTarget ) return
@@ -969,6 +976,26 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
969976 }
970977 }
971978
979+ Modal . prototype . setScrollbar = function ( ) {
980+ if ( document . body . clientHeight <= window . innerHeight ) return
981+ var scrollbarWidth = this . measureScrollbar ( )
982+ var bodyPad = parseInt ( this . $body . css ( 'padding-right' ) || 0 )
983+ if ( scrollbarWidth ) this . $body . css ( 'padding-right' , bodyPad + scrollbarWidth )
984+ }
985+
986+ Modal . prototype . resetScrollbar = function ( ) {
987+ this . $body . css ( 'padding-right' , '' )
988+ }
989+
990+ Modal . prototype . measureScrollbar = function ( ) { // thx walsh
991+ var scrollDiv = document . createElement ( 'div' )
992+ scrollDiv . className = 'modal-scrollbar-measure'
993+ this . $body . append ( scrollDiv )
994+ var scrollbarWidth = scrollDiv . offsetWidth - scrollDiv . clientWidth
995+ this . $body [ 0 ] . removeChild ( scrollDiv )
996+ return scrollbarWidth
997+ }
998+
972999
9731000 // MODAL PLUGIN DEFINITION
9741001 // =======================
@@ -1017,10 +1044,6 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
10171044 } )
10181045 } )
10191046
1020- $ ( document )
1021- . on ( 'show.bs.modal' , '.modal' , function ( ) { $ ( document . body ) . addClass ( 'modal-open' ) } )
1022- . on ( 'hidden.bs.modal' , '.modal' , function ( ) { $ ( document . body ) . removeClass ( 'modal-open' ) } )
1023-
10241047} ( jQuery ) ;
10251048
10261049/* ========================================================================
@@ -1054,7 +1077,7 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
10541077 animation : true ,
10551078 placement : 'top' ,
10561079 selector : false ,
1057- template : '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>' ,
1080+ template : '<div class="tooltip" role="tooltip" ><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>' ,
10581081 trigger : 'hover focus' ,
10591082 title : '' ,
10601083 delay : 0 ,
@@ -1600,7 +1623,7 @@ if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript re
16001623
16011624 ScrollSpy . prototype . process = function ( ) {
16021625 var scrollTop = this . $scrollElement . scrollTop ( ) + this . options . offset
1603- var scrollHeight = this . $scrollElement [ 0 ] . scrollHeight || this . $body [ 0 ] . scrollHeight
1626+ var scrollHeight = this . $scrollElement [ 0 ] . scrollHeight || Math . max ( this . $body [ 0 ] . scrollHeight , document . documentElement . scrollHeight )
16041627 var maxScroll = scrollHeight - this . $scrollElement . height ( )
16051628 var offsets = this . offsets
16061629 var targets = this . targets
0 commit comments