blur as action/reducer
This commit is contained in:
parent
3c67cc0a00
commit
359fdb5288
4 changed files with 49 additions and 69 deletions
|
@ -1,48 +0,0 @@
|
|||
import './console-frame.scss';
|
||||
import * as consoleActions from '../actions/console';
|
||||
|
||||
export default class ConsoleFrame {
|
||||
constructor(win) {
|
||||
let element = window.document.createElement('iframe');
|
||||
element.src = browser.runtime.getURL('build/console.html');
|
||||
element.className = 'vimvixen-console-frame';
|
||||
win.document.body.append(element);
|
||||
|
||||
this.element = element;
|
||||
|
||||
this.errorShown = true;
|
||||
|
||||
this.hide();
|
||||
}
|
||||
|
||||
showCommand(text) {
|
||||
this.showFrame();
|
||||
this.errorShown = false;
|
||||
return browser.runtime.sendMessage(consoleActions.showCommand(text));
|
||||
}
|
||||
|
||||
showError(text) {
|
||||
this.showFrame();
|
||||
|
||||
this.errorShown = true;
|
||||
this.element.blur();
|
||||
|
||||
return browser.runtime.sendMessage(consoleActions.showError(text));
|
||||
}
|
||||
|
||||
showFrame() {
|
||||
this.element.style.display = 'block';
|
||||
}
|
||||
|
||||
hide() {
|
||||
this.element.style.display = 'none';
|
||||
this.element.blur();
|
||||
this.errorShown = false;
|
||||
|
||||
return browser.runtime.sendMessage(consoleActions.hide());
|
||||
}
|
||||
|
||||
isErrorShown() {
|
||||
return this.element.style.display === 'block' && this.errorShown;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
import './console.scss';
|
||||
import * as backgroundActions from '../actions/background';
|
||||
import * as consoleActions from '../actions/console';
|
||||
import Completion from './completion';
|
||||
import consoleReducer from '../reducers/console';
|
||||
|
||||
|
@ -9,12 +10,6 @@ var completion = null;
|
|||
var completionOrigin = "";
|
||||
let state = consoleReducer(undefined, {});
|
||||
|
||||
const blurMessage = () => {
|
||||
return {
|
||||
type: 'vimvixen.command.blur'
|
||||
};
|
||||
};
|
||||
|
||||
const keydownMessage = (input) => {
|
||||
return {
|
||||
type: 'vimvixen.command.enter',
|
||||
|
@ -23,7 +18,7 @@ const keydownMessage = (input) => {
|
|||
};
|
||||
|
||||
const handleBlur = () => {
|
||||
return browser.runtime.sendMessage(blurMessage());
|
||||
return browser.runtime.sendMessage(consoleActions.hide());
|
||||
};
|
||||
|
||||
const completeNext = () => {
|
||||
|
@ -57,9 +52,11 @@ const completePrev = () => {
|
|||
}
|
||||
|
||||
const handleKeydown = (e) => {
|
||||
let input = window.document.querySelector('#vimvixen-console-command-input');
|
||||
|
||||
switch(e.keyCode) {
|
||||
case KeyboardEvent.DOM_VK_ESCAPE:
|
||||
return browser.runtime.sendMessage(blurMessage());
|
||||
return input.blur();
|
||||
case KeyboardEvent.DOM_VK_RETURN:
|
||||
return browser.runtime.sendMessage(keydownMessage(e.target));
|
||||
case KeyboardEvent.DOM_VK_TAB:
|
||||
|
@ -183,3 +180,7 @@ browser.runtime.onMessage.addListener((action) => {
|
|||
state = nextState;
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
update({}, state);
|
||||
});
|
||||
|
|
27
src/console/frames.js
Normal file
27
src/console/frames.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
import './console-frame.scss';
|
||||
import * as consoleActions from '../actions/console';
|
||||
|
||||
const initialize = (doc) => {
|
||||
let iframe = doc.createElement('iframe');
|
||||
iframe.src = browser.runtime.getURL('build/console.html');
|
||||
iframe.id = 'vimvixen-console-frame';
|
||||
iframe.className = 'vimvixen-console-frame';
|
||||
doc.body.append(iframe);
|
||||
|
||||
return iframe;
|
||||
}
|
||||
|
||||
const showCommand = (text) => {
|
||||
return browser.runtime.sendMessage(consoleActions.showCommand(text));
|
||||
};
|
||||
|
||||
const showError = (text) => {
|
||||
return browser.runtime.sendMessage(consoleActions.showError(text));
|
||||
}
|
||||
|
||||
const blur = (doc) => {
|
||||
let iframe = doc.getElementById('vimvixen-console-frame');
|
||||
iframe.blur();
|
||||
}
|
||||
|
||||
export { initialize, showCommand, showError, blur };
|
Reference in a new issue