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/command-line/command-line-frame.js | 19 ---------- src/command-line/command-line-frame.scss | 11 ------ src/command-line/command-line.html | 18 --------- src/command-line/command-line.js | 64 -------------------------------- src/command-line/command-line.scss | 52 -------------------------- src/console/console-frame.js | 19 ++++++++++ src/console/console-frame.scss | 11 ++++++ src/console/console.html | 18 +++++++++ src/console/console.js | 64 ++++++++++++++++++++++++++++++++ src/console/console.scss | 52 ++++++++++++++++++++++++++ src/content/index.js | 8 ++-- 11 files changed, 168 insertions(+), 168 deletions(-) delete mode 100644 src/command-line/command-line-frame.js delete mode 100644 src/command-line/command-line-frame.scss delete mode 100644 src/command-line/command-line.html delete mode 100644 src/command-line/command-line.js delete mode 100644 src/command-line/command-line.scss create mode 100644 src/console/console-frame.js create mode 100644 src/console/console-frame.scss create mode 100644 src/console/console.html create mode 100644 src/console/console.js create mode 100644 src/console/console.scss (limited to 'src') diff --git a/src/command-line/command-line-frame.js b/src/command-line/command-line-frame.js deleted file mode 100644 index 3f1dda4..0000000 --- a/src/command-line/command-line-frame.js +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index 88772d9..0000000 --- a/src/command-line/command-line-frame.scss +++ /dev/null @@ -1,11 +0,0 @@ -.vimvixen-command-line-frame { - margin: 0; - padding: 0; - bottom: 0; - left: 0; - width: 100%; - height: 100%; - position: fixed; - z-index: 10000; - border: none; -} diff --git a/src/command-line/command-line.html b/src/command-line/command-line.html deleted file mode 100644 index bad0b66..0000000 --- a/src/command-line/command-line.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - - VimVixen command-line - - - -
-

-
- -
-
- - diff --git a/src/command-line/command-line.js b/src/command-line/command-line.js deleted file mode 100644 index 34f3f35..0000000 --- a/src/command-line/command-line.js +++ /dev/null @@ -1,64 +0,0 @@ -import './command-line.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(); -}); diff --git a/src/command-line/command-line.scss b/src/command-line/command-line.scss deleted file mode 100644 index 68a0a03..0000000 --- a/src/command-line/command-line.scss +++ /dev/null @@ -1,52 +0,0 @@ -html, body, * { - margin: 0; - padding: 0; -} - -body { - position: absolute; - bottom: 0; - left: 0; - right: 0; -} - -.vimvixen-command-line { - border-top: 1px solid gray; - bottom: 0; - margin: 0; - padding: 0; - - @mixin input-style { - font-style: normal; - font-family: monospace; - font-size: 12px; - } - - - &-title { - background-color: lightgray; - font-weight: bold; - margin: 0; - padding: 0; - - @include input-style; - } - - &-line { - background-color: white; - display: flex; - - &-prompt:before { - content: ':'; - - @include input-style; - } - - &-input { - border: none; - flex-grow: 1; - - @include input-style; - } - } -} diff --git a/src/console/console-frame.js b/src/console/console-frame.js new file mode 100644 index 0000000..cf72f25 --- /dev/null +++ b/src/console/console-frame.js @@ -0,0 +1,19 @@ +import './console-frame.scss'; + +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.className = 'vimvixen-console-frame'; + win.document.body.append(element); + + this.element = element; + } + + remove() { + this.element.remove(); + } +} diff --git a/src/console/console-frame.scss b/src/console/console-frame.scss new file mode 100644 index 0000000..1bab2b0 --- /dev/null +++ b/src/console/console-frame.scss @@ -0,0 +1,11 @@ +.vimvixen-console-frame { + margin: 0; + padding: 0; + bottom: 0; + left: 0; + width: 100%; + height: 100%; + position: fixed; + z-index: 10000; + border: none; +} 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 + + + +
+

+
+ +
+
+ + diff --git a/src/console/console.js b/src/console/console.js new file mode 100644 index 0000000..f8a91a6 --- /dev/null +++ b/src/console/console.js @@ -0,0 +1,64 @@ +import './console.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-console-command-input'); + input.addEventListener('blur', handleBlur); + input.addEventListener('keydown', handleKeydown); + input.addEventListener('keyup', handleKeyup); + input.value = initial; + input.focus(); +}); diff --git a/src/console/console.scss b/src/console/console.scss new file mode 100644 index 0000000..becc15c --- /dev/null +++ b/src/console/console.scss @@ -0,0 +1,52 @@ +html, body, * { + margin: 0; + padding: 0; +} + +body { + position: absolute; + bottom: 0; + left: 0; + right: 0; +} + +.vimvixen-console { + border-top: 1px solid gray; + bottom: 0; + margin: 0; + padding: 0; + + @mixin input-style { + font-style: normal; + font-family: monospace; + font-size: 12px; + } + + + &-title { + background-color: lightgray; + font-weight: bold; + margin: 0; + padding: 0; + + @include input-style; + } + + &-command { + background-color: white; + display: flex; + + &-prompt:before { + content: ':'; + + @include input-style; + } + + &-input { + border: none; + flex-grow: 1; + + @include input-style; + } + } +} diff --git a/src/content/index.js b/src/content/index.js index 9bd4e15..591aa98 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -1,7 +1,7 @@ import * as scrolls from './scrolls'; import * as histories from './histories'; import * as actions from '../shared/actions'; -import CommandLineFrame from '../command-line/command-line-frame'; +import ConsoleFrame from '../console/console-frame'; import Follow from './follow'; let cmd = null; @@ -13,14 +13,14 @@ const invokeEvent = (action) => { switch (action[0]) { case actions.CMD_OPEN: - cmd = new CommandLineFrame(window); + cmd = new ConsoleFrame(window); break; case actions.CMD_TABS_OPEN: if (action[1] || false) { // alter url - cmd = new CommandLineFrame(window, 'open ' + window.location.href); + cmd = new ConsoleFrame(window, 'open ' + window.location.href); } else { - cmd = new CommandLineFrame(window, 'open '); + cmd = new ConsoleFrame(window, 'open '); } break; case actions.SCROLL_LINES: -- cgit v1.2.3