From 6e5286ef10b26d0a09f3882d6c3bfdbd92223d0f Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Fri, 1 Sep 2017 08:51:14 +0900 Subject: Rename command-line to console --- src/console/console.html | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/console/console.html (limited to 'src/console/console.html') diff --git a/src/console/console.html b/src/console/console.html new file mode 100644 index 0000000..9177045 --- /dev/null +++ b/src/console/console.html @@ -0,0 +1,18 @@ + + + + + VimVixen console + + + +
+

+
+ +
+
+ + -- cgit v1.2.3 From 95c095f366106952d25982f12d99e4858c54cdb9 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Fri, 1 Sep 2017 09:23:01 +0900 Subject: add console error element --- src/console/console.html | 1 + src/console/console.scss | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'src/console/console.html') diff --git a/src/console/console.html b/src/console/console.html index 9177045..206976a 100644 --- a/src/console/console.html +++ b/src/console/console.html @@ -6,6 +6,7 @@ +

diff --git a/src/console/console.scss b/src/console/console.scss index becc15c..0de873d 100644 --- a/src/console/console.scss +++ b/src/console/console.scss @@ -16,10 +16,19 @@ body { margin: 0; padding: 0; - @mixin input-style { + @mixin consoole-font { font-style: normal; font-family: monospace; font-size: 12px; + line-height: 16px; + } + + &-error { + background-color: red; + font-weight: bold; + color: white; + + @include consoole-font; } @@ -29,7 +38,7 @@ body { margin: 0; padding: 0; - @include input-style; + @include consoole-font; } &-command { @@ -39,14 +48,14 @@ body { &-prompt:before { content: ':'; - @include input-style; + @include consoole-font; } &-input { border: none; flex-grow: 1; - @include input-style; + @include consoole-font; } } } -- cgit v1.2.3 From d51b6744679f7a0c40c5479b2cf386a6b04c34c9 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Fri, 1 Sep 2017 12:38:51 +0900 Subject: error text --- src/console/console.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/console/console.html') diff --git a/src/console/console.html b/src/console/console.html index 206976a..feee5d0 100644 --- a/src/console/console.html +++ b/src/console/console.html @@ -6,7 +6,8 @@ -

+

-- cgit v1.2.3 From d5007a747cdc39b2978847cd7c012515e5169ff7 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Fri, 1 Sep 2017 12:50:29 +0900 Subject: error title --- src/console/console-frame.js | 36 ++++++++++++++++++++++++++++++------ src/console/console.html | 2 +- src/console/console.js | 23 +++++++++++++++-------- src/content/index.js | 13 +++++-------- 4 files changed, 51 insertions(+), 23 deletions(-) (limited to 'src/console/console.html') diff --git a/src/console/console-frame.js b/src/console/console-frame.js index cf72f25..f8aeeeb 100644 --- a/src/console/console-frame.js +++ b/src/console/console-frame.js @@ -1,19 +1,43 @@ import './console-frame.scss'; +import * as messages from '../shared/messages'; export default class ConsoleFrame { constructor(win, initial = '') { - let url = browser.runtime.getURL('build/console.html') + - '#' + encodeURIComponent(initial); - let element = window.document.createElement('iframe'); - element.src = url; + element.src = browser.runtime.getURL('build/console.html'); element.className = 'vimvixen-console-frame'; win.document.body.append(element); this.element = element; + + this.hide(); + } + + showCommand(text) { + this.showFrame(); + + let message = { + type: 'vimvixen.console.show.command', + text: text + }; + messages.send(this.element.contentWindow, message); + } + + showError(text) { + this.showFrame(); + + let message = { + type: 'vimvixen.console.show.error', + text: text + }; + messages.send(this.element.contentWindow, message); + } + + showFrame() { + this.element.style.display = 'block'; } - remove() { - this.element.remove(); + hide() { + this.element.style.display = 'none'; } } diff --git a/src/console/console.html b/src/console/console.html index feee5d0..228660b 100644 --- a/src/console/console.html +++ b/src/console/console.html @@ -6,7 +6,7 @@ -

diff --git a/src/console/console.js b/src/console/console.js index 67b9eab..2db9d29 100644 --- a/src/console/console.js +++ b/src/console/console.js @@ -50,16 +50,23 @@ const handleKeyup = (e) => { }; 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-console-command-input'); input.addEventListener('blur', handleBlur); input.addEventListener('keydown', handleKeydown); input.addEventListener('keyup', handleKeyup); - input.value = initial; - input.focus(); +}); + +messages.receive(window, (message) => { + switch (message.type) { + case 'vimvixen.console.show.command': + if (message.text) { + let input = window.document.querySelector('#vimvixen-console-command-input'); + input.value = message.text; + input.focus(); + } + break; + case 'vimvixen.console.show.error': + window.document.querySelector('#vimvixen-console-error').textContent = message.text; + break; + } }); diff --git a/src/content/index.js b/src/content/index.js index ad3f740..66b1121 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -5,7 +5,7 @@ import * as messages from '../shared/messages'; import ConsoleFrame from '../console/console-frame'; import Follow from './follow'; -let cmd = null; +let vvConsole = new ConsoleFrame(window); const invokeEvent = (action) => { if (typeof action === 'undefined' || action === null) { @@ -14,14 +14,14 @@ const invokeEvent = (action) => { switch (action[0]) { case actions.CMD_OPEN: - cmd = new ConsoleFrame(window); + vvConsole.showCommand(''); break; case actions.CMD_TABS_OPEN: if (action[1] || false) { // alter url - cmd = new ConsoleFrame(window, 'open ' + window.location.href); + vvConsole.showCommand('open ' + window.location.href); } else { - cmd = new ConsoleFrame(window, 'open '); + vvConsole.showCommand('open '); } break; case actions.SCROLL_LINES: @@ -75,10 +75,7 @@ window.addEventListener("keypress", (e) => { messages.receive(window, (message) => { switch (message.type) { case 'vimvixen.commandline.blur': - if (cmd) { - cmd.remove(); - cmd = null; - } + vvConsole.hide(); break; case 'vimvixen.commandline.enter': browser.runtime.sendMessage({ -- cgit v1.2.3 From 02ea10a357955752dda4c72c49de2340997c9818 Mon Sep 17 00:00:00 2001 From: Shin'ya Ueoka Date: Fri, 1 Sep 2017 16:29:36 +0900 Subject: show error text --- src/console/console-frame.js | 2 +- src/console/console-frame.scss | 1 + src/console/console.html | 2 +- src/console/console.js | 29 +++++++++++++++++++++++------ 4 files changed, 26 insertions(+), 8 deletions(-) (limited to 'src/console/console.html') diff --git a/src/console/console-frame.js b/src/console/console-frame.js index dc67650..aabb96a 100644 --- a/src/console/console-frame.js +++ b/src/console/console-frame.js @@ -2,7 +2,7 @@ import './console-frame.scss'; import * as messages from '../shared/messages'; export default class ConsoleFrame { - constructor(win, initial = '') { + constructor(win) { let element = window.document.createElement('iframe'); element.src = browser.runtime.getURL('build/console.html'); element.className = 'vimvixen-console-frame'; diff --git a/src/console/console-frame.scss b/src/console/console-frame.scss index 1bab2b0..33bfff3 100644 --- a/src/console/console-frame.scss +++ b/src/console/console-frame.scss @@ -8,4 +8,5 @@ position: fixed; z-index: 10000; border: none; + pointer-events:none; } diff --git a/src/console/console.html b/src/console/console.html index 228660b..2eb445d 100644 --- a/src/console/console.html +++ b/src/console/console.html @@ -8,7 +8,7 @@

-
+

{ input.addEventListener('keyup', handleKeyup); }); +const showCommand = (text) => { + let input = window.document.querySelector('#vimvixen-console-command-input'); + input.value = text; + input.focus(); + + let command = window.document.querySelector('#vimvixen-console-command'); + command.style.display = 'block'; + + let error = window.document.querySelector('#vimvixen-console-error'); + error.style.display = 'none'; +} + +const showError = (text) => { + let error = window.document.querySelector('#vimvixen-console-error'); + error.textContent = text; + error.style.display = 'block'; + + let command = window.document.querySelector('#vimvixen-console-command'); + command.style.display = 'none'; +} + messages.receive(window, (message) => { switch (message.type) { case 'vimvixen.console.show.command': - if (message.text) { - let input = window.document.querySelector('#vimvixen-console-command-input'); - input.value = message.text; - input.focus(); - } + showCommand(message.text); break; case 'vimvixen.console.show.error': - window.document.querySelector('#vimvixen-console-error').textContent = message.text; + showError(message.text); break; } }); -- cgit v1.2.3