From b3984ccd54340195fc352033f61d33e4b5f492ea Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 9 Jul 2017 15:23:11 -0700 Subject: cleanup --- ext/fg/js/util.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'ext/fg') diff --git a/ext/fg/js/util.js b/ext/fg/js/util.js index e1b0e080..2acd81c4 100644 --- a/ext/fg/js/util.js +++ b/ext/fg/js/util.js @@ -117,7 +117,7 @@ function docImposterDestroy() { function docRangeFromPoint(point) { const element = document.elementFromPoint(point.x, point.y); - if (element !== null) { + if (element) { if (element.nodeName === 'IMG' || element.nodeName === 'BUTTON') { return new TextSourceElement(element); } else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') { @@ -128,23 +128,19 @@ function docRangeFromPoint(point) { if (!document.caretRangeFromPoint) { document.caretRangeFromPoint = (x, y) => { const position = document.caretPositionFromPoint(x,y); - if (position === null) { - return null; + if (position) { + const range = document.createRange(); + range.setStart(position.offsetNode, position.offset); + range.setEnd(position.offsetNode, position.offset); + return range; } - - const range = document.createRange(); - range.setStart(position.offsetNode, position.offset); - range.setEnd(position.offsetNode, position.offset); - return range; }; } const range = document.caretRangeFromPoint(point.x, point.y); - if (range !== null) { + if (range) { return new TextSourceRange(range); } - - return null; } function docSentenceExtract(source, extent) { -- cgit v1.2.3