browser/components/places/content/history-panel.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/places/content/history-panel.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,91 @@
     1.4 +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +var gHistoryTree;
    1.10 +var gSearchBox;
    1.11 +var gHistoryGrouping = "";
    1.12 +var gSearching = false;
    1.13 +
    1.14 +function HistorySidebarInit()
    1.15 +{
    1.16 +  gHistoryTree = document.getElementById("historyTree");
    1.17 +  gSearchBox = document.getElementById("search-box");
    1.18 +
    1.19 +  gHistoryGrouping = document.getElementById("viewButton").
    1.20 +                              getAttribute("selectedsort");
    1.21 +
    1.22 +  if (gHistoryGrouping == "site")
    1.23 +    document.getElementById("bysite").setAttribute("checked", "true");
    1.24 +  else if (gHistoryGrouping == "visited") 
    1.25 +    document.getElementById("byvisited").setAttribute("checked", "true");
    1.26 +  else if (gHistoryGrouping == "lastvisited")
    1.27 +    document.getElementById("bylastvisited").setAttribute("checked", "true");
    1.28 +  else if (gHistoryGrouping == "dayandsite")
    1.29 +    document.getElementById("bydayandsite").setAttribute("checked", "true");
    1.30 +  else
    1.31 +    document.getElementById("byday").setAttribute("checked", "true");
    1.32 +  
    1.33 +  searchHistory("");
    1.34 +}
    1.35 +
    1.36 +function GroupBy(groupingType)
    1.37 +{
    1.38 +  gHistoryGrouping = groupingType;
    1.39 +  searchHistory(gSearchBox.value);
    1.40 +}
    1.41 +
    1.42 +function searchHistory(aInput)
    1.43 +{
    1.44 +  var query = PlacesUtils.history.getNewQuery();
    1.45 +  var options = PlacesUtils.history.getNewQueryOptions();
    1.46 +
    1.47 +  const NHQO = Ci.nsINavHistoryQueryOptions;
    1.48 +  var sortingMode;
    1.49 +  var resultType;
    1.50 +
    1.51 +  switch (gHistoryGrouping) {
    1.52 +    case "visited":
    1.53 +      resultType = NHQO.RESULTS_AS_URI;
    1.54 +      sortingMode = NHQO.SORT_BY_VISITCOUNT_DESCENDING;
    1.55 +      break;
    1.56 +    case "lastvisited":
    1.57 +      resultType = NHQO.RESULTS_AS_URI;
    1.58 +      sortingMode = NHQO.SORT_BY_DATE_DESCENDING;
    1.59 +      break;
    1.60 +    case "dayandsite":
    1.61 +      resultType = NHQO.RESULTS_AS_DATE_SITE_QUERY;
    1.62 +      break;
    1.63 +    case "site":
    1.64 +      resultType = NHQO.RESULTS_AS_SITE_QUERY;
    1.65 +      sortingMode = NHQO.SORT_BY_TITLE_ASCENDING;
    1.66 +      break;
    1.67 +    case "day":
    1.68 +    default:
    1.69 +      resultType = NHQO.RESULTS_AS_DATE_QUERY;
    1.70 +      break;
    1.71 +  }
    1.72 +
    1.73 +  if (aInput) {
    1.74 +    query.searchTerms = aInput;
    1.75 +    if (gHistoryGrouping != "visited" && gHistoryGrouping != "lastvisited") {
    1.76 +      sortingMode = NHQO.SORT_BY_FRECENCY_DESCENDING;
    1.77 +      resultType = NHQO.RESULTS_AS_URI;
    1.78 +    }
    1.79 +  }
    1.80 +
    1.81 +  options.sortingMode = sortingMode;
    1.82 +  options.resultType = resultType;
    1.83 +  options.includeHidden = !!aInput;
    1.84 +
    1.85 +  // call load() on the tree manually
    1.86 +  // instead of setting the place attribute in history-panel.xul
    1.87 +  // otherwise, we will end up calling load() twice
    1.88 +  gHistoryTree.load([query], options);
    1.89 +}
    1.90 +
    1.91 +window.addEventListener("SidebarFocused",
    1.92 +                        function()
    1.93 +                          gSearchBox.focus(),
    1.94 +                        false);

mercurial