popover.js
5.05 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
define("mall/res/js/popover", ["mall/res/js/popover.html"],
function(o, t, e) {
"use strict";
function i(o) {
if (o = $.extend(!0, {},
h, o), this.opt = o, this.$dom = $(o.dom), this.$dom.data("popover")) {
var t = this.$dom.data("popover");
return s(o, t),
t.$pop.show(),
t;
}
// return o.buttons && o.buttons && o.buttons.each(function(o) {
// o.type = o.type || "default";
// }),
return o.buttons && o.buttons && $.each(o.buttons, function(i, o) {
o.type = o.type || "default";
}),
this.$pop=$(template.compile(p)(o)),
o.addCls && this.$pop.addClass(o.addCls),
$("body").append(this.$pop),
n(this, o),
s(o, this),
this.$pop.show(),
this.$dom.data("popover", this),
this.clickIn = !0,
this;
}
function n(o, t) {
function e() {
clearTimeout(n),
o.show();
}
function i() {
n = setTimeout(function() {
o.hide();
},
s);
}
if (t.buttons && t.buttons.length > 0 && o.$pop.find(".jsPopoverBt").each(function(e, i) {
t.buttons[e] && "function" == typeof t.buttons[e].click && $(i).click(function(i) {
t.buttons[e].click.call(o, i);
});
}), o.$pop.find(".jsPopoverClose").click(function() {
t.close === !0 ? o.hide() : "function" == typeof t.close && t.close.call(o);
}), t.hover && (o.$dom.hover(function() {
o.hoverTime && clearTimeout(o.hoverTime);
},
function() {
o.hoverTime = o.hide.delay(1, o);
}), o.$pop.hover(function() {
o.hoverTime && clearTimeout(o.hoverTime);
},
function() {
o.hoverTime && clearTimeout(o.hoverTime),
o.hoverTime = o.hide.delay(1, o);
})), t.isToggle) {
var n = null,
s = 300;
o.$dom.hover(e, i),
o.$pop.hover(e, i);
}
t.hideIfBlur && (o._onBlur = function(o) {
var t = o.data.context,
e = o.target,
i = t.$dom.get(0),
n = t.$pop.get(0);
t.clickIn ? t.clickIn = !1 : $.contains(i, e) || i === e || $.contains(n, e) || n === e || o.data.context.hide();
},
$(document).on("click", {
context: o
},
o._onBlur)),
o._onResize = function(o) {
o.data.context.resetPosition();
},
$(window).on("resize", {
context: o
},
o._onResize);
}
function s(o, t) {
var e = t.$dom.offset();
"left" == o.margin ? (console.log(e.top), console.log(t.$dom.height()), t.$pop.css({
top: e.top + t.$dom.height(),
left: e.left
}).addClass("pos_left")) : "right" == o.margin ? t.$pop.css({
top: e.top + t.$dom.height(),
left: e.left + t.$dom.width() - t.$pop.width()
}).addClass("pos_right") : t.$pop.css({
top: e.top + t.$dom.height(),
left: e.left + t.$dom.outerWidth() / 2 - t.$pop.width() / 2
}).addClass("pos_center");
}
var p = o("mall/res/js/popover.html"),
h = {
dom: "",
content: "",
place: "bottom",
margin: "center",
hideIfBlur: !1,
hover: !1,
addCls: "",
isToggle: !1,
onHide: !1,
onShow: !1,
onRemove: !1
};
i.prototype = {
remove: function() {
this.$pop.remove(),
this.$dom.removeData("popover"),
this._onBlur && $(document).off("click", this._onBlur),
$(window).off("resize", this._onResize),
"function" == typeof this.opt.onRemove && this.opt.onRemove.call(this);
},
hide: function() {
this.$pop.hide(),
"function" == typeof this.opt.onHide && this.opt.onHide.call(this);
},
show: function() {
this.$pop.show(),
"function" == typeof this.opt.onShow && this.opt.onShow.call(this);
},
resetPosition: function() {
return s(this.opt, this);
}
},
e.exports = i;
});