From 50241c91d286c5a5b473e34def38697c2d08d7cc Mon Sep 17 00:00:00 2001 From: Colin Caine Date: Thu, 5 Oct 2017 15:27:45 +0100 Subject: [PATCH] src: hide commandline after exec --- src/commandline_content.ts | 28 ++++++++++++++++------------ src/commandline_frame.ts | 2 +- src/excmds_background.ts | 4 ++++ src/excmds_content.ts | 6 ++++-- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/commandline_content.ts b/src/commandline_content.ts index be1da56a..05ec8e75 100644 --- a/src/commandline_content.ts +++ b/src/commandline_content.ts @@ -11,22 +11,26 @@ // inject the commandline iframe into a content page -export let COMMANDLINE = null +let cmdline_iframe: HTMLIFrameElement = undefined + +function init(){ + cmdline_iframe = window.document.createElement("iframe") + cmdline_iframe.setAttribute("src", browser.extension.getURL("static/commandline.html")) + window.document.body.appendChild(cmdline_iframe) +} export function show(){ - COMMANDLINE = window.document.createElement("iframe") - COMMANDLINE.setAttribute("src", browser.extension.getURL("static/commandline.html")) - COMMANDLINE.setAttribute("style", "position: fixed; top: 0; left: 0; z-index: 10000; width: 100%; height: 36px; border: 0; padding: 0; margin: 0;"); - window.document.body.appendChild(COMMANDLINE) + if (cmdline_iframe === undefined) { + init() + } + cmdline_iframe.setAttribute("style", "position: fixed; top: 0; left: 0; z-index: 10000; width: 100%; height: 36px; border: 0; padding: 0; margin: 0;"); +} - /** Focus the commandline input: not required **/ - // let focus = ():void => COMMANDLINE.focus() - // line below doesn't work - COMMANDLINE.addEventListener("blur",COMMANDLINE.remove) - // Why were we returning focus? It's a void, surely? - // return focus +export function hide(){ + cmdline_iframe.setAttribute("style", "display: none") } export function focus(){ - COMMANDLINE.focus() + show() + cmdline_iframe.focus() } diff --git a/src/commandline_frame.ts b/src/commandline_frame.ts index aae16d51..463b3272 100644 --- a/src/commandline_frame.ts +++ b/src/commandline_frame.ts @@ -12,9 +12,9 @@ clInput.addEventListener("keydown", function (keyevent) { /* Send the commandline to the background script and await response. */ function process() { - // TODO. console.log(clInput.value) browser.runtime.sendMessage({type: "commandline", exStr: clInput.value}) + browser.runtime.sendMessage({type: "commandline", exStr: "hidecommandline"}) clInput.value = "" } diff --git a/src/excmds_background.ts b/src/excmds_background.ts index 26a1a7b1..ca3c536c 100644 --- a/src/excmds_background.ts +++ b/src/excmds_background.ts @@ -90,6 +90,10 @@ export function showcommandline(){ messageActiveTab("showcommandline") } +export function hidecommandline(){ + messageActiveTab("hidecommandline") +} + // TODO: address should default to some page to which we have access // and focus the location bar export async function tabopen(address?: string){ diff --git a/src/excmds_content.ts b/src/excmds_content.ts index 06e4c856..716a0977 100644 --- a/src/excmds_content.ts +++ b/src/excmds_content.ts @@ -24,9 +24,11 @@ const commands = new Map([ window.history.go(n) }, function showcommandline() { - CommandLineContent.show() CommandLineContent.focus() - } + }, + function hidecommandline() { + CommandLineContent.hide() + }, ].map((command):any => [command.name, command])) function messageReceiver(message) {