diff options
| -rw-r--r-- | CREDITS | 1 | ||||
| -rw-r--r-- | README.markdown | 15 | ||||
| -rw-r--r-- | background_page.html | 36 | ||||
| -rw-r--r-- | helpDialog.html | 32 | ||||
| -rw-r--r-- | manifest.json | 2 | ||||
| -rw-r--r-- | options.html | 54 | ||||
| -rw-r--r-- | vimiumFrontend.js | 33 | 
7 files changed, 100 insertions, 73 deletions
| @@ -10,6 +10,7 @@ Contributors:    Christian Stefanescu (github: stchris)    ConradIrwin    drizzd +  hogelog    int3    Johannes Emerich (github: knuton)    Julian Naydichev <rublind@gmail.com> (github: naydichev) diff --git a/README.markdown b/README.markdown index 9b122f56..fcf50fad 100644 --- a/README.markdown +++ b/README.markdown @@ -30,10 +30,8 @@ Navigating the current page:      l       scroll right      gg      scroll to top of the page      G       scroll to bottom of the page -    <c-d>, <c-e>   scroll down a page -    <c-u>, <c-y>   scroll up a page -    <c-f>   scroll down a full page -    <c-b>   scroll up a full page +    d, <c-d>  scroll down half a page +    u, <c-u>  scroll up half a page      f       open a link in the current tab      F       open a link in a new tab      r       reload @@ -57,8 +55,8 @@ Manipulating tabs:      J, gT      go one tab left      K, gt      go one tab right      t          create tab -    d          close current tab -    u          restore closed tab (i.e. unwind the 'd' command) +    x          close current tab +    X          restore closed tab (i.e. unwind the 'x' command)  Additional advanced browsing commands:      ]]      Follow the link labeled 'next' or '>'. Helpful for browsing paginated sites. @@ -69,6 +67,8 @@ Additional advanced browsing commands:      zH      scroll all the way left      zL      scroll all the way right      z0      reset zoom to default value +    <c-f>   scroll down a full page +    <c-b>   scroll up a full page  Vimium supports command repetition so, for example, hitting '5t' will open 5 tabs in rapid succession. ESC (or @@ -94,13 +94,14 @@ don't exceed 110 characters.  Release Notes  ------------- -1.22 +1.22, 1.23, 1.24, 1.25 (02/10/2011)  -  Some sites are now excluded by default.  -  View source (`gs`) now opens in a new tab.  -  Support for browsing paginated sites using `]]` and `[[` to go forward and backward respectively.  -  `z0` will reset the zoom level for the current page.  -  Many of the less-used commands are now marked as "advanced" and hidden in the help dialog by default, so that the core command set is more focused and approachable. +-  Improvements to link hinting.  -  Bugfixes.  1.21 (10/24/2010) diff --git a/background_page.html b/background_page.html index abb91677..5b055dbb 100644 --- a/background_page.html +++ b/background_page.html @@ -18,8 +18,9 @@    var focusedFrame = null;    var framesForTab = {}; -  // Keys are either literal characters, or "named" - for example <a-b> (alt+b), <left> (the left arrow) or <f12> -  // This regular expression captures two groups, the first is a named key, the second is the remainder of the string. +  // Keys are either literal characters, or "named" - for example <a-b> (alt+b), <left> (left arrow) or <f12> +  // This regular expression captures two groups: the first is a named key, the second is the remainder of +  // the string.    var namedKeyRegex = /^(<(?:[amc]-.|(?:[amc]-)?[a-z0-9]{2,5})>)(.*)$/;    var defaultSettings = { @@ -79,7 +80,8 @@      upgradeNotificationClosed: upgradeNotificationClosed,      updateScrollPosition: handleUpdateScrollPosition,      copyToClipboard: copyToClipboard, -    isEnabledForUrl: isEnabledForUrl +    isEnabledForUrl: isEnabledForUrl, +    saveHelpDialogSettings: saveHelpDialogSettings    };    // Event handlers @@ -140,7 +142,7 @@     */    function isEnabledForUrl(request) {      // excludedUrls are stored as a series of URL expressions separated by newlines. -    var excludedUrls = (localStorage["excludedUrls"] || defaultSettings.excludedUrls).split("\n"); +    var excludedUrls = getSettingFromLocalStorage("excludedUrls").split("\n");      var isEnabled = true;      for (var i = 0; i < excludedUrls.length; i++) {        // The user can add "*" to the URL which means ".*" @@ -151,6 +153,10 @@      return { isEnabledForUrl: isEnabled };    } +  function saveHelpDialogSettings(request) { +    localStorage["helpDialog_showAdvancedCommands"] = request.showAdvancedCommands; +  } +    /*     * Returns the previously saved zoom level for the current tab, or the default zoom level     */ @@ -158,14 +164,14 @@      var returnPort = chrome.tabs.connect(port.tab.id, { name: "returnZoomLevel" });      var localStorageKey = "zoom" + args.domain;      var zoomLevelForDomain = (localStorage[localStorageKey] || "").split(",")[1]; -    var zoomLevel = parseInt(zoomLevelForDomain || localStorage["defaultZoomLevel"] || -        defaultSettings.defaultZoomLevel); +    var zoomLevel = parseInt(zoomLevelForDomain || getSettingFromLocalStorage("defaultZoomLevel"));      returnPort.postMessage({ zoomLevel: zoomLevel });    }    function showHelp(callback, frameId) {      chrome.tabs.getSelected(null, function(tab) { -      chrome.tabs.sendRequest(tab.id, { name: "showHelpDialog", dialogHtml: helpDialogHtml(), frameId:frameId }); +      chrome.tabs.sendRequest(tab.id, +        { name: "showHelpDialog", dialogHtml: helpDialogHtml(), frameId:frameId });      });    } @@ -185,6 +191,8 @@                                          showUnboundCommands, showCommandNames));      dialogHtml = dialogHtml.replace("{{version}}", currentVersion);      dialogHtml = dialogHtml.replace("{{title}}", customTitle || "Help"); +    dialogHtml = dialogHtml.replace("{{showAdvancedCommands}}", +        localStorage["helpDialog_showAdvancedCommands"] == "true");      return dialogHtml;    } @@ -276,13 +284,23 @@     * Used by the content scripts to get settings from the local storage.     */    function getSetting(args, port) { -    var value = localStorage[args.key] ? localStorage[args.key] : defaultSettings[args.key]; - +    var value = getSettingFromLocalStorage(args.key);      var returnPort = chrome.tabs.connect(port.tab.id, { name: "returnSetting" });      returnPort.postMessage({ key: args.key, value: value });    }    /* +   * Used by everyone to get settings from local storage. +   */ +  function getSettingFromLocalStorage(setting) { +    if (localStorage[setting] != "" && !localStorage[setting]) { +      return defaultSettings[setting]; +    } else { +      return localStorage[setting]; +    } +  } + +  /*     * Persists the current zoom level for a given domain     */    function saveZoomLevel(args) { diff --git a/helpDialog.html b/helpDialog.html index c21c8b7b..51ff1692 100644 --- a/helpDialog.html +++ b/helpDialog.html @@ -5,7 +5,7 @@  <div id="vimiumHelpDialog">    <style>      #vimiumHelpDialog * { -      font-size:12px; +      font-size:11px;        line-height:130%;        color:black;        background-color:transparent; @@ -27,6 +27,7 @@        margin-left:-320px;        top:50px;        -webkit-box-shadow: rgba(0, 0, 0, 0.4) 0px 0px 6px; +      z-index:99999998;      }      #vimiumHelpDialog a { color:blue; }      #vimiumTitle, #vimiumTitle * { font-size:20px; } @@ -132,10 +133,15 @@    <script>      VimiumHelpDialog = { +      // This setting is pulled out of local storage. It's false by default. +      advancedCommandsVisible: {{showAdvancedCommands}}, +        init: function() {          this.dialogElement = document.getElementById("vimiumHelpDialog");          this.dialogElement.getElementsByClassName("toggleAdvancedCommands")[0].addEventListener("click",             VimiumHelpDialog.toggleAdvancedCommands, false); +        this.showAdvancedCommands(this.advancedCommandsVisible); +        this.centerDialog();        },        /* @@ -143,13 +149,27 @@         */        toggleAdvancedCommands: function(event) {          event.preventDefault(); -        var advanced = VimiumHelpDialog.dialogElement.getElementsByClassName("advanced"); -        var shouldShow = (advanced[0].style.display == "" || advanced[0].style.display == "none"); +        VimiumHelpDialog.advancedCommandsVisible = !VimiumHelpDialog.advancedCommandsVisible; +        chrome.extension.sendRequest({ handler: "saveHelpDialogSettings", +            showAdvancedCommands: VimiumHelpDialog.advancedCommandsVisible }); +        VimiumHelpDialog.showAdvancedCommands(VimiumHelpDialog.advancedCommandsVisible); +        VimiumHelpDialog.centerDialog(); +      }, + +      showAdvancedCommands: function(visible) {          VimiumHelpDialog.dialogElement.getElementsByClassName("toggleAdvancedCommands")[0].innerHTML = -            shouldShow ? "Hide advanced commands" : "Show advanced commands"; +            visible ? "Hide advanced commands" : "Show advanced commands"; +        var advanced = VimiumHelpDialog.dialogElement.getElementsByClassName("advanced");          for (var i = 0; i < advanced.length; i++) -          advanced[i].style.display = (shouldShow ? "table-row" : "none"); -      } +          advanced[i].style.display = (visible ? "table-row" : "none"); +      }, + +      centerDialog: function() { +        var zoomFactor = currentZoomLevel / 100.0; +        this.dialogElement.style.top = Math.max( +            (window.innerHeight - this.dialogElement.clientHeight * zoomFactor) / 2.0, +            20) / zoomFactor + "px"; +        }      };      VimiumHelpDialog.init(); diff --git a/manifest.json b/manifest.json index 181c8739..b67e8daa 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@  {    "name": "Vimium", -  "version": "1.22", +  "version": "1.25",    "description": "The Hacker's Browser. Vimium provides keyboard shortcuts for navigation and control in the spirit of Vim.",    "icons": {  "16": "icons/icon16.png",                "48": "icons/icon48.png", diff --git a/options.html b/options.html index 1724f51b..f1194554 100644 --- a/options.html +++ b/options.html @@ -79,12 +79,12 @@    <script type="text/javascript">    $ = function(id) { return document.getElementById(id); }; -  currentlyShowingDialog = null; -    var defaultSettings = chrome.extension.getBackgroundPage().defaultSettings;    var editableFields = ["scrollStepSize", "defaultZoomLevel", "excludedUrls", "linkHintCharacters", -    "userDefinedLinkHintCss", "keyMappings", "filterLinkHints"]; +                        "userDefinedLinkHintCss", "keyMappings", "filterLinkHints"]; + +  var canBeEmptyFields = ["excludedUrls", "keyMappings", "userDefinedLinkHintCss"];    var postSaveHooks = {      keyMappings: function (value) { @@ -106,8 +106,8 @@      $("advancedOptions").addEventListener("click", openAdvancedOptions, false);      $("showCommands").addEventListener("click", function () { -      showDialog("vimiumCommandListingContainer", -        chrome.extension.getBackgroundPage().helpDialogHtml(true, true, "Command Listing")); +      showHelpDialog( +        chrome.extension.getBackgroundPage().helpDialogHtml(true, true, "Command Listing"), frameId);      }, false);    } @@ -141,12 +141,18 @@        var defaultFieldValue = (defaultSettings[fieldName] != null) ?          defaultSettings[fieldName].toString() : ""; +      // Don't save to storage if it's equal to the default        if (fieldValue == defaultFieldValue)          delete localStorage[fieldName]; -      else +      // ..or if it's empty and not a field that we allow to be empty. +      else if (!fieldValue && canBeEmptyFields.indexOf(fieldName) == -1) { +        delete localStorage[fieldName]; +        fieldValue = defaultFieldValue; +      } else          localStorage[fieldName] = fieldValue; -      field.setAttribute("savedValue", fieldValue); +      $(fieldName).value = fieldValue; +      $(fieldName).setAttribute("savedValue", fieldValue);        if (postSaveHooks[fieldName]) { postSaveHooks[fieldName](fieldValue); }      } @@ -156,9 +162,13 @@    // Restores select box state to saved value from localStorage.    function populateOptions() {      for (var i = 0; i < editableFields.length; i++) { -      var val = localStorage[editableFields[i]] || defaultSettings[editableFields[i]] || ""; -      var field = $(editableFields[i]); -      setFieldValue($(editableFields[i]), val); +      // If it's null or undefined, let's go to the default. We want to allow empty strings in certain cases. +      if (localStorage[editableFields[i]] != "" && !localStorage[editableFields[i]]) { +        var val = defaultSettings[editableFields[i]] || ""; +      } else { +	    var val = localStorage[editableFields[i]]; +      } +	  setFieldValue($(editableFields[i]), val);      }      onDataLoaded();    } @@ -187,30 +197,6 @@        elements[i].style.display = (elements[i].style.display == "table-row") ? "none" : "table-row";      event.preventDefault();    } - -  function showDialog(dialogId, dialogHtml) { -    if (currentlyShowingDialog) -      return false; - -    currentlyShowingDialog = dialogId; -    var container = document.createElement("div"); -    container.id = currentlyShowingDialog; -    container.innerHTML = dialogHtml; -    container.getElementsByClassName("closeButton")[0].addEventListener("click", hideDialog, false); -    container.getElementsByClassName("optionsPage")[0].style.display = 'none'; -    document.body.appendChild(container); -    var dialog = document.getElementById("vimiumHelpDialog"); -    dialog.style.top = Math.max((window.innerHeight - dialog.clientHeight) / 2.0, 20) + "px"; -  } - -  function hideDialog() { -    var dialog = document.getElementById(currentlyShowingDialog); -    if (dialog) -      dialog.parentNode.removeChild(dialog); - -    currentlyShowingDialog = null; -  } -    </script>    </head> diff --git a/vimiumFrontend.js b/vimiumFrontend.js index e0b6eb6a..58def011 100644 --- a/vimiumFrontend.js +++ b/vimiumFrontend.js @@ -80,7 +80,8 @@ function initializePreDomReady() {    checkIfEnabledForUrl();    var getZoomLevelPort = chrome.extension.connect({ name: "getZoomLevel" }); -  getZoomLevelPort.postMessage({ domain: window.location.host }); +  if (window.self == window.parent) +    getZoomLevelPort.postMessage({ domain: window.location.host });    chrome.extension.sendRequest({handler: "getLinkHintCss"}, function (response) {      linkHintCss = response.linkHintCss; @@ -171,8 +172,8 @@ function initializeWhenEnabled() {  /*   * The backend needs to know which frame has focus.   */ -window.addEventListener("focus", function(e){ -  chrome.extension.sendRequest({handler: "frameFocused", frameId: frameId}); +window.addEventListener("focus", function(e) { +  chrome.extension.sendRequest({ handler: "frameFocused", frameId: frameId });  });  /* @@ -203,7 +204,8 @@ function initializeOnDomReady() {  // This is a little hacky but sometimes the size wasn't available on domReady?  function registerFrameIfSizeAvailable (top) {    if (innerWidth != undefined && innerWidth != 0 && innerHeight != undefined && innerHeight != 0) -    chrome.extension.sendRequest({ handler: "registerFrame", frameId: frameId, area: innerWidth * innerHeight, top: top, total: frames.length + 1 }); +    chrome.extension.sendRequest({ handler: "registerFrame", frameId: frameId, +        area: innerWidth * innerHeight, top: top, total: frames.length + 1 });    else      setTimeout(function () { registerFrameIfSizeAvailable(top); }, 100);  } @@ -239,18 +241,23 @@ function setPageZoomLevel(zoomLevel, showUINotification) {  }  function zoomIn() { -  setPageZoomLevel(currentZoomLevel += 20, true); -  saveZoomLevel(window.location.host, currentZoomLevel); +  currentZoomLevel += 20; +  setAndSaveZoom();  }  function zoomOut() { -  setPageZoomLevel(currentZoomLevel -= 20, true); -  saveZoomLevel(window.location.host, currentZoomLevel); +  currentZoomLevel -= 20; +  setAndSaveZoom();  }  function zoomReset() { -  setPageZoomLevel(100, true); -  saveZoomLevel(window.location.host, 100); +  currentZoomLevel = 100; +  setAndSaveZoom(); +} + +function setAndSaveZoom() { +  setPageZoomLevel(currentZoomLevel, true); +  saveZoomLevel(window.location.host, currentZoomLevel);  }  function scrollToBottom() { window.scrollTo(window.pageXOffset, document.body.scrollHeight); } @@ -665,12 +672,6 @@ function showHelpDialog(html, fid) {    container.getElementsByClassName("closeButton")[0].addEventListener("click", hideHelpDialog, false);    container.getElementsByClassName("optionsPage")[0].addEventListener("click",        function() { chrome.extension.sendRequest({ handler: "openOptionsPageInNewTab" }); }, false); - -  var dialog = document.getElementById("vimiumHelpDialog"); -  dialog.style.zIndex = "99999998"; -  var zoomFactor = currentZoomLevel / 100.0; -  dialog.style.top = -      Math.max((window.innerHeight - dialog.clientHeight * zoomFactor) / 2.0, 20) / zoomFactor + "px";  }  function hideHelpDialog(clickEvent) { | 
