Skip to content

Commit

Permalink
Add required functionality for the loader to work
Browse files Browse the repository at this point in the history
(in viewer.js)
  • Loading branch information
MHShetty committed Jun 6, 2022
1 parent ae80f90 commit 66faafb
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions app/src/main/assets/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ let useRender;
const cache = [];
const maxCached = 6;

var loading_bar = document.getElementById("loading-bar");
var loading_bar_container = document.getElementById("loading-bar-container");

function show_progress_bar() {
loading_bar.style.display = "block";
loading_bar_container.style.display = "block";
}

function hide_progress_bar() {
loading_bar.style.display = "none";
loading_bar_container.style.display = "none";
}

function set_progress(value) {
if(value==0) show_progress_bar();
else if(value==100) hide_progress_bar();
else loading_bar.style.width = value + "%";
}

function maybeRenderNextPage() {
if (renderPending) {
pageRendering = false;
Expand Down Expand Up @@ -209,6 +228,14 @@ function loadDocument() {
}
}

loadingTask.onProgress = function(data){
var progress = Math.ceil((data.loaded/data.total)*100);
console.log("Progress: " + progress);
set_progress(progress);
}

show_progress_bar();

loadingTask.promise.then(function (newDoc) {
pdfDoc = newDoc;
channel.setNumPages(pdfDoc.numPages);
Expand All @@ -218,7 +245,9 @@ function loadDocument() {
console.log("getMetadata error: " + error);
});
renderPage(channel.getPage(), false, false);
hide_progress_bar();
}, function (reason) {
hide_progress_bar();
console.error(reason.name + ": " + reason.message);
});
}

0 comments on commit 66faafb

Please sign in to comment.