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:
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

View File

@ -1,40 +1,53 @@
/**
* 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.
*
*
* 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 <http://www.gnu.org/licenses/>.
*/
/* 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 = [];