Skip to content

Commit 66faafb

Browse files
committed
Add required functionality for the loader to work
(in viewer.js)
1 parent ae80f90 commit 66faafb

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

app/src/main/assets/viewer.js

+29
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,25 @@ let useRender;
1919
const cache = [];
2020
const maxCached = 6;
2121

22+
var loading_bar = document.getElementById("loading-bar");
23+
var loading_bar_container = document.getElementById("loading-bar-container");
24+
25+
function show_progress_bar() {
26+
loading_bar.style.display = "block";
27+
loading_bar_container.style.display = "block";
28+
}
29+
30+
function hide_progress_bar() {
31+
loading_bar.style.display = "none";
32+
loading_bar_container.style.display = "none";
33+
}
34+
35+
function set_progress(value) {
36+
if(value==0) show_progress_bar();
37+
else if(value==100) hide_progress_bar();
38+
else loading_bar.style.width = value + "%";
39+
}
40+
2241
function maybeRenderNextPage() {
2342
if (renderPending) {
2443
pageRendering = false;
@@ -209,6 +228,14 @@ function loadDocument() {
209228
}
210229
}
211230

231+
loadingTask.onProgress = function(data){
232+
var progress = Math.ceil((data.loaded/data.total)*100);
233+
console.log("Progress: " + progress);
234+
set_progress(progress);
235+
}
236+
237+
show_progress_bar();
238+
212239
loadingTask.promise.then(function (newDoc) {
213240
pdfDoc = newDoc;
214241
channel.setNumPages(pdfDoc.numPages);
@@ -218,7 +245,9 @@ function loadDocument() {
218245
console.log("getMetadata error: " + error);
219246
});
220247
renderPage(channel.getPage(), false, false);
248+
hide_progress_bar();
221249
}, function (reason) {
250+
hide_progress_bar();
222251
console.error(reason.name + ": " + reason.message);
223252
});
224253
}

0 commit comments

Comments
 (0)