Tab-Search-and-Manage/src/scripts/eventListeners.js

40 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-05-13 22:27:16 +00:00
// Set click events for tab blocks
2018-04-20 06:06:32 +00:00
document.addEventListener("click", (e) => {
2018-05-06 01:02:50 +00:00
var target = e.target;
var targetID = target.id;
2018-04-20 06:06:32 +00:00
var parentElm = target.parentElement;
2018-05-06 01:02:50 +00:00
var id = 0;
2018-04-20 06:06:32 +00:00
if (targetID == "closeBttn") {
2018-05-06 01:02:50 +00:00
id = parseInt(parentElm.getAttribute("tabID"));
2018-04-20 06:06:32 +00:00
2018-05-06 01:02:50 +00:00
browser.tabs.remove(id);
2018-04-20 06:06:32 +00:00
parentElm.parentElement.removeChild(parentElm);
} else if (targetID == "iconElm" || targetID == "faveIcon") {
2018-05-06 01:02:50 +00:00
if (targetID == "faveIcon")
target = parentElm.parentElement;
2018-04-20 06:06:32 +00:00
2018-05-13 22:27:16 +00:00
id = parseInt(target.getAttribute("tabID"));
browser.tabs.update(id, { active: true });
2018-05-06 01:02:50 +00:00
oldElm.setAttribute("class", "block");
oldElm = target;
target.setAttribute("class", "block block-focused");
} 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);
2018-05-13 22:27:16 +00:00
} else if (targetID == "newTab") {
createTab();
2018-04-20 06:06:32 +00:00
}
});
2018-05-06 01:02:50 +00:00
document.getElementById("searchBar").onkeypress = function () {
2018-04-20 06:06:32 +00:00
searchTabs();
}