blob: c2a47f476a4caa099c9e9c7c27b5883c96220dec (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(function() {
var plugin;
var sizer;
function onScroll() {
var coordinates = [window.pageXOffset, window.pageYOffset];
plugin.postMessage(coordinates);
}
function handleMessage(message) {
if (message.data['type'] == 'document_dimensions') {
if (sizer.style.height != message.data['document_height'] + 'px') {
sizer.style.height = message.data['document_height'] + 'px';
sizer.style.width = message.data['document_width'] + 'px';
}
}
}
function load() {
window.addEventListener('scroll',
function() { webkitRequestAnimationFrame(onScroll); });
// The pdf location is passed in the document url in the format:
// http://<.../pdf.html>?<pdf location>.
var url = window.location.search.substring(1);
plugin = document.createElement('object');
plugin.setAttribute('width', '100%');
plugin.setAttribute('height', '100%');
plugin.setAttribute('type', 'application/x-google-chrome-pdf');
plugin.setAttribute('src', url);
plugin.style.zIndex = '1';
plugin.style.position = 'fixed';
plugin.addEventListener('message', handleMessage, false);
document.body.appendChild(plugin);
sizer = document.createElement('div');
sizer.style.zIndex = '0';
sizer.style.position = 'absolute';
sizer.style.width = '100%';
sizer.style.height = '100%';
document.body.appendChild(sizer);
}
load();
})();
|