error title

jh-changes
Shin'ya Ueoka 7 years ago
parent d51b674467
commit d5007a747c
  1. 36
      src/console/console-frame.js
  2. 2
      src/console/console.html
  3. 23
      src/console/console.js
  4. 13
      src/content/index.js

@ -1,19 +1,43 @@
import './console-frame.scss'; import './console-frame.scss';
import * as messages from '../shared/messages';
export default class ConsoleFrame { export default class ConsoleFrame {
constructor(win, initial = '') { constructor(win, initial = '') {
let url = browser.runtime.getURL('build/console.html') +
'#' + encodeURIComponent(initial);
let element = window.document.createElement('iframe'); let element = window.document.createElement('iframe');
element.src = url; element.src = browser.runtime.getURL('build/console.html');
element.className = 'vimvixen-console-frame'; element.className = 'vimvixen-console-frame';
win.document.body.append(element); win.document.body.append(element);
this.element = 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() { hide() {
this.element.remove(); this.element.style.display = 'none';
} }
} }

@ -6,7 +6,7 @@
<script src='console.js'></script> <script src='console.js'></script>
</head> </head>
<body class='vimvixen-console'> <body class='vimvixen-console'>
<p id='vimvixen-console-title' <p id='vimvixen-console-error'
class='vimvixen-console-error'></p> class='vimvixen-console-error'></p>
<div> <div>
<p class='vimvixen-console-title'></p> <p class='vimvixen-console-title'></p>

@ -50,16 +50,23 @@ const handleKeyup = (e) => {
}; };
window.addEventListener('load', () => { 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'); let input = window.document.querySelector('#vimvixen-console-command-input');
input.addEventListener('blur', handleBlur); input.addEventListener('blur', handleBlur);
input.addEventListener('keydown', handleKeydown); input.addEventListener('keydown', handleKeydown);
input.addEventListener('keyup', handleKeyup); 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;
}
}); });

@ -5,7 +5,7 @@ import * as messages from '../shared/messages';
import ConsoleFrame from '../console/console-frame'; import ConsoleFrame from '../console/console-frame';
import Follow from './follow'; import Follow from './follow';
let cmd = null; let vvConsole = new ConsoleFrame(window);
const invokeEvent = (action) => { const invokeEvent = (action) => {
if (typeof action === 'undefined' || action === null) { if (typeof action === 'undefined' || action === null) {
@ -14,14 +14,14 @@ const invokeEvent = (action) => {
switch (action[0]) { switch (action[0]) {
case actions.CMD_OPEN: case actions.CMD_OPEN:
cmd = new ConsoleFrame(window); vvConsole.showCommand('');
break; break;
case actions.CMD_TABS_OPEN: case actions.CMD_TABS_OPEN:
if (action[1] || false) { if (action[1] || false) {
// alter url // alter url
cmd = new ConsoleFrame(window, 'open ' + window.location.href); vvConsole.showCommand('open ' + window.location.href);
} else { } else {
cmd = new ConsoleFrame(window, 'open '); vvConsole.showCommand('open ');
} }
break; break;
case actions.SCROLL_LINES: case actions.SCROLL_LINES:
@ -75,10 +75,7 @@ window.addEventListener("keypress", (e) => {
messages.receive(window, (message) => { messages.receive(window, (message) => {
switch (message.type) { switch (message.type) {
case 'vimvixen.commandline.blur': case 'vimvixen.commandline.blur':
if (cmd) { vvConsole.hide();
cmd.remove();
cmd = null;
}
break; break;
case 'vimvixen.commandline.enter': case 'vimvixen.commandline.enter':
browser.runtime.sendMessage({ browser.runtime.sendMessage({