Skip to content

Commit

Permalink
WebUI: Use classlist.toggle() whenever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
skomerko committed Dec 3, 2024
1 parent 8a494fb commit 00d0725
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 33 deletions.
5 changes: 1 addition & 4 deletions src/webui/www/private/scripts/contextmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,7 @@ window.qBittorrent.ContextMenu ??= (() => {
const show_seq_dl = (all_are_seq_dl || !there_are_seq_dl);
const show_f_l_piece_prio = (all_are_f_l_piece_prio || !there_are_f_l_piece_prio);

if (!show_seq_dl && show_f_l_piece_prio)
this.menu.getElement("a[href$=firstLastPiecePrio]").parentNode.classList.add("separator");
else
this.menu.getElement("a[href$=firstLastPiecePrio]").parentNode.classList.remove("separator");
this.menu.getElement("a[href$=firstLastPiecePrio]").parentNode.classList.toggle("separator", !show_seq_dl && show_f_l_piece_prio);

if (show_seq_dl)
this.showItem("sequentialDownload");
Expand Down
27 changes: 6 additions & 21 deletions src/webui/www/private/scripts/dynamicTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,7 @@ window.qBittorrent.DynamicTable ??= (() => {
th.setAttribute("style", "width: " + this.columns[i].width + "px;" + this.columns[i].style);
th.columnName = this.columns[i].name;
th.classList.add("column_" + th.columnName);
if ((this.columns[i].visible === "0") || this.columns[i].force_hide)
th.classList.add("invisible");
else
th.classList.remove("invisible");
th.classList.toggle("invisible", (this.columns[i].visible === "0") || this.columns[i].force_hide);
}
},

Expand Down Expand Up @@ -676,10 +673,7 @@ window.qBittorrent.DynamicTable ??= (() => {
const colElem = getCol(this.dynamicTableFixedHeaderDivId, newColumn);
if (colElem !== null) {
colElem.classList.add("sorted");
if (isReverse)
colElem.classList.add("reverse");
else
colElem.classList.remove("reverse");
colElem.classList.toggle("reverse", isReverse);
}
const oldColElem = getCol(this.dynamicTableFixedHeaderDivId, oldColumn);
if (oldColElem !== null) {
Expand Down Expand Up @@ -711,8 +705,7 @@ window.qBittorrent.DynamicTable ??= (() => {
for (let i = 0; i < trs.length; ++i) {
const tr = trs[i];
this.selectedRows.push(tr.rowId);
if (!tr.classList.contains("selected"))
tr.classList.add("selected");
tr.classList.add("selected");
}
},

Expand Down Expand Up @@ -764,13 +757,8 @@ window.qBittorrent.DynamicTable ??= (() => {
},

setRowClass: function() {
const that = this;
this.tableBody.getElements("tr").each((tr) => {
if (that.isRowSelected(tr.rowId))
tr.classList.add("selected");
else
tr.classList.remove("selected");
});
for (const tr of this.tableBody.querySelectorAll("tr"))
tr.classList.toggle("selected", this.isRowSelected(tr.rowId));
},

onSelectedRowChanged: () => {},
Expand Down Expand Up @@ -2987,10 +2975,7 @@ window.qBittorrent.DynamicTable ??= (() => {
updateRow: function(tr, fullUpdate) {
const row = this.rows.get(tr.rowId);
const data = row[fullUpdate ? "full_data" : "data"];
if (!row.full_data.isRead)
tr.classList.add("unreadArticle");
else
tr.classList.remove("unreadArticle");
tr.classList.toggle("unreadArticle", !row.full_data.isRead);

const tds = tr.getElements("td");
for (let i = 0; i < this.columns.length; ++i) {
Expand Down
10 changes: 2 additions & 8 deletions src/webui/www/private/scripts/prop-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,10 +668,7 @@ window.qBittorrent.PropFiles ??= (() => {
if (span === null)
return;
const rowElem = span.parentElement.parentElement;
if (shouldHide)
rowElem.classList.add("invisible");
else
rowElem.classList.remove("invisible");
rowElem.classList.toggle("invisible", shouldHide);
};

/**
Expand All @@ -689,10 +686,7 @@ window.qBittorrent.PropFiles ??= (() => {

// rotate the collapse icon
const collapseIcon = td.getElementsByClassName("filesTableCollapseIcon")[0];
if (isCollapsed)
collapseIcon.classList.add("rotate");
else
collapseIcon.classList.remove("rotate");
collapseIcon.classList.toggle("rotate", isCollapsed);
};

const _isCollapsed = (node) => {
Expand Down

0 comments on commit 00d0725

Please sign in to comment.