@@ -355,11 +355,9 @@ export default {
355
355
} ,
356
356
watch : {
357
357
visible ( newVal , oldVal ) {
358
- if ( newVal === oldVal ) {
359
- /* istanbul ignore next */
360
- return
358
+ if ( newVal !== oldVal ) {
359
+ this [ newVal ? 'show' : 'hide' ] ( )
361
360
}
362
- this [ newVal ? 'show' : 'hide' ] ( )
363
361
}
364
362
} ,
365
363
created ( ) {
@@ -381,7 +379,7 @@ export default {
381
379
this . show ( )
382
380
}
383
381
} ,
384
- beforeDestroy ( ) /* istanbul ignore next */ {
382
+ beforeDestroy ( ) {
385
383
// Ensure everything is back to normal
386
384
if ( this . _observer ) {
387
385
this . _observer . disconnect ( )
@@ -409,11 +407,14 @@ export default {
409
407
show ( ) {
410
408
if ( this . is_visible || this . is_opening ) {
411
409
// if already open, on in the process of opening, do nothing
410
+ /* istanbul ignore next */
412
411
return
413
412
}
414
413
if ( this . is_closing ) {
415
414
// if we are in the process of closing, wait until hidden before re-opening
415
+ /* istanbul ignore next: very difficult to test */
416
416
this . $once ( 'hidden' , this . show )
417
+ /* istanbul ignore next */
417
418
return
418
419
}
419
420
this . is_opening = true
@@ -433,11 +434,7 @@ export default {
433
434
if ( ! this . noStacking ) {
434
435
// Find the z-index to use
435
436
this . zIndex = getModalNextZIndex ( )
436
- // Show the modal
437
- this . doShow ( )
438
- return
439
- }
440
- if ( hasClass ( document . body , 'modal-open' ) ) {
437
+ } else if ( hasClass ( document . body , 'modal-open' ) ) {
441
438
// If another modal is already open, wait for it to close
442
439
this . $root . $once ( 'bv::modal::hidden' , this . doShow )
443
440
return
@@ -447,6 +444,7 @@ export default {
447
444
} ,
448
445
hide ( trigger ) {
449
446
if ( ! this . is_visible || this . is_closing ) {
447
+ /* istanbul ignore next */
450
448
return
451
449
}
452
450
this . is_closing = true
@@ -618,23 +616,15 @@ export default {
618
616
} ,
619
617
// Turn on/off focusin listener
620
618
setEnforceFocus ( on ) {
621
- const options = { passive : true , capture : false }
622
- if ( on ) {
623
- eventOn ( document , 'focusin' , this . focusHandler , options )
624
- } else {
625
- eventOff ( document , 'focusin' , this . focusHandler , options )
626
- }
619
+ const method = on ? eventOn : eventOff
620
+ method ( document , 'focusin' , this . focusHandler , { passive : true , capture : false } )
627
621
} ,
628
622
// Resize Listener
629
- setResizeEvent ( on ) /* istanbul ignore next: can't easily test in JSDOM */ {
630
- ; [ 'resize' , 'orientationchange' ] . forEach ( evtName => {
631
- const options = { passive : true , capture : false }
632
- if ( on ) {
633
- eventOn ( window , evtName , this . adjustDialog , options )
634
- } else {
635
- eventOff ( window , evtName , this . adjustDialog , options )
636
- }
637
- } )
623
+ setResizeEvent ( on ) {
624
+ const options = { passive : true , capture : false }
625
+ const method = on ? eventOn : eventOff
626
+ method ( window , 'resize' , this . adjustDialog , options )
627
+ method ( window , 'orientationchange' , this . adjustDialog , options )
638
628
} ,
639
629
// Root Listener handlers
640
630
showHandler ( id , triggerEl ) {
@@ -673,6 +663,7 @@ export default {
673
663
focusFirst ( ) {
674
664
// Don't try and focus if we are SSR
675
665
if ( typeof document === 'undefined' ) {
666
+ /* istanbul ignore next */
676
667
return
677
668
}
678
669
const modal = this . $refs . modal
@@ -713,14 +704,12 @@ export default {
713
704
document . body . removeChild ( scrollDiv )
714
705
} ,
715
706
setModalOpenClass ( open ) {
716
- if ( open ) {
717
- addClass ( document . body , 'modal-open' )
718
- } else {
719
- removeClass ( document . body , 'modal-open' )
720
- }
707
+ const method = open ? addClass : removeClass
708
+ method ( document . body , 'modal-open' )
721
709
} ,
722
710
adjustDialog ( ) {
723
711
if ( ! this . is_visible ) {
712
+ /* istanbul ignore next */
724
713
return
725
714
}
726
715
const modal = this . $refs . modal
@@ -743,20 +732,23 @@ export default {
743
732
modal . style . paddingRight = ''
744
733
}
745
734
} ,
746
- checkScrollbar ( ) /* istanbul ignore next: getBCR can't be tested in JSDOM */ {
735
+ checkScrollbar ( ) {
747
736
const { left, right, height } = getBCR ( document . body )
748
737
// Extra check for body.height needed for stacked modals
749
738
this . isBodyOverflowing = left + right < window . innerWidth || height > window . innerHeight
750
739
} ,
751
740
setScrollbar ( ) {
741
+ const body = document . body
742
+ // Storage place to cache changes to margins and padding
743
+ // Note: THis assumes the following element types are not added to the
744
+ // document after hte modal has opened.
745
+ body . _paddingChangedForModal = body . _paddingChangedForModal || [ ]
746
+ body . _marginChangedForModal = body . _marginChangedForModal || [ ]
752
747
/* istanbul ignore if: get Computed Style can't be tested in JSDOM */
753
748
if ( this . isBodyOverflowing ) {
754
749
// Note: DOMNode.style.paddingRight returns the actual value or '' if not set
755
750
// while $(DOMNode).css('padding-right') returns the calculated value or 0 if not set
756
- const body = document . body
757
751
const scrollbarWidth = this . scrollbarWidth
758
- body . _paddingChangedForModal = [ ]
759
- body . _marginChangedForModal = [ ]
760
752
// Adjust fixed content padding
761
753
selectAll ( Selector . FIXED_CONTENT ) . forEach ( el => {
762
754
const actualPadding = el . style . paddingRight
0 commit comments