Search results pagination and clearing

This commit is contained in:
Calvin Montgomery 2013-05-26 22:45:50 -04:00
parent 50d73cee5b
commit ee10a080cc
4 changed files with 46 additions and 13 deletions

View File

@ -692,21 +692,26 @@ Callbacks = {
}, },
librarySearchResults: function(data) { librarySearchResults: function(data) {
var n = $("#library").children().length; clearSearchResults();
for(var i = 0; i < n; i++) { $("#library").data("entries", data.results);
$("#library")[0].removeChild($("#library").children()[0]); if(data.results.length > 100) {
} var pag = $("<div/>").addClass("pagination")
var ul = $("#library")[0]; .attr("id", "search_pagination")
for(var i = 0; i < data.results.length; i++) { .insertAfter($("#library"));
var li = makeQueueEntry(data.results[i]); var btns = $("<ul/>").appendTo(pag);
if(RANK >= Rank.Moderator || OPENQUEUE || LEADER) { for(var i = 0; i < data.results.length / 100; i++) {
if(data.results[i].thumb) var li = $("<li/>").appendTo(btns);
addLibraryButtons(li, data.results[i].id, true); (function(i) {
else $("<a/>").attr("href", "javascript:void(0)")
addLibraryButtons(li, data.results[i].id); .text(i+1)
.click(function() {
loadSearchPage(i);
})
.appendTo(li);
})(i);
} }
$(li).appendTo(ul);
} }
loadSearchPage(0);
}, },
/* REGION Polls */ /* REGION Polls */

View File

@ -559,6 +559,10 @@ $("#youtube_search").click(function() {
}); });
}); });
$("#search_clear").click(function() {
clearSearchResults();
});
function fluidLayout() { function fluidLayout() {
$(".row").each(function() { $(".row").each(function() {
$(this).removeClass("row").addClass("row-fluid"); $(this).removeClass("row").addClass("row-fluid");

View File

@ -448,6 +448,29 @@ function addLibraryButtons(li, id, yt) {
} }
} }
function loadSearchPage(page) {
$("#library").html("");
var results = $("#library").data("entries");
var start = page * 100;
for(var i = start; i < start + 100 && i < results.length; i++) {
var li = makeQueueEntry(results[i]);
if(hasPermission("playlistadd")) {
if(results[i].thumb) {
addLibraryButtons(li, results[i].id, true);
}
else {
addLibraryButtons(li, results[i].id);
}
}
$(li).appendTo($("#library"));
}
}
function clearSearchResults() {
$("#library").html("");
$("#search_pagination").remove();
}
// Rearranges the queue // Rearranges the queue
function moveVideo(src, dest, noanim) { function moveVideo(src, dest, noanim) {
var li = $($("#queue").children()[src]); var li = $($("#queue").children()[src]);

View File

@ -85,6 +85,7 @@
<div class="span12" style="margin-left: 0;"> <div class="span12" style="margin-left: 0;">
<ul id="library" class="videolist"> <ul id="library" class="videolist">
</ul> </ul>
<button class="btn btn-block" id="search_clear">Clear Results</button>
</div> </div>
</div> </div>
</div> </div>