Cleaned up code logic and wording.

This commit is contained in:
Maxim Stewart 2018-10-13 17:08:32 -05:00
parent 4f5173f7f9
commit 7feec057a5
2 changed files with 67 additions and 51 deletions

View File

@ -1,3 +1,7 @@
document.getElementById("searchBar").onkeypress = function () {
searchTabs();
}
// Set click events for tab blocks // Set click events for tab blocks
document.addEventListener("click", (e) => { document.addEventListener("click", (e) => {
var target = (!e.target.className.includes("pTagTitleText")) ? e.target : e.target.parentElement; var target = (!e.target.className.includes("pTagTitleText")) ? e.target : e.target.parentElement;
@ -6,6 +10,31 @@ document.addEventListener("click", (e) => {
var id = 0; var id = 0;
if (targetID == "closeBttn") { if (targetID == "closeBttn") {
closeBttnAction(target, targetID, parentElm, id);
} else if (targetID == "iconElm") {
setNewTabAction(target, targetID, parentElm, id);
} else if (targetID == "goTop") {
window.scrollTo(0,0);
} else if (targetID == "goBottom") {
window.scrollTo(0, document.body.scrollHeight);
} else if (targetID == "goToTab") {
// Go to selected and 100px up
oldElm.scrollIntoView();
window.scrollBy(0, -100);
} else if (targetID == "newTab") {
createTab();
} else if (targetID == "hideTgglBttn") {
hideSelectedTabAction(target, targetID, parentElm, id);
} else if (targetID == "hideAllBttn") {
showHideTabsAction(0)
} else if (targetID == "showAllBttn") {
showHideTabsAction(1);
} else if (targetID == "searchMode") {
setSearchModeAction(target, targetID, parentElm, id);
}
});
function closeBttnAction(var target, var targetID, var parentElm, var id) {
if (parentElm == oldElm) { if (parentElm == oldElm) {
var index = Array.from(parentElm.parentElement.children).indexOf(parentElm); var index = Array.from(parentElm.parentElement.children).indexOf(parentElm);
(index - 1 < 0) ? index++ : index-- ; // Check what index to chose (index - 1 < 0) ? index++ : index-- ; // Check what index to chose
@ -20,7 +49,9 @@ document.addEventListener("click", (e) => {
browser.tabs.remove(id); browser.tabs.remove(id);
parentElm.parentElement.removeChild(parentElm); parentElm.parentElement.removeChild(parentElm);
} else if (targetID == "iconElm") { }
function setNewTabAction(var target, var targetID, var parentElm, var id) {
id = parseInt(target.getAttribute("tabID")); id = parseInt(target.getAttribute("tabID"));
tabsAction.get(id).then((tab) => { tabsAction.get(id).then((tab) => {
browser.windows.update(tab.windowId, {focused: true}); browser.windows.update(tab.windowId, {focused: true});
@ -28,17 +59,9 @@ document.addEventListener("click", (e) => {
},id); },id);
setOldElm(target); setOldElm(target);
} else if (targetID == "goTop") { }
window.scrollTo(0,0);
} else if (targetID == "goBottom") { function hideSelectedTabAction(var target, var targetID, var parentElm, var id) {
window.scrollTo(0, document.body.scrollHeight);
} else if (targetID == "goToTab") {
// Go to selected and 100px up
oldElm.scrollIntoView();
window.scrollBy(0, -100);
} else if (targetID == "newTab") {
createTab();
} else if (targetID == "hideTgglBttn") {
id = parseInt(parentElm.getAttribute("tabID")); id = parseInt(parentElm.getAttribute("tabID"));
if (id != oldElm.getAttribute("tabID")) { if (id != oldElm.getAttribute("tabID")) {
@ -52,11 +75,9 @@ document.addEventListener("click", (e) => {
hideSelectedTab(id); hideSelectedTab(id);
} }
} }
} else if (targetID == "hideAllBttn") { }
doAllTabs(0)
} else if (targetID == "showAllBttn") { function setSearchModeAction(var target, var targetID, var parentElm, var id) {
doAllTabs(1);
} else if (targetID == "searchMode") {
var currentMode = target.getAttribute("searchwindowsmode"); var currentMode = target.getAttribute("searchwindowsmode");
if (currentMode == "true") { if (currentMode == "true") {
// In generateview // In generateview
@ -65,8 +86,7 @@ document.addEventListener("click", (e) => {
setSearchMode(target, "all windows", "windows", true); setSearchMode(target, "all windows", "windows", true);
} }
clearNodes(listZone); clearNodes(listZone);
} }
});
function setOldElm(target) { function setOldElm(target) {
target.querySelectorAll(".hiderImg")[0].src = "../icons/eyeOpen.png"; target.querySelectorAll(".hiderImg")[0].src = "../icons/eyeOpen.png";
@ -74,7 +94,3 @@ function setOldElm(target) {
oldElm = target; oldElm = target;
target.setAttribute("class", "block block-focused"); target.setAttribute("class", "block block-focused");
} }
document.getElementById("searchBar").onkeypress = function () {
searchTabs();
}

View File

@ -24,7 +24,7 @@ function errMsg(ev) {
} }
} }
function doAllTabs(doType) { function showHideTabsAction(doType) {
// 0 == hide and 1 == unhide // 0 == hide and 1 == unhide
tabsAction.query({currentWindow: true}).then((tabs) => { tabsAction.query({currentWindow: true}).then((tabs) => {
var tabCollectionIDs = []; var tabCollectionIDs = [];