Refactor test slave

- Improved names of elements
- Easier scrolling code
This commit is contained in:
Tim van der Meij 2015-05-15 14:02:56 +02:00
parent 90982332bf
commit 58769fd3b9
2 changed files with 25 additions and 35 deletions

View File

@ -54,7 +54,7 @@ window.load = function load() {
var delay = params.delay || 0; var delay = params.delay || 0;
canvas = document.createElement('canvas'); canvas = document.createElement('canvas');
stdout = document.getElementById('stdout'); stdout = document.getElementById('output');
info('User Agent: ' + navigator.userAgent); info('User Agent: ' + navigator.userAgent);
log('load...\n'); log('load...\n');
@ -93,7 +93,7 @@ function cleanup(callback) {
var ownerNode = styleSheet.ownerNode; var ownerNode = styleSheet.ownerNode;
ownerNode.parentNode.removeChild(ownerNode); ownerNode.parentNode.removeChild(ownerNode);
} }
var guard = document.getElementById('content-end'); var guard = document.getElementById('end');
var body = document.body; var body = document.body;
while (body.lastChild !== guard) { while (body.lastChild !== guard) {
body.removeChild(body.lastChild); body.removeChild(body.lastChild);
@ -369,7 +369,7 @@ function quitApp() {
function done() { function done() {
if (inFlightRequests > 0) { if (inFlightRequests > 0) {
document.getElementById('inFlightCount').innerHTML = inFlightRequests; document.getElementById('inflight').innerHTML = inFlightRequests;
setTimeout(done, 100); setTimeout(done, 100);
} else { } else {
setTimeout(quitApp, 100); setTimeout(quitApp, 100);
@ -417,7 +417,7 @@ function send(url, message, callback) {
} }
} }
}; };
document.getElementById('inFlightCount').innerHTML = inFlightRequests++; document.getElementById('inflight').innerHTML = inFlightRequests++;
r.send(message); r.send(message);
} }
@ -433,11 +433,8 @@ function clear(ctx) {
ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.clearRect(0, 0, canvas.width, canvas.height);
} }
/* Auto-scroll if the scrollbar is near the bottom, otherwise do nothing. */ function scroll() {
function checkScrolling() { window.scrollTo(0, document.body.scrollHeight);
if ((stdout.scrollHeight - stdout.scrollTop) <= stdout.offsetHeight) {
stdout.scrollTop = stdout.scrollHeight;
}
} }
function log(str) { function log(str) {
@ -448,7 +445,7 @@ function log(str) {
} }
if (str.lastIndexOf('\n') >= 0) { if (str.lastIndexOf('\n') >= 0) {
checkScrolling(); scroll();
} }
} }

View File

@ -1,6 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<!-- <!--
Copyright 2012 Mozilla Foundation Copyright 2015 Mozilla Foundation
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -14,34 +14,27 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
--> -->
<html> <html>
<head> <head>
<title>pdf.js test slave</title> <title>PDF.js test slave</title>
<style type="text/css"></style> <meta charset="utf-8">
<script src="/src/shared/util.js"></script> <script src="../src/shared/util.js"></script>
<script src="/src/display/api.js"></script> <script src="../src/display/api.js"></script>
<script src="/src/display/metadata.js"></script> <script src="../src/display/metadata.js"></script>
<script src="/src/display/canvas.js"></script> <script src="../src/display/canvas.js"></script>
<script src="/src/display/webgl.js"></script> <script src="../src/display/webgl.js"></script>
<script src="/src/display/pattern_helper.js"></script> <script src="../src/display/pattern_helper.js"></script>
<script src="/src/display/font_loader.js"></script> <script src="../src/display/font_loader.js"></script>
<script src="/src/display/annotation_helper.js"></script> <script src="../src/display/annotation_helper.js"></script>
<script src="driver.js"></script> <script src="driver.js"></script>
<script>
PDFJS.workerSrc = '/src/worker_loader.js';
</script>
</head> </head>
<body> <body>
<pre style="width:800px; height:800px; overflow:scroll;" id="stdout"></pre> <pre id="output"></pre>
<p>Inflight requests: <span id="inFlightCount"></span></p> <p>Inflight requests: <span id="inflight"></span></p>
<div id="content-end"></div> <div id="end"></div>
<script>
'use strict';
load();
</script>
</body> </body>
<script>
PDFJS.workerSrc = '../src/worker_loader.js';
load();
</script>
</html> </html>