Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Commit

Permalink
Add a Restore Session button
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher De Cairos committed Aug 3, 2017
1 parent 620054b commit ded55bb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
6 changes: 5 additions & 1 deletion sidebar/css/panel.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ table.table td a {
text-overflow: ellipsis;
white-space: nowrap;
display: block;
}
}

.panel-heading button {
margin-left: 1.5em;
}
41 changes: 30 additions & 11 deletions sidebar/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ class TabSweeperSideBar {
return `${day}-${month}-${year} ${hours}:${minutes}`;
}

/*
* Restore a tabs in a session
*/
restoreTab(tab) {
tabs.create({
url: tab.url
});
}

/*
* Restore all tabs in a session
*/
restoreSession(session) {
session.tabs.forEach(tab => this.restoreTab(tab));
}

/*
* Output a single session's URLs
*/
Expand All @@ -127,20 +143,28 @@ class TabSweeperSideBar {
smart_count: session.tabs.length
});

// set up panel
let urlPanel = document.createElement(this.tags.DIV);
let panelHeading = document.createElement(this.tags.DIV);
let urlTable = document.createElement(this.tags.TABLE);
let restoreAllBtn = document.createElement(this.tags.BUTTON);

// panel classes
urlPanel.classList.add("panel", "panel-default");

// set up panel heading
let panelHeading = document.createElement(this.tags.DIV);
// heading classes and text
panelHeading.classList.add("panel-heading");
panelHeading.textContent = `${pluralized} - ${created}`;

// set up table element
let urlTable = document.createElement(this.tags.TABLE);
// table classes
urlTable.classList.add("table", "table-responsive");

// button classes
restoreAllBtn.classList.add("btn", "btn-primary", "btn-xs");
restoreAllBtn.textContent = "Restore Session";
restoreAllBtn.addEventListener("click", () => this.restoreSession(session));

// append panel heading and table to the panel
panelHeading.appendChild(restoreAllBtn);
urlPanel.appendChild(panelHeading);
urlPanel.appendChild(urlTable);

Expand All @@ -152,7 +176,6 @@ class TabSweeperSideBar {
let anchor = document.createElement(this.tags.A)

closeBtn.classList.add("close");
closeBtn.setAttribute("type", "button");
closeBtn.setAttribute("aria-label", "Close");

closeSpan.innerHTML = "×";
Expand All @@ -165,11 +188,7 @@ class TabSweeperSideBar {

anchor.setAttribute("href", "#");
anchor.textContent = tab.url;
anchor.addEventListener("click", () => {
tabs.create({
url: tab.url
});
});
anchor.addEventListener("click", () => this.restoreTab(tab));

urlTableData.appendChild(anchor)
urlTableRow.appendChild(urlTableData)
Expand Down

0 comments on commit ded55bb

Please sign in to comment.