-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPopupManager.js
54 lines (47 loc) · 1.82 KB
/
PopupManager.js
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
function PopupManager(options) {
var settings = {
maskClass: 'popup-mask',
popupClass: 'popup',
fadeInTime: 300,
reposition: true,
beforeShow: function () { },
afterClose: function () { }
};
if (options) {
$.extend(settings, options);
}
var mask = $('.' + settings.maskClass);
var popup = $('.' + settings.popupClass);
var setPosition = function () {
var scrollWidth = document.documentElement.scrollWidth || document.body.scrollWidth;
var scrollHeight = document.documentElement.scrollHeight || document.body.scrollHeight;
var clientWidth = document.documentElement.clientWidth || document.body.clientWidth;
var clientHeight = document.documentElement.clientHeight || document.body.clientHeight;
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop
var realWidth = scrollWidth > clientWidth ? scrollWidth : clientWidth;
var realHeight = scrollHeight > clientHeight ? scrollHeight : clientHeight;
var ww = $(window).width();
var wh = $(window).height();
var popupWidth = popup.width();
var popupHeight = popup.height();
mask.css({ 'top': 0, 'left': 0 }).width(realWidth).height(realHeight);
popup.css({ 'left': (ww - popupWidth) / 2, 'top': scrollTop + (wh - popupHeight) / 2 });
};
PopupManager.prototype.show = function () {
settings.beforeShow();
setPosition();
mask.fadeIn(settings.fadeInTime, function () {
popup.show();
});
};
PopupManager.prototype.close = function () {
popup.hide();
mask.hide();
settings.afterClose();
};
$(window).bind('resize', function () {
if (settings.reposition) {
setPosition();
}
});
}