Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 104 additions & 18 deletions plugins/mobile/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,17 @@ plugin.setSort = function() {
// points at anything meaningful, so go back to the top
plugin.scrollTop = 0;
plugin.update(true);
var statusEl = document.getElementById('sortLiveStatus');
if (statusEl) {
var sortField = (sort[0] === '-') ? sort.substr(1) : sort;
var sortDir = (sort[0] === '-') ? (theUILang.decs || 'Descending') : (theUILang.acs || 'Ascending');
var langKey = '';
$.each(plugin.sortFields, function(i, f) {
if (f[0] === sortField) langKey = f[1];
});
var fieldName = langKey ? (theUILang[langKey] || sortField) : sortField;
statusEl.textContent = (theUILang.SortTorrents || 'Sort') + ': ' + fieldName + ' (' + sortDir + ')';
}
}
plugin.goBack();
};
Expand Down Expand Up @@ -1793,6 +1804,32 @@ plugin.loadSeedingTime = function () {
};

/*** Torrent list rendering and updates ***/
plugin.reorderRows = function(container, orderedNodes, movedNodes) {
var moveNode = (typeof container.moveBefore === 'function')
? function(node) { container.moveBefore(node, null); }
: function(node) { container.appendChild(node); };

for (var i = 0; i < orderedNodes.length; i++) {
moveNode(orderedNodes[i]);
}

if (movedNodes && movedNodes.length) {
for (var j = 0; j < movedNodes.length; j++) {
var cell = $(movedNodes[j]).children('td');
cell.removeClass('rank-highlight');
if (cell[0]) {
void cell[0].offsetWidth;
}
cell.addClass('rank-highlight');
}
setTimeout(function() {
for (var k = 0; k < movedNodes.length; k++) {
$(movedNodes[k]).children('td').removeClass('rank-highlight');
}
}, 1500);
}
};

plugin.dynamicSort = function (property) {
var sortOrder = 1;
if(property[0] === "-") {
Expand All @@ -1801,29 +1838,38 @@ plugin.dynamicSort = function (property) {
}
return function (a,b) {
var result;
if (typeof a[property] == 'string' || a[property] instanceof String) {
if (parseInt(a[property])) {
if (parseInt(b[property])) {
result = (parseInt(a[property]) < parseInt(b[property])) ? -1 : (parseInt(a[property]) > parseInt(b[property])) ? 1 : 0;
} else {
result = -1;
}
} else if (parseInt(b[property])) {
result = 1;
var valA = a[property];
var valB = b[property];
if (typeof valA == 'string' && property !== 'ul' && property !== 'dl' &&
property !== 'size' && property !== 'uploaded' && property !== 'downloaded' &&
property !== 'done' && property !== 'eta' && property !== 'ratio' &&
property !== 'addtime' && property !== 'seedingtime') {
var strA = valA.toLowerCase();
var strB = (valB || '').toLowerCase();
result = (strA < strB) ? -1 : (strA > strB) ? 1 : 0;
} else {
var numA = (valA === undefined || valA === null) ? 0 : Number(valA);
var numB = (valB === undefined || valB === null) ? 0 : Number(valB);
if (!isNaN(numA) && !isNaN(numB)) {
result = (numA < numB) ? -1 : (numA > numB) ? 1 : 0;
} else {
result = (a[property].toLowerCase() < b[property].toLowerCase()) ? -1 : (a[property].toLowerCase() > b[property].toLowerCase()) ? 1 : 0;
result = (valA < valB) ? -1 : (valA > valB) ? 1 : 0;
}
} else {
result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
}
if (result == 0 && property != 'name') {
// Tie-break by name (always ascending), so e.g. sorting by status
// lists same-status torrents alphabetically like the desktop does
return (a.name.toLowerCase() < b.name.toLowerCase()) ? -1 : (a.name.toLowerCase() > b.name.toLowerCase()) ? 1 : 0;
if (result == 0) {
if (property != 'name') {
var nameA = (a.name || '').toLowerCase();
var nameB = (b.name || '').toLowerCase();
var nameResult = (nameA < nameB) ? -1 : (nameA > nameB) ? 1 : 0;
if (nameResult != 0) {
return nameResult;
}
}
return (a.hash < b.hash) ? -1 : (a.hash > b.hash) ? 1 : 0;
}
return result * sortOrder;
}
}
};
};

// Only the fields the torrent row rendering depends on; comparing these
// (instead of whole torrent objects) avoids redrawing rows whose visible
Expand Down Expand Up @@ -2052,6 +2098,46 @@ plugin.processTorrents = function(torrents, singleUpdate) {
}
}

// Reorder DOM rows to match the current sort order when new data arrived
if (!listHtmlString && torrentArray.length) {
var tbody = listHtml[0];
if (tbody) {
var currentChildren = tbody.children;
var orderChanged = false;
var orderedRows = [];
var prevIndex = {};
var rIdx;
for (rIdx = 0; rIdx < currentChildren.length; rIdx++) {
prevIndex[currentChildren[rIdx].id] = rIdx;
}
for (rIdx = 0; rIdx < torrentArray.length; rIdx++) {
var rowEl = document.getElementById(torrentArray[rIdx].hash);
if (rowEl) {
orderedRows.push(rowEl);
}
}
var movedRows = [];
if (currentChildren.length !== orderedRows.length) {
orderChanged = true;
} else {
for (rIdx = 0; rIdx < orderedRows.length; rIdx++) {
var r = orderedRows[rIdx];
if (currentChildren[rIdx] !== r) {
orderChanged = true;
}
if (prevIndex[r.id] !== undefined && prevIndex[r.id] !== rIdx) {
movedRows.push(r);
}
}
}
if (orderChanged) {
var isVisible = (plugin.currentPage == 'torrentsList') && ($('#torrentsList').css('display') != 'none');
var highlightMoved = plugin.rowsPrimed && isVisible ? movedRows : [];
plugin.reorderRows(tbody, orderedRows, highlightMoved);
}
}
}

// New arrivals (rows are in the DOM and filtered by now): an add
// made here scrolls to its torrent — the upload receipt toast was
// already shown — while arrivals from anywhere else (another
Expand Down
46 changes: 42 additions & 4 deletions plugins/mobile/mobile.css
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,54 @@ h5, #detailsTrackersPage a, #detailsTrackersPage .accordion-button, #detailsFile
font-size: 12px;
}
/* Accent-colored flash on the row scrolled to after adding a torrent
(see plugin.scrollToTorrent). An inset box-shadow, like Bootstrap's
own row coloring, so it renders above the table striping */
(see plugin.scrollToTorrent). Preserves Bootstrap's table striping
layer underneath so the fade blends into the alternating background. */
@keyframes added-highlight {
from { box-shadow: inset 0 0 0 9999px rgba(var(--mobile-accent-rgb), 0.3); }
to { box-shadow: inset 0 0 0 9999px rgba(var(--mobile-accent-rgb), 0); }
from {
box-shadow: inset 0 0 0 9999px rgba(var(--mobile-accent-rgb), 0.3),
inset 0 0 0 9999px var(--bs-table-bg-state, var(--bs-table-bg-type, var(--bs-table-accent-bg)));
}
to {
box-shadow: inset 0 0 0 9999px rgba(var(--mobile-accent-rgb), 0),
inset 0 0 0 9999px var(--bs-table-bg-state, var(--bs-table-bg-type, var(--bs-table-accent-bg)));
}
}
#torrentsList #list .added-highlight {
box-shadow: inset 0 0 0 9999px rgba(var(--mobile-accent-rgb), 0),
inset 0 0 0 9999px var(--bs-table-bg-state, var(--bs-table-bg-type, var(--bs-table-accent-bg)));
animation: added-highlight 2s ease-out;
}

/*** Dynamic sort rank-change highlight ***/
@keyframes rank-highlight {
from {
box-shadow: inset 0 0 0 9999px rgba(var(--mobile-accent-rgb), 0.35),
inset 0 0 0 9999px var(--bs-table-bg-state, var(--bs-table-bg-type, var(--bs-table-accent-bg)));
}
to {
box-shadow: inset 0 0 0 9999px rgba(var(--mobile-accent-rgb), 0),
inset 0 0 0 9999px var(--bs-table-bg-state, var(--bs-table-bg-type, var(--bs-table-accent-bg)));
}
}
#torrentsList #list .rank-highlight {
box-shadow: inset 0 0 0 9999px rgba(var(--mobile-accent-rgb), 0),
inset 0 0 0 9999px var(--bs-table-bg-state, var(--bs-table-bg-type, var(--bs-table-accent-bg)));
animation: rank-highlight 1.5s ease-out;
}
@media (prefers-reduced-motion: reduce) {
#torrentsList #list .rank-highlight {
animation: none !important;
}
}
.visually-hidden {
position: absolute;
width: 1px;
height: 1px;
overflow: hidden;
clip-path: inset(50%);
white-space: nowrap;
}


/*** navbar bottom ***/
.navbar {
Expand Down
1 change: 1 addition & 0 deletions plugins/mobile/mobile.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<button type="button" id="searchClose" onclick="mobile.toggleSearch();" class="btn btn-outline-secondary"><i class="bi bi-x-lg"></i></button>
</div>
<div id="list"><table class="table table-striped"><tbody></tbody></table></div>
<div id="sortLiveStatus" role="status" class="visually-hidden"></div>
</div>

<div class="mainContainer" id="torrentDetails" style="display:none;">
Expand Down
Loading
Loading