michael@0: /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: var gHistoryTree; michael@0: var gSearchBox; michael@0: var gHistoryGrouping = ""; michael@0: var gSearching = false; michael@0: michael@0: function HistorySidebarInit() michael@0: { michael@0: gHistoryTree = document.getElementById("historyTree"); michael@0: gSearchBox = document.getElementById("search-box"); michael@0: michael@0: gHistoryGrouping = document.getElementById("viewButton"). michael@0: getAttribute("selectedsort"); michael@0: michael@0: if (gHistoryGrouping == "site") michael@0: document.getElementById("bysite").setAttribute("checked", "true"); michael@0: else if (gHistoryGrouping == "visited") michael@0: document.getElementById("byvisited").setAttribute("checked", "true"); michael@0: else if (gHistoryGrouping == "lastvisited") michael@0: document.getElementById("bylastvisited").setAttribute("checked", "true"); michael@0: else if (gHistoryGrouping == "dayandsite") michael@0: document.getElementById("bydayandsite").setAttribute("checked", "true"); michael@0: else michael@0: document.getElementById("byday").setAttribute("checked", "true"); michael@0: michael@0: searchHistory(""); michael@0: } michael@0: michael@0: function GroupBy(groupingType) michael@0: { michael@0: gHistoryGrouping = groupingType; michael@0: searchHistory(gSearchBox.value); michael@0: } michael@0: michael@0: function searchHistory(aInput) michael@0: { michael@0: var query = PlacesUtils.history.getNewQuery(); michael@0: var options = PlacesUtils.history.getNewQueryOptions(); michael@0: michael@0: const NHQO = Ci.nsINavHistoryQueryOptions; michael@0: var sortingMode; michael@0: var resultType; michael@0: michael@0: switch (gHistoryGrouping) { michael@0: case "visited": michael@0: resultType = NHQO.RESULTS_AS_URI; michael@0: sortingMode = NHQO.SORT_BY_VISITCOUNT_DESCENDING; michael@0: break; michael@0: case "lastvisited": michael@0: resultType = NHQO.RESULTS_AS_URI; michael@0: sortingMode = NHQO.SORT_BY_DATE_DESCENDING; michael@0: break; michael@0: case "dayandsite": michael@0: resultType = NHQO.RESULTS_AS_DATE_SITE_QUERY; michael@0: break; michael@0: case "site": michael@0: resultType = NHQO.RESULTS_AS_SITE_QUERY; michael@0: sortingMode = NHQO.SORT_BY_TITLE_ASCENDING; michael@0: break; michael@0: case "day": michael@0: default: michael@0: resultType = NHQO.RESULTS_AS_DATE_QUERY; michael@0: break; michael@0: } michael@0: michael@0: if (aInput) { michael@0: query.searchTerms = aInput; michael@0: if (gHistoryGrouping != "visited" && gHistoryGrouping != "lastvisited") { michael@0: sortingMode = NHQO.SORT_BY_FRECENCY_DESCENDING; michael@0: resultType = NHQO.RESULTS_AS_URI; michael@0: } michael@0: } michael@0: michael@0: options.sortingMode = sortingMode; michael@0: options.resultType = resultType; michael@0: options.includeHidden = !!aInput; michael@0: michael@0: // call load() on the tree manually michael@0: // instead of setting the place attribute in history-panel.xul michael@0: // otherwise, we will end up calling load() twice michael@0: gHistoryTree.load([query], options); michael@0: } michael@0: michael@0: window.addEventListener("SidebarFocused", michael@0: function() michael@0: gSearchBox.focus(), michael@0: false);