aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/util.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2017-02-07 21:46:37 -0800
committerAlex Yatskov <alex@foosoft.net>2017-02-07 21:46:37 -0800
commite73d2d96c9cadce1364ae48a0dc68e24f2019c72 (patch)
treef1984328b561f7fc9a960b45e8b29a57b9835083 /ext/fg/js/util.js
parent4e3792aba319b52f957c70347e859f677972e4e2 (diff)
add support for looking up definitions for textareas and textboxes1.0.10
Diffstat (limited to 'ext/fg/js/util.js')
-rw-r--r--ext/fg/js/util.js28
1 files changed, 26 insertions, 2 deletions
diff --git a/ext/fg/js/util.js b/ext/fg/js/util.js
index ba872467..a7533846 100644
--- a/ext/fg/js/util.js
+++ b/ext/fg/js/util.js
@@ -70,12 +70,36 @@ function addDefinition(definition, mode) {
return invokeBgApi('addDefinition', {definition, mode});
}
+function createImposter(element) {
+ const imposter = document.createElement('div');
+ const elementRect = element.getBoundingClientRect();
+
+ imposter.className = 'yomichan-imposter';
+ imposter.innerText = element.value;
+ imposter.style.cssText = window.getComputedStyle(element).cssText;
+ imposter.style.position = 'absolute';
+ imposter.style.top = elementRect.top + 'px';
+ imposter.style.left = elementRect.left + 'px';
+ imposter.style.zIndex = 2147483646;
+ document.body.appendChild(imposter);
+
+ imposter.scrollTop = element.scrollTop;
+ imposter.scrollLeft = element.scrollLeft;
+}
+
+function destroyImposters() {
+ for (const element of document.getElementsByClassName('yomichan-imposter')) {
+ element.parentNode.removeChild(element);
+ }
+}
+
function textSourceFromPoint(point) {
const element = document.elementFromPoint(point.x, point.y);
if (element !== null) {
- const names = ['IMG', 'INPUT', 'BUTTON', 'TEXTAREA'];
- if (names.includes(element.nodeName)) {
+ if (element.nodeName === 'IMG' || element.nodeName === 'BUTTON') {
return new TextSourceElement(element);
+ } else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
+ createImposter(element);
}
}