-
Notifications
You must be signed in to change notification settings - Fork 5
/
popWindow.js
52 lines (51 loc) · 1.74 KB
/
popWindow.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
var template= _.template(require('./popWindow.html'));
require('./popWindow.css');
module.exports=function (options) {
var defaultOptions = {
title: '',
content: '',
yes: '确认',
no: '',
uniqID: $.uniqID(),
type: 1,
closeBtn: false,
tapMask: false,
callback: $.noop()
},
opt = {},
win;
opt = $.extend(defaultOptions, options);
if (opt.type == 1) opt.no = opt.no || '取消';
win = $(template(opt));
$('body').append(win).on('tap.popWindow' + opt.uniqID, '.yes_btn,.no_btn,.pop_window_wrap,.close_btn', function (e) {
var pos = false,
obj = $(e.target),
obj2 = $(e.currentTarget);
if (obj.hasClass('pop_window_wrap') && opt.tapMask) {
win.remove();
$('body').off('tap.popWindow' + opt.uniqID);
return false;
}
if (obj2.hasClass('yes_btn') || obj2.hasClass('no_btn') || obj2.hasClass('close_btn')) {
if (obj2.hasClass('yes_btn')) {
pos = true
}
if ($.type(opt.callback) == 'function') {
if (opt.callback(pos) !== false) {
win.remove();
$('body').off('tap.popWindow' + opt.uniqID);
}
} else {
win.remove();
$('body').off('tap.popWindow' + opt.uniqID);
}
}
})
var obj=win.find('.pop_window');
obj.css('margin-top',-obj.height()/2);
$(window).on('popstate.popWindow'+ opt.uniqID,function(){
win.remove();
$('body').off('tap.popWindow' + opt.uniqID);
$(window).off('popstate.popWindow'+ opt.uniqID);
})
};