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,75 +10,87 @@ document.addEventListener("click", (e) => {
var id = 0;
if (targetID == "closeBttn") {
if (parentElm == oldElm) {
var index = Array.from(parentElm.parentElement.children).indexOf(parentElm);
(index - 1 < 0) ? index++ : index-- ; // Check what index to chose
var newElm = parentElm.parentElement.children[index];
id = parseInt(newElm.getAttribute("tabID"));
browser.tabs.update(id, { active: true });
setOldElm(newElm);
}
id = parseInt(parentElm.getAttribute("tabID"));
browser.tabs.remove(id);
parentElm.parentElement.removeChild(parentElm);
closeBttnAction(target, targetID, parentElm, id);
} else if (targetID == "iconElm") {
id = parseInt(target.getAttribute("tabID"));
tabsAction.get(id).then((tab) => {
browser.windows.update(tab.windowId, {focused: true});
browser.tabs.update(id, { active: true });
},id);
setOldElm(target);
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);
oldElm.scrollIntoView();
window.scrollBy(0, -100);
} else if (targetID == "newTab") {
createTab();
} else if (targetID == "hideTgglBttn") {
id = parseInt(parentElm.getAttribute("tabID"));
if (id != oldElm.getAttribute("tabID")) {
if (target.src.includes("eyeClosed.png")) {
parentElm.setAttribute("class", "block");
target.src = "../icons/eyeOpen.png"
unhideSelectedTab(id);
} else {
parentElm.setAttribute("class", "block hiddenBGColor");
target.src = "../icons/eyeClosed.png"
hideSelectedTab(id);
}
}
hideSelectedTabAction(target, targetID, parentElm, id);
} else if (targetID == "hideAllBttn") {
doAllTabs(0)
showHideTabsAction(0)
} else if (targetID == "showAllBttn") {
doAllTabs(1);
showHideTabsAction(1);
} else if (targetID == "searchMode") {
var currentMode = target.getAttribute("searchwindowsmode");
if (currentMode == "true") {
// In generateview
setSearchMode(target, "curent window", "window", false);
} else {
setSearchMode(target, "all windows", "windows", true);
}
clearNodes(listZone);
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
var newElm = parentElm.parentElement.children[index];
id = parseInt(newElm.getAttribute("tabID"));
browser.tabs.update(id, { active: true });
setOldElm(newElm);
}
id = parseInt(parentElm.getAttribute("tabID"));
browser.tabs.remove(id);
parentElm.parentElement.removeChild(parentElm);
}
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});
browser.tabs.update(id, { active: true });
},id);
setOldElm(target);
}
function hideSelectedTabAction(var target, var targetID, var parentElm, var id) {
id = parseInt(parentElm.getAttribute("tabID"));
if (id != oldElm.getAttribute("tabID")) {
if (target.src.includes("eyeClosed.png")) {
parentElm.setAttribute("class", "block");
target.src = "../icons/eyeOpen.png"
unhideSelectedTab(id);
} else {
parentElm.setAttribute("class", "block hiddenBGColor");
target.src = "../icons/eyeClosed.png"
hideSelectedTab(id);
}
}
}
function setSearchModeAction(var target, var targetID, var parentElm, var id) {
var currentMode = target.getAttribute("searchwindowsmode");
if (currentMode == "true") {
// In generateview
setSearchMode(target, "curent window", "window", false);
} else {
setSearchMode(target, "all windows", "windows", true);
}
clearNodes(listZone);
}
function setOldElm(target) {
target.querySelectorAll(".hiderImg")[0].src = "../icons/eyeOpen.png";
oldElm.setAttribute("class", "block");
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 = [];