mirror of
https://github.com/balkian/go5ears.git
synced 2024-11-22 05:12:29 +00:00
Added infinite search
This commit is contained in:
parent
aded1d0253
commit
07c6d9b407
32
js/app.js
32
js/app.js
@ -228,6 +228,8 @@ $(document).ready(function(){
|
|||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
self.results = ko.observableArray([]);
|
self.results = ko.observableArray([]);
|
||||||
|
self.hasMoreSearch = ko.observable(true);
|
||||||
|
self.currentPage = ko.observable(0);
|
||||||
self.queryString = ko.observable();
|
self.queryString = ko.observable();
|
||||||
self.shuffle = shuffle;
|
self.shuffle = shuffle;
|
||||||
self.current = current;
|
self.current = current;
|
||||||
@ -249,14 +251,38 @@ $(document).ready(function(){
|
|||||||
}
|
}
|
||||||
// Operations
|
// Operations
|
||||||
|
|
||||||
self.getResults = function(form) {
|
self.search = function(page) {
|
||||||
$.getJSON(encodeURI('/search?id="'+self.queryString()+'"'), function(allData) {
|
$.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) });
|
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"){
|
if(typeof(LocalStorage)!=="undefined"){
|
||||||
alert("Bad luck!");
|
alert("Bad luck!");
|
||||||
|
|
||||||
|
@ -25,8 +25,10 @@ app.get('/search', function(req, resp){
|
|||||||
var options = {
|
var options = {
|
||||||
host: 'www.goear.com',
|
host: 'www.goear.com',
|
||||||
port: 80,
|
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 results = [];
|
||||||
var html = '';
|
var html = '';
|
||||||
|
@ -77,7 +77,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<button data-bind="click: searchMore, visible: currentPage() > 0 && hasMoreSearch()">Show more</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user