history-panel.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. var gHistoryTree;
  6. var gSearchBox;
  7. var gHistoryGrouping = "";
  8. var gSearching = false;
  9. function HistorySidebarInit()
  10. {
  11. gHistoryTree = document.getElementById("historyTree");
  12. gSearchBox = document.getElementById("search-box");
  13. gHistoryGrouping = document.getElementById("viewButton").
  14. getAttribute("selectedsort");
  15. if (gHistoryGrouping == "site")
  16. document.getElementById("bysite").setAttribute("checked", "true");
  17. else if (gHistoryGrouping == "visited")
  18. document.getElementById("byvisited").setAttribute("checked", "true");
  19. else if (gHistoryGrouping == "lastvisited")
  20. document.getElementById("bylastvisited").setAttribute("checked", "true");
  21. else if (gHistoryGrouping == "dayandsite")
  22. document.getElementById("bydayandsite").setAttribute("checked", "true");
  23. else
  24. document.getElementById("byday").setAttribute("checked", "true");
  25. searchHistory("");
  26. }
  27. function GroupBy(groupingType)
  28. {
  29. gHistoryGrouping = groupingType;
  30. searchHistory(gSearchBox.value);
  31. }
  32. function searchHistory(aInput)
  33. {
  34. var query = PlacesUtils.history.getNewQuery();
  35. var options = PlacesUtils.history.getNewQueryOptions();
  36. const NHQO = Ci.nsINavHistoryQueryOptions;
  37. var sortingMode;
  38. var resultType;
  39. switch (gHistoryGrouping) {
  40. case "visited":
  41. resultType = NHQO.RESULTS_AS_URI;
  42. sortingMode = NHQO.SORT_BY_VISITCOUNT_DESCENDING;
  43. break;
  44. case "lastvisited":
  45. resultType = NHQO.RESULTS_AS_URI;
  46. sortingMode = NHQO.SORT_BY_DATE_DESCENDING;
  47. break;
  48. case "dayandsite":
  49. resultType = NHQO.RESULTS_AS_DATE_SITE_QUERY;
  50. break;
  51. case "site":
  52. resultType = NHQO.RESULTS_AS_SITE_QUERY;
  53. sortingMode = NHQO.SORT_BY_TITLE_ASCENDING;
  54. break;
  55. case "day":
  56. default:
  57. resultType = NHQO.RESULTS_AS_DATE_QUERY;
  58. break;
  59. }
  60. if (aInput) {
  61. query.searchTerms = aInput;
  62. if (gHistoryGrouping != "visited" && gHistoryGrouping != "lastvisited") {
  63. sortingMode = NHQO.SORT_BY_FRECENCY_DESCENDING;
  64. resultType = NHQO.RESULTS_AS_URI;
  65. }
  66. }
  67. options.sortingMode = sortingMode;
  68. options.resultType = resultType;
  69. options.includeHidden = !!aInput;
  70. // call load() on the tree manually
  71. // instead of setting the place attribute in history-panel.xul
  72. // otherwise, we will end up calling load() twice
  73. gHistoryTree.load([query], options);
  74. }
  75. window.addEventListener("SidebarFocused",
  76. function()
  77. gSearchBox.focus(),
  78. false);