From 7a67af24f0a988dbf1d3acbb79abf030834c9bdf Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 12 May 2015 07:06:55 +0200 Subject: [PATCH] js: Fix some lint. --- .eslintrc | 4 +-- qutebrowser/javascript/position_caret.js | 46 ++++++++++++++++-------- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/.eslintrc b/.eslintrc index dcd5b3b8c..2eec935a7 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,7 +5,6 @@ env: rules: block-scoped-var: 2 - complexity: [2, 5] dot-location: 2 default-case: 2 guard-for-in: 2 @@ -42,6 +41,7 @@ rules: max-depth: [2, 5] max-len: [2, 79, 4] max-params: [2, 5] - max-statements: [2, 20] + max-statements: [2, 30] no-bitwise: 2 no-reserved-keys: 2 + global-strict: 0 diff --git a/qutebrowser/javascript/position_caret.js b/qutebrowser/javascript/position_caret.js index 9e14b5b3c..36bf0451f 100644 --- a/qutebrowser/javascript/position_caret.js +++ b/qutebrowser/javascript/position_caret.js @@ -1,40 +1,53 @@ /** -* Copyright 2014-2015 Florian Bruhin (The Compiler) -* +* Copyright 2015 Artur Shaik +* Copyright 2015 Florian Bruhin (The Compiler) +* * This file is part of qutebrowser. -* +* * qutebrowser is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. -* +* * qutebrowser is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. -* +* * You should have received a copy of the GNU General Public License * along with qutebrowser. If not, see . */ +/* eslint-disable max-len */ + /** - * Snippet to position caret at top of the page when caret mode enabled. - * Some code was borrowed from https://github.com/1995eaton/chromium-vim/blob/master/content_scripts/dom.js - * and https://github.com/1995eaton/chromium-vim/blob/master/content_scripts/visual.js + * Snippet to position caret at top of the page when caret mode is enabled. + * Some code was borrowed from: + * + * https://github.com/1995eaton/chromium-vim/blob/master/content_scripts/dom.js + * https://github.com/1995eaton/chromium-vim/blob/master/content_scripts/visual.js */ +/* eslint-enable max-len */ + +"use strict"; + function isElementInViewport(node) { var i; - var boundingRect = node.getClientRects()[0] || node.getBoundingClientRect(); + var boundingRect = (node.getClientRects()[0] || + node.getBoundingClientRect()); if (boundingRect.width <= 1 && boundingRect.height <= 1) { var rects = node.getClientRects(); for (i = 0; i < rects.length; i++) { - if (rects[i].width > rects[0].height && rects[i].height > rects[0].height) { + if (rects[i].width > rects[0].height && + rects[i].height > rects[0].height) { boundingRect = rects[i]; } } } - if (boundingRect === void 0) return null; + if (boundingRect === undefined) { + return null; + } if (boundingRect.top > innerHeight || boundingRect.left > innerWidth) { return null; } @@ -42,15 +55,19 @@ function isElementInViewport(node) { var children = node.children; var visibleChildNode = false; for (i = 0, l = children.length; i < l; ++i) { - boundingRect = children[i].getClientRects()[0] || children[i].getBoundingClientRect(); + boundingRect = (children[i].getClientRects()[0] || + children[i].getBoundingClientRect()); if (boundingRect.width > 1 && boundingRect.height > 1) { visibleChildNode = true; break; } } - if (visibleChildNode === false) return null; + if (visibleChildNode === false) { + return null; + } } - if (boundingRect.top + boundingRect.height < 10 || boundingRect.left + boundingRect.width < -10) { + if (boundingRect.top + boundingRect.height < 10 || + boundingRect.left + boundingRect.width < -10) { return null; } var computedStyle = window.getComputedStyle(node, null); @@ -64,6 +81,7 @@ function isElementInViewport(node) { return boundingRect.top >= -20; } + var walker = document.createTreeWalker(document.body, 4, null); var node; var textNodes = [];