jquery.toptip.js
1.27 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
(function($) {
var template = '<div class="toptip"> \
<i class="mark">!</i> \
<div class="content"></div> \
<div class="close">×</div> \
</div>';
var defaultOpts = {
selector: document.body,
mark: true,
close: true
};
function hide () {
this.dom.hide();
}
function show () {
this.dom.css('display','flex');
}
function config (options) {
this.dom.find('.content').text(options.text);
if (options.mark) {
this.dom.find('.mark').show();
} else {
this.dom.find('.mark').hide();
}
if (options.close) {
this.dom.find('.close').show();
} else {
this.dom.find('.close').hide();
}
}
var toptip = function(options) {
var $dom = $(template).addClass('toptip-' + options.type);
var opts = $.extend({}, defaultOpts, options);
var obj = {
dom: $dom,
hide: hide,
show: show,
reset: config
};
obj.reset(opts);
$(opts.selector).prepend($dom);
return obj;
};
$.extend({
toptip: toptip
});
})(jQuery);