bookmarksSidebar.js (3471B)
1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ 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 /* Shared Places Import - change other consumers if you change this: */ 7 var { XPCOMUtils } = ChromeUtils.importESModule( 8 "resource://gre/modules/XPCOMUtils.sys.mjs" 9 ); 10 11 ChromeUtils.defineESModuleGetters(this, { 12 PlacesTransactions: "resource://gre/modules/PlacesTransactions.sys.mjs", 13 PlacesUIUtils: "moz-src:///browser/components/places/PlacesUIUtils.sys.mjs", 14 PlacesUtils: "resource://gre/modules/PlacesUtils.sys.mjs", 15 PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.sys.mjs", 16 }); 17 18 XPCOMUtils.defineLazyScriptGetter( 19 this, 20 "PlacesTreeView", 21 "chrome://browser/content/places/treeView.js" 22 ); 23 XPCOMUtils.defineLazyScriptGetter( 24 this, 25 ["PlacesInsertionPoint", "PlacesController", "PlacesControllerDragHelper"], 26 "chrome://browser/content/places/controller.js" 27 ); 28 /* End Shared Places Import */ 29 var gCumulativeSearches = 0; 30 31 window.addEventListener("load", () => { 32 let uidensity = window.top.document.documentElement.getAttribute("uidensity"); 33 if (uidensity) { 34 document.documentElement.setAttribute("uidensity", uidensity); 35 } 36 37 let view = document.getElementById("bookmarks-view"); 38 view.place = 39 "place:type=" + Ci.nsINavHistoryQueryOptions.RESULTS_AS_ROOTS_QUERY; 40 view.addEventListener("keypress", event => 41 PlacesUIUtils.onSidebarTreeKeyPress(event) 42 ); 43 view.addEventListener("click", event => 44 PlacesUIUtils.onSidebarTreeClick(event) 45 ); 46 view.addEventListener("mousemove", event => 47 PlacesUIUtils.onSidebarTreeMouseMove(event) 48 ); 49 view.addEventListener("mouseout", () => 50 PlacesUIUtils.setMouseoverURL("", window) 51 ); 52 53 document 54 .getElementById("search-box") 55 .addEventListener("MozInputSearch:search", searchBookmarks); 56 57 let bhTooltip = document.getElementById("bhTooltip"); 58 bhTooltip.addEventListener("popupshowing", event => { 59 window.top.BookmarksEventHandler.fillInBHTooltip(bhTooltip, event); 60 }); 61 bhTooltip.addEventListener("popuphiding", () => 62 bhTooltip.removeAttribute("position") 63 ); 64 65 document 66 .getElementById("sidebar-panel-close") 67 .addEventListener("click", closeSidebarPanel); 68 }); 69 70 function searchBookmarks(event) { 71 let { value } = event.currentTarget; 72 73 var tree = document.getElementById("bookmarks-view"); 74 if (!value) { 75 // eslint-disable-next-line no-self-assign 76 tree.place = tree.place; 77 } else { 78 Glean.sidebar.search.bookmarks.add(1); 79 gCumulativeSearches++; 80 tree.applyFilter(value, PlacesUtils.bookmarks.userContentRoots); 81 } 82 } 83 84 function updateTelemetry(urlsOpened = []) { 85 Glean.bookmarksSidebar.cumulativeSearches.accumulateSingleSample( 86 gCumulativeSearches 87 ); 88 clearCumulativeCounter(); 89 90 Glean.sidebar.link.bookmarks.add(urlsOpened.length); 91 } 92 93 function clearCumulativeCounter() { 94 gCumulativeSearches = 0; 95 } 96 97 window.addEventListener("unload", () => { 98 clearCumulativeCounter(); 99 PlacesUIUtils.setMouseoverURL("", window); 100 }); 101 102 function closeSidebarPanel(e) { 103 e.preventDefault(); 104 let view = e.target.getAttribute("view"); 105 window.browsingContext.embedderWindowGlobal.browsingContext.window.SidebarController.toggle( 106 view 107 ); 108 } 109 110 window.addEventListener("SidebarFocused", () => 111 document.getElementById("search-box").focus() 112 );