Skip to content

Commit

Permalink
Fixed a bug, progress is not shown, once pdfDoc is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
Narendra Sisodiya committed Apr 26, 2015
1 parent a3c0a9b commit 2c17c46
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pt-pdfslideshow",
"version": "1.0.2",
"version": "1.0.3",
"homepage": "https://github.com/pitana/pt-pdfslideshow",
"authors": [
"Narendra Sisodiya <narendra@narendrasisodiya.com>"
Expand Down
29 changes: 18 additions & 11 deletions src/pt-pdfslideshow.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pitana.register({
referenceNode.parentNode.insertBefore(document.createElement("pt-progressbar"), referenceNode.nextSibling);

this.pdfDoc = null;
this.pdfLoaded = false;

this.$.setAttribute("tabindex", "-1");
this.pageRendering = false;
Expand All @@ -67,24 +68,30 @@ pitana.register({
this.bar.value = 0;
this.bar.intermediate = false;
PDFJS.getDocument(this.$.src, null, null, function(progress){
if(self.bar.max !== progress.total){
if(progress.total === null || progress.total === undefined){
self.bar.intermediate = true
}else{
self.bar.max = progress.total;
}
}
if(progress.loaded > self.bar.value){
self.bar.value = progress.loaded;
}
self.onProgress(progress);
}).then(function (pdfDoc) {
self.onPdfLoaded(pdfDoc);
});
},
onProgress: function (progress) {
if(this.pdfLoaded === true){
return;
}
if(this.bar.max !== progress.total){
if(progress.total === null || progress.total === undefined){
this.bar.intermediate = true
}else{
this.bar.max = progress.total;
}
}
if(progress.loaded > this.bar.value){
this.bar.value = progress.loaded;
}
},
onPdfLoaded: function (pdfDoc) {
this.pdfLoaded = true;
this.pdfDoc = pdfDoc;
this.$.querySelector('#page_count').textContent = this.pdfDoc.numPages;

this.bar.intermediate = false;
this.bar.max = this.pdfDoc.numPages;
this.$.currentPage = 1;
Expand Down

0 comments on commit 2c17c46

Please sign in to comment.