|
@@ -2,42 +2,9 @@ import Vue from 'vue';
|
|
|
import merge from 'element-ui/src/utils/merge';
|
|
|
import PopupManager from 'element-ui/src/utils/popup/popup-manager';
|
|
|
import getScrollBarWidth from '../scrollbar-width';
|
|
|
-import { getStyle } from '../dom';
|
|
|
+import { getStyle, addClass, removeClass, hasClass } from '../dom';
|
|
|
|
|
|
let idSeed = 1;
|
|
|
-const transitions = [];
|
|
|
-
|
|
|
-const hookTransition = (transition) => {
|
|
|
- if (transitions.indexOf(transition) !== -1) return;
|
|
|
-
|
|
|
- const getVueInstance = (element) => {
|
|
|
- let instance = element.__vue__;
|
|
|
- if (!instance) {
|
|
|
- const textNode = element.previousSibling;
|
|
|
- if (textNode.__vue__) {
|
|
|
- instance = textNode.__vue__;
|
|
|
- }
|
|
|
- }
|
|
|
- return instance;
|
|
|
- };
|
|
|
-
|
|
|
- Vue.transition(transition, {
|
|
|
- afterEnter(el) {
|
|
|
- const instance = getVueInstance(el);
|
|
|
-
|
|
|
- if (instance) {
|
|
|
- instance.doAfterOpen && instance.doAfterOpen();
|
|
|
- }
|
|
|
- },
|
|
|
- afterLeave(el) {
|
|
|
- const instance = getVueInstance(el);
|
|
|
-
|
|
|
- if (instance) {
|
|
|
- instance.doAfterClose && instance.doAfterClose();
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
-};
|
|
|
|
|
|
let scrollBarWidth;
|
|
|
|
|
@@ -55,10 +22,6 @@ export default {
|
|
|
type: Boolean,
|
|
|
default: false
|
|
|
},
|
|
|
- transition: {
|
|
|
- type: String,
|
|
|
- default: ''
|
|
|
- },
|
|
|
openDelay: {},
|
|
|
closeDelay: {},
|
|
|
zIndex: {},
|
|
@@ -89,12 +52,6 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- created() {
|
|
|
- if (this.transition) {
|
|
|
- hookTransition(this.transition);
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
beforeMount() {
|
|
|
this._popupId = 'popup-' + idSeed++;
|
|
|
PopupManager.register(this._popupId, this);
|
|
@@ -103,19 +60,16 @@ export default {
|
|
|
beforeDestroy() {
|
|
|
PopupManager.deregister(this._popupId);
|
|
|
PopupManager.closeModal(this._popupId);
|
|
|
- if (this.modal && this.bodyOverflow !== null && this.bodyOverflow !== 'hidden') {
|
|
|
- document.body.style.overflow = this.bodyOverflow;
|
|
|
- document.body.style.paddingRight = this.bodyPaddingRight;
|
|
|
- }
|
|
|
- this.bodyOverflow = null;
|
|
|
- this.bodyPaddingRight = null;
|
|
|
+
|
|
|
+ this.restoreBodyStyle();
|
|
|
},
|
|
|
|
|
|
data() {
|
|
|
return {
|
|
|
opened: false,
|
|
|
- bodyOverflow: null,
|
|
|
bodyPaddingRight: null,
|
|
|
+ computedBodyPaddingRight: 0,
|
|
|
+ withoutHiddenClass: false,
|
|
|
rendered: false
|
|
|
};
|
|
|
},
|
|
@@ -186,17 +140,18 @@ export default {
|
|
|
}
|
|
|
PopupManager.openModal(this._popupId, PopupManager.nextZIndex(), this.modalAppendToBody ? undefined : dom, props.modalClass, props.modalFade);
|
|
|
if (props.lockScroll) {
|
|
|
- if (!this.bodyOverflow) {
|
|
|
+ this.withoutHiddenClass = !hasClass(document.body, 'el-popup-parent--hidden');
|
|
|
+ if (this.withoutHiddenClass) {
|
|
|
this.bodyPaddingRight = document.body.style.paddingRight;
|
|
|
- this.bodyOverflow = document.body.style.overflow;
|
|
|
+ this.computedBodyPaddingRight = parseInt(getStyle(document.body, 'paddingRight'), 10);
|
|
|
}
|
|
|
scrollBarWidth = getScrollBarWidth();
|
|
|
let bodyHasOverflow = document.documentElement.clientHeight < document.body.scrollHeight;
|
|
|
let bodyOverflowY = getStyle(document.body, 'overflowY');
|
|
|
- if (scrollBarWidth > 0 && (bodyHasOverflow || bodyOverflowY === 'scroll')) {
|
|
|
- document.body.style.paddingRight = scrollBarWidth + 'px';
|
|
|
+ if (scrollBarWidth > 0 && (bodyHasOverflow || bodyOverflowY === 'scroll') && this.withoutHiddenClass) {
|
|
|
+ document.body.style.paddingRight = this.computedBodyPaddingRight + scrollBarWidth + 'px';
|
|
|
}
|
|
|
- document.body.style.overflow = 'hidden';
|
|
|
+ addClass(document.body, 'el-popup-parent--hidden');
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -209,9 +164,7 @@ export default {
|
|
|
|
|
|
this.onOpen && this.onOpen();
|
|
|
|
|
|
- if (!this.transition) {
|
|
|
- this.doAfterOpen();
|
|
|
- }
|
|
|
+ this.doAfterOpen();
|
|
|
},
|
|
|
|
|
|
doAfterOpen() {
|
|
@@ -245,26 +198,24 @@ export default {
|
|
|
this.onClose && this.onClose();
|
|
|
|
|
|
if (this.lockScroll) {
|
|
|
- setTimeout(() => {
|
|
|
- if (this.modal && this.bodyOverflow !== 'hidden') {
|
|
|
- document.body.style.overflow = this.bodyOverflow;
|
|
|
- document.body.style.paddingRight = this.bodyPaddingRight;
|
|
|
- }
|
|
|
- this.bodyOverflow = null;
|
|
|
- this.bodyPaddingRight = null;
|
|
|
- }, 200);
|
|
|
+ setTimeout(this.restoreBodyStyle, 200);
|
|
|
}
|
|
|
|
|
|
this.opened = false;
|
|
|
|
|
|
- if (!this.transition) {
|
|
|
- this.doAfterClose();
|
|
|
- }
|
|
|
+ this.doAfterClose();
|
|
|
},
|
|
|
|
|
|
doAfterClose() {
|
|
|
PopupManager.closeModal(this._popupId);
|
|
|
this._closing = false;
|
|
|
+ },
|
|
|
+
|
|
|
+ restoreBodyStyle() {
|
|
|
+ if (this.modal && this.withoutHiddenClass) {
|
|
|
+ document.body.style.paddingRight = this.bodyPaddingRight;
|
|
|
+ removeClass(document.body, 'el-popup-parent--hidden');
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
};
|