From a6ef46143f0a4234a079d18cad286602c0f06e34 Mon Sep 17 00:00:00 2001 From: AP Nothize Date: Wed, 27 Dec 2017 20:06:30 +0800 Subject: [PATCH 1/2] Fix scripts/web for shared files and content-base 1. Copy the shared folder to docs/shared instead of docs/shared/shared. 2. Use docs/ instead of web/ as content-base because web/ doesn't exist. 3. Add $* to allow optional argument such as passing --port to use another port. --- scripts/web | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/web b/scripts/web index ba17dd5..1e46924 100755 --- a/scripts/web +++ b/scripts/web @@ -1,7 +1,7 @@ #!/bin/bash ./scripts/shared -cp -rf shared/ docs/shared/ +cp -rf shared docs server=./node_modules/.bin/webpack-dev-server -$server --inline --config ./webpack.web.js --content-base web/ +$server --inline --config ./webpack.web.js --content-base docs/ $* \ No newline at end of file From 63dc2316b8251c677c7599edcb4805671ed2f118 Mon Sep 17 00:00:00 2001 From: AP Nothize Date: Wed, 27 Dec 2017 20:08:32 +0800 Subject: [PATCH 2/2] Fix rendering the same page more than once from scroll event Prevent invoking UI.renderPage on the same page more than once as that will corrupt the result. --- docs/main.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/main.js b/docs/main.js index 49f52a8..6787e8e 100644 --- a/docs/main.js +++ b/docs/main.js @@ -17,13 +17,19 @@ PDFJS.workerSrc = './shared/pdf.worker.js'; // Render stuff let NUM_PAGES = 0; +let renderedPages = {}; document.getElementById('content-wrapper').addEventListener('scroll', function (e) { let visiblePageNum = Math.round(e.target.scrollTop / PAGE_HEIGHT) + 1; let visiblePage = document.querySelector(`.page[data-page-number="${visiblePageNum}"][data-loaded="false"]`); + if (visiblePage) { - setTimeout(function () { - UI.renderPage(visiblePageNum, RENDER_OPTIONS); - }); + // Prevent invoking UI.renderPage on the same page more than once. + if ( !renderedPages[visiblePageNum] ) { + renderedPages[visiblePageNum] = true; + setTimeout(function () { + UI.renderPage(visiblePageNum, RENDER_OPTIONS); + }); + } } });