-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (34 loc) · 1.21 KB
/
index.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
// Get dependencies
var position = require('position');
var style = require('computed-style');
module.exports = function (element) {
if (element) highlight(element);
else hide_highlighter();
}
function hide_highlighter() {
var highlighter = fetch_highlighter();
highlighter.classList.add("rm-highlight-hidden");
}
function fetch_highlighter() {
var highlighter;
if (!(highlighter = document.querySelector(".rm-highlight"))) {
highlighter = document.createElement("div");
highlighter.classList.add("rm-highlight");
highlighter.classList.add("rm-highlight-hidden");
}
return highlighter;
}
function highlight(element) {
var highlighter = fetch_highlighter();;
document.body.insertBefore(highlighter, document.body.childNodes[0]);
var pos = position(element);
var s = style(highlighter);
var off_x = parseInt(s.getPropertyValue('border-left-width'));
var off_y = parseInt(s.getPropertyValue('border-top-width'));
highlighter.classList.remove("rm-highlight-hidden");
highlighter.style.top = pos.top - off_y + "px";
highlighter.style.top = pos.top - off_y + "px";
highlighter.style.height = pos.height + "px";
highlighter.style.left = pos.left - off_x + "px";
highlighter.style.width = pos.width + "px";
}