]> git.parisson.com Git - pdf.js.git/commitdiff
Fix an issue with the setTimeout method used for waiting for fonts to load
authorVivien Nicolas <21@vingtetun.org>
Tue, 14 Jun 2011 02:52:21 +0000 (04:52 +0200)
committerVivien Nicolas <21@vingtetun.org>
Tue, 14 Jun 2011 02:52:21 +0000 (04:52 +0200)
test.js

diff --git a/test.js b/test.js
index bd6c812e89047f7d0328bbbb04d2544c51c99e40..8c561e8a6762789bfad53f3f8fef47bc35846dd0 100644 (file)
--- a/test.js
+++ b/test.js
@@ -1,7 +1,7 @@
 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- /
 /* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */
 
-var pdfDocument, canvas, pageDisplay, pageNum;
+var pdfDocument, canvas, pageDisplay, pageNum, pageTimeout;
 function load() {
     canvas = document.getElementById("canvas");
     canvas.mozOpaque = true;
@@ -47,6 +47,9 @@ function gotoPage(num) {
 }
 
 function displayPage(num) {
+    if (pageNum != num)
+      window.clearTimeout(pageTimeout);
+
     document.getElementById("pageNumber").value = num;
 
     var t0 = Date.now();
@@ -104,8 +107,11 @@ function displayPage(num) {
     // If everything is ready do not delayed the page loading any more
     if (fontsReady)
       display();
-    else
-      setTimeout(displayPage, 150, num);
+    else {
+      // FIXME Relying on an event seems much more cleaner here instead
+      // of a setTimeout...
+      pageTimeout = window.setTimeout(displayPage, 150, num);
+    }
 }
 
 function nextPage() {