1
0
mirror of https://github.com/balkian/go5ears.git synced 2024-11-13 01:32:28 +00:00

Added infinite search

This commit is contained in:
J.Fernando Sánchez 2012-10-13 16:51:17 +02:00
parent aded1d0253
commit 07c6d9b407
3 changed files with 33 additions and 5 deletions

View File

@ -228,6 +228,8 @@ $(document).ready(function(){
var self = this;
self.results = ko.observableArray([]);
self.hasMoreSearch = ko.observable(true);
self.currentPage = ko.observable(0);
self.queryString = ko.observable();
self.shuffle = shuffle;
self.current = current;
@ -249,14 +251,38 @@ $(document).ready(function(){
}
// Operations
self.getResults = function(form) {
$.getJSON(encodeURI('/search?id="'+self.queryString()+'"'), function(allData) {
self.search = function(page) {
$.getJSON(encodeURI('/search?id='+self.queryString()+'&p='+page), function(allData) {
var results = $.map(allData, function(item) { console.log(JSON.stringify(item)); return new Song(item.id,item.group,item.title,item.quality) });
self.results(results);
console.log("Results:");
console.log(results);
if(results.length < 10){
console.log("No more results");
self.hasMoreSearch(false);
}else{
self.hasMoreSearch(true);
}
if(results.length > 0){
for (var i = 0; i < results.length; i += 1) {
self.results.push(results[i])
}
self.currentPage(page);
}
});
}
self.getResults = function() {
self.results.removeAll();
self.search(1);
}
self.searchMore = function(){
if(self.hasMoreSearch()){
self.search(self.currentPage()+1);
}
}
if(typeof(LocalStorage)!=="undefined"){
alert("Bad luck!");

View File

@ -25,8 +25,10 @@ app.get('/search', function(req, resp){
var options = {
host: 'www.goear.com',
port: 80,
path: '/search.php?q='+encodeURIComponent(req.query['id'])
path: '/search/'+encodeURIComponent(req.query['id'].replace(/\s/g , "-"))+'/'+encodeURIComponent(req.query['p'])
};
console.log("Query:"+req.query['id']);
console.log("Querying:"+options.path);
var results = [];
var html = '';

View File

@ -77,7 +77,7 @@
</div>
</li>
</ul>
<button data-bind="click: searchMore, visible: currentPage() > 0 && hasMoreSearch()">Show more</button>
</div>
</div>
</div>