aboutsummaryrefslogtreecommitdiff
path: root/src/command-line
diff options
context:
space:
mode:
Diffstat (limited to 'src/command-line')
-rw-r--r--src/command-line/command-line-frame.js19
-rw-r--r--src/command-line/command-line-frame.scss11
-rw-r--r--src/command-line/index.html4
-rw-r--r--src/command-line/index.js63
4 files changed, 96 insertions, 1 deletions
diff --git a/src/command-line/command-line-frame.js b/src/command-line/command-line-frame.js
new file mode 100644
index 0000000..3f1dda4
--- /dev/null
+++ b/src/command-line/command-line-frame.js
@@ -0,0 +1,19 @@
+import './command-line-frame.scss';
+
+export default class CommandLineFrame {
+ constructor(win, initial = '') {
+ let url = browser.runtime.getURL('build/command-line.html') +
+ '#' + encodeURIComponent(initial);
+
+ let element = window.document.createElement('iframe');
+ element.src = url;
+ element.className = 'vimvixen-command-line-frame';
+ win.document.body.append(element);
+
+ this.element = element;
+ }
+
+ remove() {
+ this.element.remove();
+ }
+}
diff --git a/src/command-line/command-line-frame.scss b/src/command-line/command-line-frame.scss
new file mode 100644
index 0000000..67bf514
--- /dev/null
+++ b/src/command-line/command-line-frame.scss
@@ -0,0 +1,11 @@
+.vimvixen-command-line-frame {
+ margin: 0;
+ padding: 0;
+ bottom: 0;
+ left: 0;
+ width: 100%;
+ height: 20px;
+ position: fixed;
+ z-index: 10000;
+ border: none;
+}
diff --git a/src/command-line/index.html b/src/command-line/index.html
index e9e4123..bad0b66 100644
--- a/src/command-line/index.html
+++ b/src/command-line/index.html
@@ -9,7 +9,9 @@
<div>
<p class='vimvixen-command-line-title'></p>
<div class='vimvixen-command-line-line'>
- <i class='vimvixen-command-line-line-prompt'></i><input class='vimvixen-command-line-line-input'></input>
+ <i class='vimvixen-command-line-line-prompt'></i><input
+ id='vimvixen-command-line-line-input'
+ class='vimvixen-command-line-line-input'></input>
</div>
</div>
</body>
diff --git a/src/command-line/index.js b/src/command-line/index.js
index 67aac61..f99afa0 100644
--- a/src/command-line/index.js
+++ b/src/command-line/index.js
@@ -1 +1,64 @@
import './index.scss';
+
+const parent = window.parent;
+
+// TODO consider object-oriented
+var prevValue = "";
+
+const blurData = () => {
+ return JSON.stringify({
+ type: 'vimvixen.commandline.blur'
+ });
+};
+
+const keydownData = (input) => {
+ return JSON.stringify({
+ type: 'vimvixen.commandline.enter',
+ value: input.value
+ });
+};
+
+const keyupData = (input) => {
+ return JSON.stringify({
+ type: 'vimvixen.commandline.change',
+ value: input.value
+ });
+};
+
+const handleBlur = () => {
+ parent.postMessage(blurData(), '*');
+};
+
+const handleKeydown = (e) => {
+ switch(e.keyCode) {
+ case KeyboardEvent.DOM_VK_ESCAPE:
+ parent.postMessage(blurData(), '*');
+ break;
+ case KeyboardEvent.DOM_VK_RETURN:
+ parent.postMessage(keydownData(e.target), '*');
+ break;
+ }
+};
+
+const handleKeyup = (e) => {
+ if (e.target.value === prevValue) {
+ return;
+ }
+ parent.postMessage(keyupData(e.target), '*');
+ prevValue = e.target.value;
+};
+
+window.addEventListener('load', () => {
+ let hash = window.location.hash;
+ let initial = '';
+ if (hash.length > 0) {
+ initial = decodeURIComponent(hash.substring(1));
+ }
+
+ let input = window.document.querySelector('#vimvixen-command-line-line-input');
+ input.addEventListener('blur', handleBlur);
+ input.addEventListener('keydown', handleKeydown);
+ input.addEventListener('keyup', handleKeyup);
+ input.value = initial;
+ input.focus();
+});