index.js
5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
'use strict';
exports.__esModule = true;
exports.PopupManager = undefined;
var _vue = require('vue');
var _vue2 = _interopRequireDefault(_vue);
var _merge = require('module/element-ui/lib/utils/merge');
var _merge2 = _interopRequireDefault(_merge);
var _popupManager = require('module/element-ui/lib/utils/popup/popup-manager');
var _popupManager2 = _interopRequireDefault(_popupManager);
var _scrollbarWidth = require('../scrollbar-width');
var _scrollbarWidth2 = _interopRequireDefault(_scrollbarWidth);
var _dom = require('../dom');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var idSeed = 1;
var scrollBarWidth = void 0;
exports.default = {
props: {
visible: {
type: Boolean,
default: false
},
openDelay: {},
closeDelay: {},
zIndex: {},
modal: {
type: Boolean,
default: false
},
modalFade: {
type: Boolean,
default: true
},
modalClass: {},
modalAppendToBody: {
type: Boolean,
default: false
},
lockScroll: {
type: Boolean,
default: true
},
closeOnPressEscape: {
type: Boolean,
default: false
},
closeOnClickModal: {
type: Boolean,
default: false
}
},
beforeMount: function beforeMount() {
this._popupId = 'popup-' + idSeed++;
_popupManager2.default.register(this._popupId, this);
},
beforeDestroy: function beforeDestroy() {
_popupManager2.default.deregister(this._popupId);
_popupManager2.default.closeModal(this._popupId);
this.restoreBodyStyle();
},
data: function data() {
return {
opened: false,
bodyPaddingRight: null,
computedBodyPaddingRight: 0,
withoutHiddenClass: true,
rendered: false
};
},
watch: {
visible: function visible(val) {
var _this = this;
if (val) {
if (this._opening) return;
if (!this.rendered) {
this.rendered = true;
_vue2.default.nextTick(function () {
_this.open();
});
} else {
this.open();
}
} else {
this.close();
}
}
},
methods: {
open: function open(options) {
var _this2 = this;
if (!this.rendered) {
this.rendered = true;
}
var props = (0, _merge2.default)({}, this.$props || this, options);
if (this._closeTimer) {
clearTimeout(this._closeTimer);
this._closeTimer = null;
}
clearTimeout(this._openTimer);
var openDelay = Number(props.openDelay);
if (openDelay > 0) {
this._openTimer = setTimeout(function () {
_this2._openTimer = null;
_this2.doOpen(props);
}, openDelay);
} else {
this.doOpen(props);
}
},
doOpen: function doOpen(props) {
if (this.$isServer) return;
if (this.willOpen && !this.willOpen()) return;
if (this.opened) return;
this._opening = true;
var dom = this.$el;
var modal = props.modal;
var zIndex = props.zIndex;
if (zIndex) {
_popupManager2.default.zIndex = zIndex;
}
if (modal) {
if (this._closing) {
_popupManager2.default.closeModal(this._popupId);
this._closing = false;
}
_popupManager2.default.openModal(this._popupId, _popupManager2.default.nextZIndex(), this.modalAppendToBody ? undefined : dom, props.modalClass, props.modalFade);
if (props.lockScroll) {
this.withoutHiddenClass = !(0, _dom.hasClass)(document.body, 'el-popup-parent--hidden');
if (this.withoutHiddenClass) {
this.bodyPaddingRight = document.body.style.paddingRight;
this.computedBodyPaddingRight = parseInt((0, _dom.getStyle)(document.body, 'paddingRight'), 10);
}
scrollBarWidth = (0, _scrollbarWidth2.default)();
var bodyHasOverflow = document.documentElement.clientHeight < document.body.scrollHeight;
var bodyOverflowY = (0, _dom.getStyle)(document.body, 'overflowY');
if (scrollBarWidth > 0 && (bodyHasOverflow || bodyOverflowY === 'scroll') && this.withoutHiddenClass) {
document.body.style.paddingRight = this.computedBodyPaddingRight + scrollBarWidth + 'px';
}
(0, _dom.addClass)(document.body, 'el-popup-parent--hidden');
}
}
if (getComputedStyle(dom).position === 'static') {
dom.style.position = 'absolute';
}
dom.style.zIndex = _popupManager2.default.nextZIndex();
this.opened = true;
this.onOpen && this.onOpen();
this.doAfterOpen();
},
doAfterOpen: function doAfterOpen() {
this._opening = false;
},
close: function close() {
var _this3 = this;
if (this.willClose && !this.willClose()) return;
if (this._openTimer !== null) {
clearTimeout(this._openTimer);
this._openTimer = null;
}
clearTimeout(this._closeTimer);
var closeDelay = Number(this.closeDelay);
if (closeDelay > 0) {
this._closeTimer = setTimeout(function () {
_this3._closeTimer = null;
_this3.doClose();
}, closeDelay);
} else {
this.doClose();
}
},
doClose: function doClose() {
this._closing = true;
this.onClose && this.onClose();
if (this.lockScroll) {
setTimeout(this.restoreBodyStyle, 200);
}
this.opened = false;
this.doAfterClose();
},
doAfterClose: function doAfterClose() {
_popupManager2.default.closeModal(this._popupId);
this._closing = false;
},
restoreBodyStyle: function restoreBodyStyle() {
if (this.modal && this.withoutHiddenClass) {
document.body.style.paddingRight = this.bodyPaddingRight;
(0, _dom.removeClass)(document.body, 'el-popup-parent--hidden');
}
this.withoutHiddenClass = true;
}
}
};
exports.PopupManager = _popupManager2.default;