Implement an option to disable automatic scrolling

This adds a checkbox with which one can disable scrolling, for example to look back at output during testing. Note that the styles are inline because the test runner removes all <style> elements for each test.
This commit is contained in:
Tim van der Meij 2015-05-15 19:58:34 +02:00
parent 07ec736eb9
commit e02ab9fb79
2 changed files with 14 additions and 6 deletions

View File

@ -96,9 +96,11 @@ var SimpleTextLayerBuilder = (function SimpleTextLayerBuilderClosure() {
/**
* @typedef {Object} DriverOptions
* @property {HTMLPreElement} output - Container for all output messages.
* @property {HTMLSpanElement} inflight - Field displaying the number of
* inflight requests.
* @property {HTMLInputElement} disableScrolling - Checkbox to disable
* automatic scrolling of the output container.
* @property {HTMLPreElement} output - Container for all output messages.
* @property {HTMLDivElement} end - Container for a completion message.
*/
@ -118,8 +120,9 @@ var Driver = (function DriverClosure() {
PDFJS.enableStats = true;
// Set the passed options
this.output = options.output;
this.inflight = options.inflight;
this.disableScrolling = options.disableScrolling;
this.output = options.output;
this.end = options.end;
// Set parameters from the query string
@ -410,9 +413,9 @@ var Driver = (function DriverClosure() {
this.output.textContent += message;
}
if (message.lastIndexOf('\n') >= 0) {
if (message.lastIndexOf('\n') >= 0 && !this.disableScrolling.checked) {
// Scroll to the bottom of the page
window.scrollTo(0, document.body.scrollHeight);
this.output.scrollTop = this.output.scrollHeight;
}
},

View File

@ -29,14 +29,19 @@ limitations under the License.
<script src="driver.js"></script>
</head>
<body>
<pre id="output"></pre>
<p>Inflight requests: <span id="inflight"></span></p>
<p>
<input type="checkbox" id="disableScrolling">
<label for="disableScrolling">Disable automatic scrolling</label>
</p>
<pre id="output" style="max-height: 800px; overflow-y: scroll;"></pre>
<div id="end"></div>
</body>
<script>
var driver = new Driver({
output: document.getElementById('output'),
disableScrolling: document.getElementById('disableScrolling'),
inflight: document.getElementById('inflight'),
output: document.getElementById('output'),
end: document.getElementById('end')
});
driver.run();