Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use async content loading
  • Loading branch information
andoma committed Jan 26, 2015
1 parent dfa4360 commit b284da5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
54 changes: 42 additions & 12 deletions headweb.js
Expand Up @@ -133,6 +133,32 @@ var XML = require('showtime/xml');
return XML.parse(v).response;
}


function asyncRequest(path, offset, limit, callback) {
var v = showtime.httpReq("https://api.headweb.com/v4" + path, {
args: {
apikey: APIKEY,
offset: offset,
limit: limit
},
debug: true
}, function(err, response) {
if(err) {
callback(null);
} else {
print("no fail");
var doc;
try {
doc = XML.parse(response).response;
} catch(e) {
callback(null);
return;
}
callback(doc);
}
});
}

function imageSet(covers) {
var images = [];
for(var i = 0; i < covers.length; i++) {
Expand Down Expand Up @@ -228,23 +254,27 @@ var XML = require('showtime/xml');
var offset = 0;

function loader() {
var doc = request(url, offset, 50);
if(!doc.list)
return false;
asyncRequest(url, offset, 50, function(doc) {
page.loading = false;
print("doc=", doc);
if(!doc.list) {
page.haveMore(false);
return;
}

page.entries = parseInt(doc.list["@items"]);
for (var i = 0; i < doc.list.length; i++) {
var c = doc.list[i];
offset++;
addContentToPage(page, c);
}
return offset < page.entries;
page.entries = parseInt(doc.list["@items"]);
for (var i = 0; i < doc.list.length; i++) {
var c = doc.list[i];
offset++;
addContentToPage(page, c);
}
page.haveMore(offset < page.entries);
});
}

page.type = "directory";
loader();
page.loading = false;
page.paginator = loader;
loader();
}


Expand Down
4 changes: 2 additions & 2 deletions plugin.json
Expand Up @@ -2,8 +2,8 @@
"type": "ecmascript",
"id": "headweb",
"file": "headweb.js",
"showtimeVersion": "4.7.515",
"version": "2.0",
"showtimeVersion": "4.9.105",
"version": "2.1",
"author": "Andreas Öman",
"title": "Headweb",
"icon": "headweb_square.png",
Expand Down

0 comments on commit b284da5

Please sign in to comment.