OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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 |
| 5 (function() { |
| 6 |
| 7 var plugin; |
| 8 var sizer; |
| 9 |
| 10 function onScroll() { |
| 11 var coordinates = [window.pageXOffset, window.pageYOffset]; |
| 12 plugin.postMessage(coordinates); |
| 13 } |
| 14 |
| 15 function handleMessage(message) { |
| 16 if (message.data['type'] == 'document_dimensions') { |
| 17 if (sizer.style.height != message.data['document_height'] + 'px') { |
| 18 sizer.style.height = message.data['document_height'] + 'px'; |
| 19 sizer.style.width = message.data['document_width'] + 'px'; |
| 20 } |
| 21 } |
| 22 } |
| 23 |
| 24 function load() { |
| 25 window.addEventListener('scroll', |
| 26 function() { webkitRequestAnimationFrame(onScroll); }); |
| 27 |
| 28 // The pdf location is passed in the document url in the format: |
| 29 // http://<.../pdf.html>?<pdf location>. |
| 30 var url = window.location.search.substring(1); |
| 31 plugin = document.createElement('object'); |
| 32 plugin.setAttribute('width', '100%'); |
| 33 plugin.setAttribute('height', '100%'); |
| 34 plugin.setAttribute('type', 'application/x-google-chrome-pdf'); |
| 35 plugin.setAttribute('src', url); |
| 36 plugin.style.zIndex = '1'; |
| 37 plugin.style.position = 'fixed'; |
| 38 plugin.addEventListener('message', handleMessage, false); |
| 39 document.body.appendChild(plugin); |
| 40 |
| 41 sizer = document.createElement('div'); |
| 42 sizer.style.zIndex = '0'; |
| 43 sizer.style.position = 'absolute'; |
| 44 sizer.style.width = '100%'; |
| 45 sizer.style.height = '100%'; |
| 46 document.body.appendChild(sizer); |
| 47 } |
| 48 |
| 49 load(); |
| 50 |
| 51 })(); |
OLD | NEW |