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

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:92293019feba
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
6 var gHistoryTree;
7 var gSearchBox;
8 var gHistoryGrouping = "";
9 var gSearching = false;
10
11 function HistorySidebarInit()
12 {
13 gHistoryTree = document.getElementById("historyTree");
14 gSearchBox = document.getElementById("search-box");
15
16 gHistoryGrouping = document.getElementById("viewButton").
17 getAttribute("selectedsort");
18
19 if (gHistoryGrouping == "site")
20 document.getElementById("bysite").setAttribute("checked", "true");
21 else if (gHistoryGrouping == "visited")
22 document.getElementById("byvisited").setAttribute("checked", "true");
23 else if (gHistoryGrouping == "lastvisited")
24 document.getElementById("bylastvisited").setAttribute("checked", "true");
25 else if (gHistoryGrouping == "dayandsite")
26 document.getElementById("bydayandsite").setAttribute("checked", "true");
27 else
28 document.getElementById("byday").setAttribute("checked", "true");
29
30 searchHistory("");
31 }
32
33 function GroupBy(groupingType)
34 {
35 gHistoryGrouping = groupingType;
36 searchHistory(gSearchBox.value);
37 }
38
39 function searchHistory(aInput)
40 {
41 var query = PlacesUtils.history.getNewQuery();
42 var options = PlacesUtils.history.getNewQueryOptions();
43
44 const NHQO = Ci.nsINavHistoryQueryOptions;
45 var sortingMode;
46 var resultType;
47
48 switch (gHistoryGrouping) {
49 case "visited":
50 resultType = NHQO.RESULTS_AS_URI;
51 sortingMode = NHQO.SORT_BY_VISITCOUNT_DESCENDING;
52 break;
53 case "lastvisited":
54 resultType = NHQO.RESULTS_AS_URI;
55 sortingMode = NHQO.SORT_BY_DATE_DESCENDING;
56 break;
57 case "dayandsite":
58 resultType = NHQO.RESULTS_AS_DATE_SITE_QUERY;
59 break;
60 case "site":
61 resultType = NHQO.RESULTS_AS_SITE_QUERY;
62 sortingMode = NHQO.SORT_BY_TITLE_ASCENDING;
63 break;
64 case "day":
65 default:
66 resultType = NHQO.RESULTS_AS_DATE_QUERY;
67 break;
68 }
69
70 if (aInput) {
71 query.searchTerms = aInput;
72 if (gHistoryGrouping != "visited" && gHistoryGrouping != "lastvisited") {
73 sortingMode = NHQO.SORT_BY_FRECENCY_DESCENDING;
74 resultType = NHQO.RESULTS_AS_URI;
75 }
76 }
77
78 options.sortingMode = sortingMode;
79 options.resultType = resultType;
80 options.includeHidden = !!aInput;
81
82 // call load() on the tree manually
83 // instead of setting the place attribute in history-panel.xul
84 // otherwise, we will end up calling load() twice
85 gHistoryTree.load([query], options);
86 }
87
88 window.addEventListener("SidebarFocused",
89 function()
90 gSearchBox.focus(),
91 false);

mercurial