aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShin'ya UEOKA <ueokande@i-beam.org>2017-10-03 02:54:38 +0000
committerShin'ya Ueoka <ueokande@i-beam.org>2017-10-03 20:20:24 +0900
commiteff8d9a83edf63bab09df4bd7f6e20e85fba3899 (patch)
treefb1caae5abf8c4c01a8e537b173ce45806c3592e
parentb5e52a75d760c23d2ac7257056f9ba592ad17b34 (diff)
comtent input as compoents
-rw-r--r--src/components/content-input.js31
-rw-r--r--src/content/index.js18
2 files changed, 33 insertions, 16 deletions
diff --git a/src/components/content-input.js b/src/components/content-input.js
new file mode 100644
index 0000000..81f2e6b
--- /dev/null
+++ b/src/components/content-input.js
@@ -0,0 +1,31 @@
+import messages from '../content/messages';
+
+export default class ContentInputComponent {
+ constructor(target) {
+ target.addEventListener('keypress', this.onKeyPress.bind(this));
+ target.addEventListener('keydown', this.onKeyDown.bind(this));
+ target.addEventListener('keyup', this.onKeyUp.bind(this));
+ }
+
+ onKeyPress(e) {
+ if (e.target instanceof HTMLInputElement ||
+ e.target instanceof HTMLTextAreaElement ||
+ e.target instanceof HTMLSelectElement) {
+ if (e.key === 'Escape' && e.target.blur) {
+ e.target.blur();
+ }
+ return;
+ }
+ browser.runtime.sendMessage({
+ type: messages.KEYDOWN,
+ code: e.which,
+ ctrl: e.ctrlKey
+ });
+ }
+
+ onKeyDown() {
+ }
+
+ onKeyUp() {
+ }
+}
diff --git a/src/content/index.js b/src/content/index.js
index 0dbc8c1..e5a2965 100644
--- a/src/content/index.js
+++ b/src/content/index.js
@@ -4,6 +4,7 @@ import * as scrolls from '../content/scrolls';
import * as navigates from '../content/navigates';
import * as followActions from '../actions/follow';
import * as store from '../store';
+import ContentInputComponent from '../components/content-input';
import FollowComponent from '../components/follow';
import followReducer from '../reducers/follow';
import operations from '../operations';
@@ -18,25 +19,10 @@ followStore.subscribe(() => {
console.error(e);
}
});
+const contentInputComponent = new ContentInputComponent(window);
consoleFrames.initialize(window.document);
-window.addEventListener('keypress', (e) => {
- if (e.target instanceof HTMLInputElement ||
- e.target instanceof HTMLTextAreaElement ||
- e.target instanceof HTMLSelectElement) {
- if (e.key === 'Escape' && e.target.blur) {
- e.target.blur();
- }
- return;
- }
- browser.runtime.sendMessage({
- type: messages.KEYDOWN,
- code: e.which,
- ctrl: e.ctrlKey
- });
-});
-
const execOperation = (operation) => {
switch (operation.type) {
case operations.SCROLL_LINES: