tabs.js (3079B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ 4 5 /** 6 * Finds the hidden tabs by comparing the tabs' top offset. 7 * hidden tabs will have a great top offset. 8 * 9 * @param tabs Array<reducer's Source object> 10 * @param sourceTabEls HTMLCollection 11 * 12 * @returns Array 13 */ 14 15 export function getHiddenTabsSources(openedSources, sourceTabEls) { 16 sourceTabEls = Array.from(sourceTabEls); 17 function getTopOffset() { 18 const topOffsets = sourceTabEls.map(t => t.getBoundingClientRect().top); 19 return Math.min(...topOffsets); 20 } 21 const tabTopOffset = getTopOffset(); 22 23 function hasTopOffset(el) { 24 // adding 10px helps account for cases where the tab might be offset by 25 // styling such as selected tabs which don't have a border. 26 return el.getBoundingClientRect().top > tabTopOffset + 10; 27 } 28 29 const hiddenSources = []; 30 for (let i = 0; i < openedSources.length; i++) { 31 const element = sourceTabEls[i]; 32 if (element && hasTopOffset(element)) { 33 hiddenSources.push(openedSources[i]); 34 } 35 } 36 return hiddenSources; 37 } 38 39 export function getTabMenuItems() { 40 return { 41 closeTab: { 42 id: "node-menu-close-tab", 43 label: L10N.getStr("sourceTabs.closeTab"), 44 accesskey: L10N.getStr("sourceTabs.closeTab.accesskey"), 45 disabled: false, 46 }, 47 closeOtherTabs: { 48 id: "node-menu-close-other-tabs", 49 label: L10N.getStr("sourceTabs.closeOtherTabs"), 50 accesskey: L10N.getStr("sourceTabs.closeOtherTabs.accesskey"), 51 disabled: false, 52 }, 53 closeTabsToEnd: { 54 id: "node-menu-close-tabs-to-end", 55 label: L10N.getStr("sourceTabs.closeTabsToEnd"), 56 accesskey: L10N.getStr("sourceTabs.closeTabsToEnd.accesskey"), 57 disabled: false, 58 }, 59 closeAllTabs: { 60 id: "node-menu-close-all-tabs", 61 label: L10N.getStr("sourceTabs.closeAllTabs"), 62 accesskey: L10N.getStr("sourceTabs.closeAllTabs.accesskey"), 63 disabled: false, 64 }, 65 showSource: { 66 id: "node-menu-show-source", 67 label: L10N.getStr("sourceTabs.revealInTree"), 68 accesskey: L10N.getStr("sourceTabs.revealInTree.accesskey"), 69 disabled: false, 70 }, 71 copySource: { 72 id: "node-menu-copy-source", 73 label: L10N.getStr("copySource.label"), 74 accesskey: L10N.getStr("copySource.accesskey"), 75 disabled: false, 76 }, 77 copySourceUri2: { 78 id: "node-menu-copy-source-url", 79 label: L10N.getStr("copySourceUri2"), 80 accesskey: L10N.getStr("copySourceUri2.accesskey"), 81 disabled: false, 82 }, 83 toggleBlackBox: { 84 id: "node-menu-blackbox", 85 label: L10N.getStr("ignoreContextItem.ignore"), 86 accesskey: L10N.getStr("ignoreContextItem.ignore.accesskey"), 87 disabled: false, 88 }, 89 prettyPrint: { 90 id: "node-menu-pretty-print", 91 label: L10N.getStr("sourceTabs.prettyPrint"), 92 accesskey: L10N.getStr("sourceTabs.prettyPrint.accesskey"), 93 disabled: false, 94 }, 95 }; 96 }