OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 var plugin; | |
tapted
2013/12/02 04:17:19
nit: maybe do that closury thing, putting
`(funct
raymes
2013/12/04 04:54:49
Done.
| |
5 var sizer; | |
6 | |
7 function onScroll() { | |
8 var coordinates = [window.pageXOffset, window.pageYOffset]; | |
9 plugin.postMessage(coordinates); | |
10 } | |
11 | |
12 function handleMessage(message) { | |
13 if (message.data['type'] == 'document_dimensions') { | |
14 if (sizer.style.height != message.data['document_height'] + 'px') { | |
15 sizer.style.height = message.data['document_height'] + 'px'; | |
16 sizer.style.width = message.data['document_width'] + 'px'; | |
17 } | |
18 } | |
19 } | |
20 | |
21 function load() { | |
22 window.onscroll = function() { webkitRequestAnimationFrame(onScroll); }; | |
tapted
2013/12/02 04:17:19
Is this the same as window.addEventListener('scrol
raymes
2013/12/04 04:54:49
Done.
| |
23 | |
24 var url = location.search.substring(1); | |
tapted
2013/12/02 04:17:19
Maybe a comment, "pop off the leading '?'". And is
raymes
2013/12/04 04:54:49
Done.
| |
25 plugin = document.createElement('object'); | |
26 plugin.setAttribute('width', '100%'); | |
27 plugin.setAttribute('height', '100%'); | |
28 plugin.setAttribute('type', 'application/x-google-chrome-pdf'); | |
29 plugin.setAttribute('src', url); | |
30 plugin.style.zIndex = '1'; | |
31 plugin.style.position = 'fixed'; | |
32 plugin.addEventListener('message', handleMessage, false); | |
33 document.body.appendChild(plugin); | |
34 | |
35 sizer = document.createElement('div'); | |
36 sizer.style.zIndex = '0'; | |
37 sizer.style.position = 'absolute'; | |
38 sizer.style.width = '100%'; | |
39 sizer.style.height = '100%'; | |
40 document.body.appendChild(sizer); | |
41 } | |
42 | |
43 load(); | |
OLD | NEW |