aboutsummaryrefslogtreecommitdiff
path: root/src/content/actions
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-10-08 15:19:25 +0900
committerGitHub <noreply@github.com>2017-10-08 15:19:25 +0900
commit0183161145d36cbafb7dbd86ca3a1aac6faca43f (patch)
treeaed757bfb5f8789156439d1e1fdff4e221376aaa /src/content/actions
parent0f54a203dba38acdd080a928cee95f875fe84706 (diff)
parent57f798044d32ba7f9dc10a34ac31ad5dbdbf56ae (diff)
Merge pull request #22 from ueokande/separate-domains
Refactor: Separate domains
Diffstat (limited to 'src/content/actions')
-rw-r--r--src/content/actions/follow.js29
-rw-r--r--src/content/actions/index.js20
-rw-r--r--src/content/actions/input.js23
-rw-r--r--src/content/actions/operation.js43
4 files changed, 115 insertions, 0 deletions
diff --git a/src/content/actions/follow.js b/src/content/actions/follow.js
new file mode 100644
index 0000000..5a18dd5
--- /dev/null
+++ b/src/content/actions/follow.js
@@ -0,0 +1,29 @@
+import actions from 'content/actions';
+
+const enable = (newTab) => {
+ return {
+ type: actions.FOLLOW_ENABLE,
+ newTab,
+ };
+};
+
+const disable = () => {
+ return {
+ type: actions.FOLLOW_DISABLE,
+ };
+};
+
+const keyPress = (key) => {
+ return {
+ type: actions.FOLLOW_KEY_PRESS,
+ key: key
+ };
+};
+
+const backspace = () => {
+ return {
+ type: actions.FOLLOW_BACKSPACE,
+ };
+};
+
+export { enable, disable, keyPress, backspace };
diff --git a/src/content/actions/index.js b/src/content/actions/index.js
new file mode 100644
index 0000000..0b3749d
--- /dev/null
+++ b/src/content/actions/index.js
@@ -0,0 +1,20 @@
+export default {
+ // User input
+ INPUT_KEY_PRESS: 'input.key,press',
+ INPUT_CLEAR_KEYS: 'input.clear.keys',
+ INPUT_SET_KEYMAPS: 'input.set,keymaps',
+
+ // Completion
+ COMPLETION_SET_ITEMS: 'completion.set.items',
+ COMPLETION_SELECT_NEXT: 'completions.select.next',
+ COMPLETION_SELECT_PREV: 'completions.select.prev',
+
+ // Settings
+ SETTING_SET_SETTINGS: 'setting.set.settings',
+
+ // Follow
+ FOLLOW_ENABLE: 'follow.enable',
+ FOLLOW_DISABLE: 'follow.disable',
+ FOLLOW_KEY_PRESS: 'follow.key.press',
+ FOLLOW_BACKSPACE: 'follow.backspace',
+};
diff --git a/src/content/actions/input.js b/src/content/actions/input.js
new file mode 100644
index 0000000..cc4efac
--- /dev/null
+++ b/src/content/actions/input.js
@@ -0,0 +1,23 @@
+import actions from 'content/actions';
+
+const asKeymapChars = (key, ctrl) => {
+ if (ctrl) {
+ return '<C-' + key.toUpperCase() + '>';
+ }
+ return key;
+};
+
+const keyPress = (key, ctrl) => {
+ return {
+ type: actions.INPUT_KEY_PRESS,
+ key: asKeymapChars(key, ctrl),
+ };
+};
+
+const clearKeys = () => {
+ return {
+ type: actions.INPUT_CLEAR_KEYS
+ };
+};
+
+export { keyPress, clearKeys };
diff --git a/src/content/actions/operation.js b/src/content/actions/operation.js
new file mode 100644
index 0000000..d188a60
--- /dev/null
+++ b/src/content/actions/operation.js
@@ -0,0 +1,43 @@
+import operations from 'shared/operations';
+import messages from 'shared/messages';
+import * as scrolls from 'content/scrolls';
+import * as navigates from 'content/navigates';
+import * as followActions from 'content/actions/follow';
+
+const exec = (operation) => {
+ switch (operation.type) {
+ case operations.SCROLL_LINES:
+ return scrolls.scrollLines(window, operation.count);
+ case operations.SCROLL_PAGES:
+ return scrolls.scrollPages(window, operation.count);
+ case operations.SCROLL_TOP:
+ return scrolls.scrollTop(window);
+ case operations.SCROLL_BOTTOM:
+ return scrolls.scrollBottom(window);
+ case operations.SCROLL_HOME:
+ return scrolls.scrollLeft(window);
+ case operations.SCROLL_END:
+ return scrolls.scrollRight(window);
+ case operations.FOLLOW_START:
+ return followActions.enable(false);
+ case operations.NAVIGATE_HISTORY_PREV:
+ return navigates.historyPrev(window);
+ case operations.NAVIGATE_HISTORY_NEXT:
+ return navigates.historyNext(window);
+ case operations.NAVIGATE_LINK_PREV:
+ return navigates.linkPrev(window);
+ case operations.NAVIGATE_LINK_NEXT:
+ return navigates.linkNext(window);
+ case operations.NAVIGATE_PARENT:
+ return navigates.parent(window);
+ case operations.NAVIGATE_ROOT:
+ return navigates.root(window);
+ default:
+ browser.runtime.sendMessage({
+ type: messages.BACKGROUND_OPERATION,
+ operation,
+ });
+ }
+};
+
+export { exec };