more strict lint

This commit is contained in:
Shin'ya Ueoka 2017-09-17 08:59:12 +09:00
parent c5529958d5
commit 9ae814dfe4
21 changed files with 211 additions and 157 deletions
src/content

View file

@ -1,7 +1,7 @@
import Hint from './hint';
import HintKeyProducer from './hint-key-producer';
const DEFAULT_HINT_CHARSET = 'abcdefghijklmnopqrstuvwxyz'
const DEFAULT_HINT_CHARSET = 'abcdefghijklmnopqrstuvwxyz';
export default class Follow {
constructor(doc) {
@ -22,14 +22,14 @@ export default class Follow {
let producer = new HintKeyProducer(DEFAULT_HINT_CHARSET);
Array.prototype.forEach.call(elements, (ele) => {
let keys = producer.produce();
let hint = new Hint(ele, keys)
let hint = new Hint(ele, keys);
this.hintElements[keys] = hint;
});
}
handleKeydown(e) {
let keyCode = e.keyCode;
let { keyCode } = e;
if (keyCode === KeyboardEvent.DOM_VK_ESCAPE) {
this.remove();
return;
@ -56,10 +56,10 @@ export default class Follow {
let hidden = Object.keys(this.hintElements).filter((key) => {
return !key.startsWith(chars);
});
if (shown.length == 0) {
if (shown.length === 0) {
this.remove();
return;
} else if (shown.length == 1) {
} else if (shown.length === 1) {
this.remove();
this.hintElements[chars].activate();
}
@ -74,7 +74,7 @@ export default class Follow {
remove() {
this.doc.removeEventListener("keydown", this.boundKeydown);
this.doc.removeEventListener('keydown', this.boundKeydown);
Object.keys(this.hintElements).forEach((key) => {
this.hintElements[key].remove();
});
@ -87,6 +87,14 @@ export default class Follow {
);
}
static isNumericKey(code) {
return KeyboardEvent.DOM_VK_0 <= code && code <= KeyboardEvent.DOM_VK_9;
}
static isAlphabeticKey(code) {
return KeyboardEvent.DOM_VK_A <= code && code <= KeyboardEvent.DOM_VK_Z;
}
static codeChars(codes) {
const CHARCODE_ZERO = '0'.charCodeAt(0);
const CHARCODE_A = 'a'.charCodeAt(0);
@ -94,10 +102,12 @@ export default class Follow {
let chars = '';
for (let code of codes) {
if (KeyboardEvent.DOM_VK_0 <= code && code <= KeyboardEvent.DOM_VK_9) {
chars += String.fromCharCode(code - KeyboardEvent.DOM_VK_0 + CHARCODE_ZERO);
} else if (KeyboardEvent.DOM_VK_A <= code && code <= KeyboardEvent.DOM_VK_Z) {
chars += String.fromCharCode(code - KeyboardEvent.DOM_VK_A + CHARCODE_A);
if (Follow.isNumericKey(code)) {
chars += String.fromCharCode(
code - KeyboardEvent.DOM_VK_0 + CHARCODE_ZERO);
} else if (Follow.isAlphabeticKey(code)) {
chars += String.fromCharCode(
code - KeyboardEvent.DOM_VK_A + CHARCODE_A);
}
}
return chars;
@ -112,7 +122,7 @@ export default class Follow {
}
static isVisibleElement(element) {
var style = window.getComputedStyle(element);
let style = window.getComputedStyle(element);
if (style.display === 'none') {
return false;
} else if (style.visibility === 'hidden') {