aboutsummaryrefslogtreecommitdiff
path: root/src/content/index.js
diff options
context:
space:
mode:
authorShin'ya Ueoka <ueokande@i-beam.org>2017-08-29 21:32:35 +0900
committerShin'ya Ueoka <ueokande@i-beam.org>2017-08-29 21:32:35 +0900
commitf1b9c6ba9d33fe1927c4855d4981d88ad73d5818 (patch)
treece65ff2c7979d27d86049d5cb13a6d43672817dc /src/content/index.js
parent21404ad534278eff643be089da9c07882b29da82 (diff)
parentb711678329463d1ec5f2eb9db99f99af5b69895e (diff)
Merge branch 'iframe-command-line'
Diffstat (limited to 'src/content/index.js')
-rw-r--r--src/content/index.js62
1 files changed, 38 insertions, 24 deletions
diff --git a/src/content/index.js b/src/content/index.js
index 9dd3706..9bd4e15 100644
--- a/src/content/index.js
+++ b/src/content/index.js
@@ -1,29 +1,10 @@
import * as scrolls from './scrolls';
import * as histories from './histories';
import * as actions from '../shared/actions';
-import FooterLine from './footer-line';
+import CommandLineFrame from '../command-line/command-line-frame';
import Follow from './follow';
-var footer = null;
-
-const createFooterLine = (initial = '') => {
- footer = new FooterLine(document, initial);
- footer.onPromptChange((e) => {
- let request = {
- type: 'event.cmd.suggest',
- text: e.target.value
- };
- browser.runtime.sendMessage(request);
- });
- footer.onEntered((e) => {
- let request = {
- type: 'event.cmd.enter',
- text: e.target.value
- };
- browser.runtime.sendMessage(request);
- });
- footer.focus();
-}
+let cmd = null;
const invokeEvent = (action) => {
if (typeof action === 'undefined' || action === null) {
@@ -32,14 +13,14 @@ const invokeEvent = (action) => {
switch (action[0]) {
case actions.CMD_OPEN:
- createFooterLine();
+ cmd = new CommandLineFrame(window);
break;
case actions.CMD_TABS_OPEN:
if (action[1] || false) {
// alter url
- createFooterLine('open ' + window.location.href);
+ cmd = new CommandLineFrame(window, 'open ' + window.location.href);
} else {
- createFooterLine('open ');
+ cmd = new CommandLineFrame(window, 'open ');
}
break;
case actions.SCROLL_LINES:
@@ -89,3 +70,36 @@ window.addEventListener("keypress", (e) => {
console.log(`Vim Vixen: ${err}`);
});
});
+
+window.addEventListener('message', (e) => {
+ let message;
+ try {
+ message = JSON.parse(e.data);
+ } catch (e) {
+ // ignore message posted by author of web page
+ return;
+ }
+
+ switch (message.type) {
+ case 'vimvixen.commandline.blur':
+ if (cmd) {
+ cmd.remove();
+ cmd = null;
+ }
+ break;
+ case 'vimvixen.commandline.enter':
+ browser.runtime.sendMessage({
+ type: 'event.cmd.enter',
+ text: message.value
+ });
+ break;
+ case 'vimvixen.commandline.change':
+ browser.runtime.sendMessage({
+ type: 'event.cmd.suggest',
+ text: message.value
+ });
+ break;
+ default:
+ return;
+ }
+});