From 70b8c396c273172ad2bc5b5cead0db7ad071767c Mon Sep 17 00:00:00 2001 From: Phil Crosby Date: Sun, 7 Mar 2010 17:27:29 -0800 Subject: Show a help dialog when pressing ? which displays all of the current keybindings o_O --- vimiumFrontend.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'vimiumFrontend.js') diff --git a/vimiumFrontend.js b/vimiumFrontend.js index f3259f10..a7dd263d 100644 --- a/vimiumFrontend.js +++ b/vimiumFrontend.js @@ -14,6 +14,7 @@ var insertMode = false; var findMode = false; var findModeQuery = ""; var findModeQueryHasResults = false; +var isShowingHelpDialog = false; var keyPort; var settingPort; var saveZoomLevelPort; @@ -85,6 +86,8 @@ function initializePreDomReady() { HUD.hideUpgradeNotification(); else if (request.name == "showUpgradeNotification" && isEnabledForUrl) HUD.showUpgradeNotification(request.version); + else if (request.name == "showHelpDialog") + showHelpDialog(request.dialogHtml); sendResponse({}); // Free up the resources used by this open connection. }); @@ -331,6 +334,10 @@ function onKeydown(event) { else if (event.keyCode == keyCodes.enter) handleEnterForFindMode(); } + else if (isShowingHelpDialog && isEscape(event)) + { + hideHelpDialog(); + } else if (!insertMode && !findMode) { if (keyChar) { if (currentCompletionKeys.indexOf(keyChar) != -1) { @@ -483,6 +490,24 @@ function exitFindMode() { HUD.hide(); } +function showHelpDialog(html) { + if (isShowingHelpDialog) + return false; + isShowingHelpDialog = true; + var container = document.createElement("div"); + container.id = "vimiumHelpDialogContainer"; + container.innerHTML = html; + container.getElementsByClassName("closeButton")[0].addEventListener("click", hideHelpDialog, false); + document.body.appendChild(container); +} + +function hideHelpDialog() { + isShowingHelpDialog = false; + var helpDialog = document.getElementById("vimiumHelpDialogContainer"); + if (helpDialog) + helpDialog.parentNode.removeChild(helpDialog); +} + /* * A heads-up-display (HUD) for showing Vimium page operations. * Note: you cannot interact with the HUD until document.body is available. -- cgit v1.2.3