rich-tip.js
2.12 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
/**
* Created by yoho on 2016/11/22.
*/
var $ = require('yoho-jquery');
var $tip = $('#yoho-order-bg'),
$tipMsg = $tip.find('.order-tip-msg'),
$tipBtns = $tip.find('.order-tip-btn-group');
var touchCallback,
params;
function setCallback(t, p) {
touchCallback = t;
params = p;
}
/**
* 跳转还是消失控制
*/
(function() {
$tip.on('touchend', function(event) {
if (event.target.tagName === 'SPAN') {
if (touchCallback) {
touchCallback(params);
}
touchCallback = null;
params = null;
setTimeout(function() {
$tip.hide();
}, 200);
} else if (event.target.tagName === 'A') {
setTimeout(function() {
$tip.hide();
}, 200);
} else {
$tip.hide();
}
});
}());
/**
* 显示提示
*/
function show(con, btn) {
var content = '',
buttons = '';
if (con && $.isArray(con)) {
$.each(con, function(key, value) {
content += '<p>' + value + '</p>';
});
}
if (btn && $.isArray(btn) && btn.length === 1) {
if (!btn[0].href) {
buttons += '<a class="order-tip-btn1 ' + btn[0].class +
'"><span>' + btn[0].text +
'</span></a>';
} else {
buttons += '<a href="' + btn[0].href +
'" class="order-tip-btn1 ' + btn[0].class +
'">' + btn[0].text +
'</a>';
}
}
if (btn && $.isArray(btn) && btn.length > 1) {
$.each(btn, function(key, value) {
if (!value.href) {
buttons += '<a class="' + value.class +
'"><span>' + value.text +
'</span></a>';
} else {
buttons += '<a href="' + value.href +
'" class="' + value.class +
'">' + value.text +
'</a>';
}
});
}
$tipMsg.html(content);
$tipBtns.html(buttons);
$tip.show();
}
exports.setCallback = setCallback;
exports.show = show;