2017-09-19 14:26:46 +08:00
|
|
|
// used for Modal & $Spin
|
|
|
|
import { getScrollBarSize } from '../../utils/assist';
|
|
|
|
export default {
|
|
|
|
methods: {
|
|
|
|
checkScrollBar () {
|
|
|
|
let fullWindowWidth = window.innerWidth;
|
|
|
|
if (!fullWindowWidth) { // workaround for missing window.innerWidth in IE8
|
|
|
|
const documentElementRect = document.documentElement.getBoundingClientRect();
|
|
|
|
fullWindowWidth = documentElementRect.right - Math.abs(documentElementRect.left);
|
|
|
|
}
|
|
|
|
this.bodyIsOverflowing = document.body.clientWidth < fullWindowWidth;
|
|
|
|
if (this.bodyIsOverflowing) {
|
|
|
|
this.scrollBarWidth = getScrollBarSize();
|
|
|
|
}
|
|
|
|
},
|
2018-06-04 16:07:58 +08:00
|
|
|
checkMaskInVisible () {
|
|
|
|
let masks = document.getElementsByClassName('ivu-modal-mask') || [];
|
|
|
|
return Array.from(masks).every(m => m.style.display === 'none' || m.classList.contains('fade-leave-to'));
|
|
|
|
},
|
2017-09-19 14:26:46 +08:00
|
|
|
setScrollBar () {
|
|
|
|
if (this.bodyIsOverflowing && this.scrollBarWidth !== undefined) {
|
|
|
|
document.body.style.paddingRight = `${this.scrollBarWidth}px`;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
resetScrollBar () {
|
|
|
|
document.body.style.paddingRight = '';
|
|
|
|
},
|
|
|
|
addScrollEffect () {
|
|
|
|
this.checkScrollBar();
|
|
|
|
this.setScrollBar();
|
|
|
|
document.body.style.overflow = 'hidden';
|
|
|
|
},
|
|
|
|
removeScrollEffect() {
|
2018-06-04 16:07:58 +08:00
|
|
|
if (this.checkMaskInVisible()) {
|
|
|
|
document.body.style.overflow = '';
|
|
|
|
this.resetScrollBar();
|
|
|
|
}
|
2017-09-19 14:26:46 +08:00
|
|
|
}
|
|
|
|
}
|
2018-06-04 16:07:58 +08:00
|
|
|
};
|