forked from matthisk/es6console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
64 lines (47 loc) · 1.45 KB
/
Copy pathutils.js
File metadata and controls
64 lines (47 loc) · 1.45 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
import CodeMirror from 'codemirror';
export function rm(el) {
if(el.parentNode) el.parentNode.removeChild(el);
}
export function showTooltip(e, msg) {
var tt = document.createElement('div');
tt.className = 'compiler-error-tooltip';
tt.appendChild(document.createTextNode(msg));
document.body.appendChild(tt);
function position(e) {
if(!tt.parentNode) return CodeMirror.off(document, 'mousemove', position);
tt.style.top = Math.max (0, e.clientY - tt.offsetHeight - 5) + 'px';
tt.style.left = (e.clientX + 5) + 'px';
}
CodeMirror.on(document, 'mousemove', position);
position(e);
if(tt.style.opacity != null) tt.style.opacity = 1;
return tt;
}
export function hideTooltip(tt) {
if(!tt.parentNode) return;
if(tt.style.opacity == null) rm(tt);
tt.style.opacity = 0;
setTimeout(()=>rm(tt),600);
}
export function showTooltipFor( e, msg, marker ) {
var tooltip = showTooltip(e, msg);
function hide() {
CodeMirror.off(marker, 'mouseout', hide);
if(tooltip) {
hideTooltip(tooltip);
tooltip = null;
}
}
CodeMirror.on(marker, 'mouseout', hide);
}
export function makeMarker( msg ) {
msg = msg.split('\n')[0];
var marker = document.createElement('i');
marker.classList.add('compiler-error-marker',
'icon',
'remove');
CodeMirror.on(marker, 'mouseover', function(e) {
showTooltipFor(e, msg, marker);
});
return marker;
}