Support for ascending/descending sorting, refactor
This commit is contained in:
parent
2838a3cc2a
commit
bba53a8be6
@ -40,24 +40,24 @@ window.onload = function () {
|
|||||||
|
|
||||||
query = queryInput.value
|
query = queryInput.value
|
||||||
switch (sortDropdown.selectedIndex) {
|
switch (sortDropdown.selectedIndex) {
|
||||||
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
setOrderBy("TOTAL_SIZE")
|
setOrderBy("TOTAL_SIZE")
|
||||||
break;
|
break;
|
||||||
|
case 2:
|
||||||
case 3:
|
case 3:
|
||||||
setOrderBy("DISCOVERED_ON")
|
setOrderBy("DISCOVERED_ON")
|
||||||
break;
|
break;
|
||||||
|
case 4:
|
||||||
case 5:
|
case 5:
|
||||||
setOrderBy("N_FILES")
|
setOrderBy("N_FILES")
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query !== '') {
|
ascending = sortDropdown.selectedIndex % 2 === 0
|
||||||
setOrderBy("RELEVANCE");
|
|
||||||
}
|
|
||||||
|
|
||||||
ul.innerHTML = ""
|
ul.innerHTML = ""
|
||||||
lastID = null
|
lastID = lastOrderedValue = null
|
||||||
lastOrderedValue = null
|
|
||||||
load(queryInput.value);
|
load(queryInput.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -115,20 +115,24 @@ function load(queryParam) {
|
|||||||
console.log("reqURL", reqURL);
|
console.log("reqURL", reqURL);
|
||||||
|
|
||||||
let req = new XMLHttpRequest();
|
let req = new XMLHttpRequest();
|
||||||
|
|
||||||
|
function disableButtonWithMsg(msg) {
|
||||||
|
button.textContent = msg;
|
||||||
|
button.setAttribute("disabled", "");
|
||||||
|
}
|
||||||
|
|
||||||
req.onreadystatechange = function () {
|
req.onreadystatechange = function () {
|
||||||
if (req.readyState !== 4)
|
if (req.readyState !== 4)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
button.textContent = "Load More Results";
|
disableButtonWithMsg("Load More Results")
|
||||||
button.removeAttribute("disabled");
|
|
||||||
|
|
||||||
if (req.status !== 200)
|
if (req.status !== 200)
|
||||||
alert(req.responseText);
|
alert(req.responseText);
|
||||||
|
|
||||||
let torrents = JSON.parse(req.responseText);
|
let torrents = JSON.parse(req.responseText);
|
||||||
if (torrents.length === 0) {
|
if (torrents.length === 0) {
|
||||||
button.textContent = "No More Results";
|
disableButtonWithMsg("No More Results")
|
||||||
button.setAttribute("disabled", "");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,8 +148,7 @@ function load(queryParam) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (torrents.length < 20) {
|
if (torrents.length < 20) {
|
||||||
button.textContent = "No More Results";
|
disableButtonWithMsg("No More Results");
|
||||||
button.setAttribute("disabled", "");
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user