@@ -65,7 +65,8 @@ $.modal = $.fn.modal = function(parameters) {
65
65
moduleNamespace = 'module-' + namespace ,
66
66
67
67
$module = $ ( this ) ,
68
- $context = [ window , document ] . indexOf ( settings . context ) < 0 ? $ ( document ) . find ( settings . context ) : $ ( settings . context ) ,
68
+ $context = [ window , document ] . indexOf ( settings . context ) < 0 ? $document . find ( settings . context ) : $body ,
69
+ isBody = $context [ 0 ] === $body [ 0 ] ,
69
70
$closeIcon = $module . find ( selector . closeIcon ) ,
70
71
$inputs ,
71
72
@@ -86,6 +87,8 @@ $.modal = $.fn.modal = function(parameters) {
86
87
initialMouseDownInScrollbar ,
87
88
initialBodyMargin = '' ,
88
89
tempBodyMargin = '' ,
90
+ keepScrollingClass = false ,
91
+ hadScrollbar = false ,
89
92
90
93
elementEventNamespace ,
91
94
id ,
@@ -203,6 +206,7 @@ $.modal = $.fn.modal = function(parameters) {
203
206
}
204
207
module . debug ( 'Creating dimmer' ) ;
205
208
$dimmable = $context . dimmer ( dimmerSettings ) ;
209
+ keepScrollingClass = module . is . scrolling ( ) ;
206
210
if ( settings . detachable ) {
207
211
module . verbose ( 'Modal is detachable, moving content into dimmer' ) ;
208
212
$dimmable . dimmer ( 'add content' , $module ) ;
@@ -328,13 +332,13 @@ $.modal = $.fn.modal = function(parameters) {
328
332
} ,
329
333
scrollLock : function ( ) {
330
334
// touch events default to passive, due to changes in chrome to optimize mobile perf
331
- $dimmable . get ( 0 ) . addEventListener ( 'touchmove' , module . event . preventScroll , { passive : false } ) ;
335
+ $dimmable [ 0 ] . addEventListener ( 'touchmove' , module . event . preventScroll , { passive : false } ) ;
332
336
}
333
337
} ,
334
338
335
339
unbind : {
336
340
scrollLock : function ( ) {
337
- $dimmable . get ( 0 ) . removeEventListener ( 'touchmove' , module . event . preventScroll , { passive : false } ) ;
341
+ $dimmable [ 0 ] . removeEventListener ( 'touchmove' , module . event . preventScroll , { passive : false } ) ;
338
342
}
339
343
} ,
340
344
@@ -416,7 +420,7 @@ $.modal = $.fn.modal = function(parameters) {
416
420
if ( initialMouseDownInModal ) {
417
421
module . verbose ( 'Mouse down event registered inside the modal' ) ;
418
422
}
419
- initialMouseDownInScrollbar = module . is . scrolling ( ) && ( ( ! isRtl && $ ( window ) . outerWidth ( ) - settings . scrollbarWidth <= event . clientX ) || ( isRtl && settings . scrollbarWidth >= event . clientX ) ) ;
423
+ initialMouseDownInScrollbar = module . is . scrolling ( ) && ( ( ! isRtl && $window . outerWidth ( ) - settings . scrollbarWidth <= event . clientX ) || ( isRtl && settings . scrollbarWidth >= event . clientX ) ) ;
420
424
if ( initialMouseDownInScrollbar ) {
421
425
module . verbose ( 'Mouse down event registered inside the scrollbar' ) ;
422
426
}
@@ -520,9 +524,12 @@ $.modal = $.fn.modal = function(parameters) {
520
524
module . verbose ( 'Show callback returned false cancelling show' ) ;
521
525
return ;
522
526
}
527
+ hadScrollbar = module . has . scrollbar ( ) ;
523
528
module . showDimmer ( ) ;
524
529
module . cacheSizes ( ) ;
525
- module . set . bodyMargin ( ) ;
530
+ if ( hadScrollbar ) {
531
+ module . set . bodyMargin ( ) ;
532
+ }
526
533
if ( module . can . useFlex ( ) ) {
527
534
module . remove . legacy ( ) ;
528
535
}
@@ -651,7 +658,12 @@ $.modal = $.fn.modal = function(parameters) {
651
658
652
659
showDimmer : function ( ) {
653
660
if ( $dimmable . dimmer ( 'is animating' ) || ! $dimmable . dimmer ( 'is active' ) ) {
654
- module . save . bodyMargin ( ) ;
661
+ if ( hadScrollbar ) {
662
+ if ( ! isBody ) {
663
+ $dimmer . css ( 'top' , $dimmable . scrollTop ( ) ) ;
664
+ }
665
+ module . save . bodyMargin ( ) ;
666
+ }
655
667
module . debug ( 'Showing dimmer' ) ;
656
668
$dimmable . dimmer ( 'show' ) ;
657
669
}
@@ -664,7 +676,9 @@ $.modal = $.fn.modal = function(parameters) {
664
676
if ( $dimmable . dimmer ( 'is animating' ) || ( $dimmable . dimmer ( 'is active' ) ) ) {
665
677
module . unbind . scrollLock ( ) ;
666
678
$dimmable . dimmer ( 'hide' , function ( ) {
667
- module . restore . bodyMargin ( ) ;
679
+ if ( hadScrollbar ) {
680
+ module . restore . bodyMargin ( ) ;
681
+ }
668
682
module . remove . clickaway ( ) ;
669
683
module . remove . screenHeight ( ) ;
670
684
} ) ;
@@ -744,9 +758,9 @@ $.modal = $.fn.modal = function(parameters) {
744
758
}
745
759
} ,
746
760
bodyMargin : function ( ) {
747
- initialBodyMargin = $body . css ( 'margin-' + ( module . can . leftBodyScrollbar ( ) ? 'left' :'right' ) ) ;
761
+ initialBodyMargin = $context . css ( ( isBody ? 'margin-' : 'padding-' ) + ( module . can . leftBodyScrollbar ( ) ? 'left' :'right' ) ) ;
748
762
var bodyMarginRightPixel = parseInt ( initialBodyMargin . replace ( / [ ^ \d . ] / g, '' ) ) ,
749
- bodyScrollbarWidth = window . innerWidth - document . documentElement . clientWidth ;
763
+ bodyScrollbarWidth = isBody ? window . innerWidth - document . documentElement . clientWidth : $context [ 0 ] . offsetWidth - $context [ 0 ] . clientWidth ;
750
764
tempBodyMargin = bodyMarginRightPixel + bodyScrollbarWidth ;
751
765
}
752
766
} ,
@@ -759,8 +773,8 @@ $.modal = $.fn.modal = function(parameters) {
759
773
} ,
760
774
bodyMargin : function ( ) {
761
775
var position = module . can . leftBodyScrollbar ( ) ? 'left' :'right' ;
762
- $body . css ( 'margin-' + position , initialBodyMargin ) ;
763
- $body . find ( selector . bodyFixed . replace ( 'right' , position ) ) . each ( function ( ) {
776
+ $context . css ( ( isBody ? 'margin-' : 'padding-' ) + position , initialBodyMargin ) ;
777
+ $context . find ( selector . bodyFixed . replace ( 'right' , position ) ) . each ( function ( ) {
764
778
var el = $ ( this ) ,
765
779
attribute = el . css ( 'position' ) === 'fixed' ? 'padding-' + position : position
766
780
;
@@ -794,16 +808,17 @@ $.modal = $.fn.modal = function(parameters) {
794
808
$dimmable . removeClass ( className . blurring ) ;
795
809
} ,
796
810
bodyStyle : function ( ) {
797
- if ( $body . attr ( 'style' ) === '' ) {
811
+ if ( $context . attr ( 'style' ) === '' ) {
798
812
module . verbose ( 'Removing style attribute' ) ;
799
- $body . removeAttr ( 'style' ) ;
813
+ $context . removeAttr ( 'style' ) ;
800
814
}
801
815
} ,
802
816
screenHeight : function ( ) {
803
817
module . debug ( 'Removing page height' ) ;
804
- $body
818
+ $context
805
819
. css ( 'height' , '' )
806
820
;
821
+ module . remove . bodyStyle ( )
807
822
} ,
808
823
keyboardShortcuts : function ( ) {
809
824
module . verbose ( 'Removing keyboard shortcuts' ) ;
@@ -812,7 +827,9 @@ $.modal = $.fn.modal = function(parameters) {
812
827
;
813
828
} ,
814
829
scrolling : function ( ) {
815
- $dimmable . removeClass ( className . scrolling ) ;
830
+ if ( ! keepScrollingClass ) {
831
+ $dimmable . removeClass ( className . scrolling ) ;
832
+ }
816
833
$module . removeClass ( className . scrolling ) ;
817
834
}
818
835
} ,
@@ -826,12 +843,12 @@ $.modal = $.fn.modal = function(parameters) {
826
843
;
827
844
if ( module . cache . pageHeight === undefined || modalHeight !== 0 ) {
828
845
$ . extend ( module . cache , {
829
- pageHeight : $ ( document ) . outerHeight ( ) ,
846
+ pageHeight : $document . outerHeight ( ) ,
830
847
width : modalWidth ,
831
848
height : modalHeight + settings . offset ,
832
849
scrollHeight : scrollHeight + settings . offset ,
833
- contextHeight : ( settings . context == 'body' )
834
- ? $ ( window ) . height ( )
850
+ contextHeight : isBody
851
+ ? $window . height ( )
835
852
: $dimmable . height ( ) ,
836
853
} ) ;
837
854
module . cache . topOffset = - ( module . cache . height / 2 ) ;
@@ -905,6 +922,9 @@ $.modal = $.fn.modal = function(parameters) {
905
922
has : {
906
923
configActions : function ( ) {
907
924
return Array . isArray ( settings . actions ) && settings . actions . length > 0 ;
925
+ } ,
926
+ scrollbar : function ( ) {
927
+ return isBody || $context . css ( 'overflow-y' ) !== 'hidden' ;
908
928
}
909
929
} ,
910
930
is : {
@@ -936,7 +956,7 @@ $.modal = $.fn.modal = function(parameters) {
936
956
} ,
937
957
rtl : function ( ) {
938
958
if ( module . cache . isRTL === undefined ) {
939
- module . cache . isRTL = $body . attr ( 'dir' ) === 'rtl' || $body . css ( 'direction' ) === 'rtl' ;
959
+ module . cache . isRTL = $module . attr ( 'dir' ) === 'rtl' || $module . css ( 'direction' ) === 'rtl' || $ body. attr ( 'dir' ) === 'rtl' || $body . css ( 'direction' ) === 'rtl' || $context . attr ( 'dir' ) === 'rtl' || $context . css ( 'direction' ) === 'rtl' ;
940
960
}
941
961
return module . cache . isRTL ;
942
962
} ,
@@ -978,9 +998,9 @@ $.modal = $.fn.modal = function(parameters) {
978
998
bodyMargin : function ( ) {
979
999
var position = module . can . leftBodyScrollbar ( ) ? 'left' :'right' ;
980
1000
if ( settings . detachable || module . can . fit ( ) ) {
981
- $body . css ( 'margin-' + position , tempBodyMargin + 'px' ) ;
1001
+ $context . css ( ( isBody ? 'margin-' : 'padding-' ) + position , tempBodyMargin + 'px' ) ;
982
1002
}
983
- $body . find ( selector . bodyFixed . replace ( 'right' , position ) ) . each ( function ( ) {
1003
+ $context . find ( selector . bodyFixed . replace ( 'right' , position ) ) . each ( function ( ) {
984
1004
var el = $ ( this ) ,
985
1005
attribute = el . css ( 'position' ) === 'fixed' ? 'padding-' + position : position
986
1006
;
@@ -1046,10 +1066,10 @@ $.modal = $.fn.modal = function(parameters) {
1046
1066
$module
1047
1067
. css ( {
1048
1068
top : ( ! $module . hasClass ( 'aligned' ) && canFit )
1049
- ? $ ( document ) . scrollTop ( ) + ( module . cache . contextHeight - module . cache . height ) / 2
1069
+ ? $document . scrollTop ( ) + ( module . cache . contextHeight - module . cache . height ) / 2
1050
1070
: ! canFit || $module . hasClass ( 'top' )
1051
- ? $ ( document ) . scrollTop ( ) + settings . padding
1052
- : $ ( document ) . scrollTop ( ) + ( module . cache . contextHeight - module . cache . height - settings . padding ) ,
1071
+ ? $document . scrollTop ( ) + settings . padding
1072
+ : $document . scrollTop ( ) + ( module . cache . contextHeight - module . cache . height - settings . padding ) ,
1053
1073
marginLeft : - ( module . cache . width / 2 )
1054
1074
} )
1055
1075
;
@@ -1067,11 +1087,11 @@ $.modal = $.fn.modal = function(parameters) {
1067
1087
} ,
1068
1088
screenHeight : function ( ) {
1069
1089
if ( module . can . fit ( ) ) {
1070
- $body . css ( 'height' , '' ) ;
1090
+ $context . css ( 'height' , '' ) ;
1071
1091
}
1072
1092
else if ( ! $module . hasClass ( 'bottom' ) ) {
1073
1093
module . debug ( 'Modal is taller than page content, resizing page height' ) ;
1074
- $body
1094
+ $context
1075
1095
. css ( 'height' , module . cache . height + ( settings . padding * 2 ) )
1076
1096
;
1077
1097
}
0 commit comments