A fork of https://github.com/ueokande/vim-vixen
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
807 B
37 lines
807 B
7 years ago
|
import './hint.css';
|
||
|
|
||
|
export default class Hint {
|
||
|
constructor(target, tag) {
|
||
7 years ago
|
if (!(document.body instanceof HTMLElement)) {
|
||
|
throw new TypeError('target is not an HTMLElement');
|
||
|
}
|
||
|
|
||
7 years ago
|
this.target = target;
|
||
|
|
||
7 years ago
|
let doc = target.ownerDocument;
|
||
7 years ago
|
let { top, left } = target.getBoundingClientRect();
|
||
7 years ago
|
let { scrollX, scrollY } = window;
|
||
7 years ago
|
|
||
|
this.element = doc.createElement('span');
|
||
|
this.element.className = 'vimvixen-hint';
|
||
|
this.element.textContent = tag;
|
||
7 years ago
|
this.element.style.left = left + scrollX + 'px';
|
||
|
this.element.style.top = top + scrollY + 'px';
|
||
7 years ago
|
|
||
|
this.show();
|
||
|
doc.body.append(this.element);
|
||
|
}
|
||
|
|
||
|
show() {
|
||
|
this.element.style.display = 'inline';
|
||
|
}
|
||
|
|
||
|
hide() {
|
||
|
this.element.style.display = 'none';
|
||
|
}
|
||
|
|
||
|
remove() {
|
||
|
this.element.remove();
|
||
|
}
|
||
|
}
|