-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtooltip.js
57 lines (54 loc) · 1.46 KB
/
tooltip.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
55
56
57
// ==Headers==
// @Name: tooltip
// @Description: tooltip
// @Version: 1.0.9
// @Author: dodying
// @Created: 2020-03-15 19:57:00
// @Modified: 2020-4-25 16:35:43
// @Namespace: https://github.com/dodying/Nodejs
// @SupportURL: https://github.com/dodying/Nodejs/issues
// @Require: null
// ==/Headers==
/* global Mousetrap, $ */
let lastTooltip = null;
const main = function tooltip(option = {}, content) {
Mousetrap.pause();
if (lastTooltip) lastTooltip.close();
if (typeof option === 'string') {
option = { title: option };
if (typeof content !== 'undefined') option.content = content;
}
if (option.theme === 'supervan' || option.autoClose === null || (option.autoClose && option.autoClose.split('|')[0] / 1000 > 1)) {
} else {
Mousetrap.unpause();
}
return new Promise((resolve, reject) => {
lastTooltip = $.confirm({
theme: 'banner',
boxWidth: '50%',
useBootstrap: false,
title: null,
autoClose: 'ok|0',
backgroundDismiss: 'ok',
buttons: {
ok: {
text: 'OK',
btnClass: 'btn-blue',
keys: ['enter'],
},
},
onClose() {
resolve();
lastTooltip = null;
Mousetrap.unpause();
},
onAction(btn) {
resolve(btn);
lastTooltip = null;
Mousetrap.unpause();
},
...option,
});
});
};
module.exports = main;