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
document.addEventListener("click", (e) => {
var target = (!e.target.className.includes("pTagTitleText")) ? e.target : e.target.parentElement;
@ -6,6 +10,31 @@ document.addEventListener("click", (e) => {
var id = 0;
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) {
var index = Array.from(parentElm.parentElement.children).indexOf(parentElm);
(index - 1 < 0) ? index++ : index-- ; // Check what index to chose
@ -20,7 +49,9 @@ document.addEventListener("click", (e) => {
browser.tabs.remove(id);
parentElm.parentElement.removeChild(parentElm);
} else if (targetID == "iconElm") {
}
function setNewTabAction(var target, var targetID, var parentElm, var id) {
id = parseInt(target.getAttribute("tabID"));
tabsAction.get(id).then((tab) => {
browser.windows.update(tab.windowId, {focused: true});
@ -28,17 +59,9 @@ document.addEventListener("click", (e) => {
},id);
setOldElm(target);
} 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") {
}
function hideSelectedTabAction(var target, var targetID, var parentElm, var id) {
id = parseInt(parentElm.getAttribute("tabID"));
if (id != oldElm.getAttribute("tabID")) {
@ -52,11 +75,9 @@ document.addEventListener("click", (e) => {
hideSelectedTab(id);
}
}
} else if (targetID == "hideAllBttn") {
doAllTabs(0)
} else if (targetID == "showAllBttn") {
doAllTabs(1);
} else if (targetID == "searchMode") {
}
function setSearchModeAction(var target, var targetID, var parentElm, var id) {
var currentMode = target.getAttribute("searchwindowsmode");
if (currentMode == "true") {
// In generateview
@ -65,8 +86,7 @@ document.addEventListener("click", (e) => {
setSearchMode(target, "all windows", "windows", true);
}
clearNodes(listZone);
}
});
}
function setOldElm(target) {
target.querySelectorAll(".hiderImg")[0].src = "../icons/eyeOpen.png";
@ -74,7 +94,3 @@ function setOldElm(target) {
oldElm = target;
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
tabsAction.query({currentWindow: true}).then((tabs) => {
var tabCollectionIDs = [];