js: Fix some lint.

This commit is contained in:
Florian Bruhin 2015-05-12 07:06:55 +02:00
parent f36a7444d7
commit 7a67af24f0
2 changed files with 34 additions and 16 deletions

View File

@ -5,7 +5,6 @@ env:
rules: rules:
block-scoped-var: 2 block-scoped-var: 2
complexity: [2, 5]
dot-location: 2 dot-location: 2
default-case: 2 default-case: 2
guard-for-in: 2 guard-for-in: 2
@ -42,6 +41,7 @@ rules:
max-depth: [2, 5] max-depth: [2, 5]
max-len: [2, 79, 4] max-len: [2, 79, 4]
max-params: [2, 5] max-params: [2, 5]
max-statements: [2, 20] max-statements: [2, 30]
no-bitwise: 2 no-bitwise: 2
no-reserved-keys: 2 no-reserved-keys: 2
global-strict: 0

View File

@ -1,5 +1,6 @@
/** /**
* Copyright 2014-2015 Florian Bruhin (The Compiler) <mail@qutebrowser.org> * Copyright 2015 Artur Shaik <ashaihullin@gmail.com>
* Copyright 2015 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
* *
* This file is part of qutebrowser. * This file is part of qutebrowser.
* *
@ -17,24 +18,36 @@
* along with qutebrowser. If not, see <http://www.gnu.org/licenses/>. * along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
*/ */
/* eslint-disable max-len */
/** /**
* Snippet to position caret at top of the page when caret mode enabled. * 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 * Some code was borrowed from:
* and https://github.com/1995eaton/chromium-vim/blob/master/content_scripts/visual.js *
* 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) { function isElementInViewport(node) {
var i; var i;
var boundingRect = node.getClientRects()[0] || node.getBoundingClientRect(); var boundingRect = (node.getClientRects()[0] ||
node.getBoundingClientRect());
if (boundingRect.width <= 1 && boundingRect.height <= 1) { if (boundingRect.width <= 1 && boundingRect.height <= 1) {
var rects = node.getClientRects(); var rects = node.getClientRects();
for (i = 0; i < rects.length; i++) { 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]; boundingRect = rects[i];
} }
} }
} }
if (boundingRect === void 0) return null; if (boundingRect === undefined) {
return null;
}
if (boundingRect.top > innerHeight || boundingRect.left > innerWidth) { if (boundingRect.top > innerHeight || boundingRect.left > innerWidth) {
return null; return null;
} }
@ -42,15 +55,19 @@ function isElementInViewport(node) {
var children = node.children; var children = node.children;
var visibleChildNode = false; var visibleChildNode = false;
for (i = 0, l = children.length; i < l; ++i) { 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) { if (boundingRect.width > 1 && boundingRect.height > 1) {
visibleChildNode = true; visibleChildNode = true;
break; 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; return null;
} }
var computedStyle = window.getComputedStyle(node, null); var computedStyle = window.getComputedStyle(node, null);
@ -64,6 +81,7 @@ function isElementInViewport(node) {
return boundingRect.top >= -20; return boundingRect.top >= -20;
} }
var walker = document.createTreeWalker(document.body, 4, null); var walker = document.createTreeWalker(document.body, 4, null);
var node; var node;
var textNodes = []; var textNodes = [];