3 changed files with 576 additions and 584 deletions
@ -1,197 +1,197 @@ |
|||||||
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- / |
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- / |
||||||
/* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */ |
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ |
||||||
|
|
||||||
body { |
body { |
||||||
background-color: #929292; |
background-color: #929292; |
||||||
font-family: 'Lucida Grande', 'Lucida Sans Unicode', Helvetica, Arial, Verdana, sans-serif; |
font-family: 'Lucida Grande', 'Lucida Sans Unicode', Helvetica, Arial, Verdana, sans-serif; |
||||||
margin: 0px; |
margin: 0px; |
||||||
padding: 0px; |
padding: 0px; |
||||||
} |
} |
||||||
|
|
||||||
canvas { |
canvas { |
||||||
box-shadow: 0px 4px 10px #000; |
box-shadow: 0px 4px 10px #000; |
||||||
-moz-box-shadow: 0px 4px 10px #000; |
-moz-box-shadow: 0px 4px 10px #000; |
||||||
-webkit-box-shadow: 0px 4px 10px #000; |
-webkit-box-shadow: 0px 4px 10px #000; |
||||||
} |
} |
||||||
|
|
||||||
span { |
span { |
||||||
font-size: 0.8em; |
font-size: 0.8em; |
||||||
} |
} |
||||||
|
|
||||||
.control { |
.control { |
||||||
display: inline-block; |
display: inline-block; |
||||||
float: left; |
float: left; |
||||||
margin: 0px 20px 0px 0px; |
margin: 0px 20px 0px 0px; |
||||||
padding: 0px 4px 0px 0px; |
padding: 0px 4px 0px 0px; |
||||||
} |
} |
||||||
|
|
||||||
.control > input { |
.control > input { |
||||||
float: left; |
float: left; |
||||||
border: 1px solid #4d4d4d; |
border: 1px solid #4d4d4d; |
||||||
height: 20px; |
height: 20px; |
||||||
padding: 0px; |
padding: 0px; |
||||||
margin: 0px 2px 0px 0px; |
margin: 0px 2px 0px 0px; |
||||||
border-radius: 4px; |
border-radius: 4px; |
||||||
-moz-border-radius: 4px; |
-moz-border-radius: 4px; |
||||||
-webkit-border-radius: 4px; |
-webkit-border-radius: 4px; |
||||||
box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25); |
box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25); |
||||||
-moz-box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25); |
-moz-box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25); |
||||||
-webkit-box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25); |
-webkit-box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25); |
||||||
} |
} |
||||||
|
|
||||||
.control > select { |
.control > select { |
||||||
float: left; |
float: left; |
||||||
border: 1px solid #4d4d4d; |
border: 1px solid #4d4d4d; |
||||||
height: 22px; |
height: 22px; |
||||||
padding: 2px 0px 0px; |
padding: 2px 0px 0px; |
||||||
margin: 0px 0px 1px; |
margin: 0px 0px 1px; |
||||||
border-radius: 4px; |
border-radius: 4px; |
||||||
-moz-border-radius: 4px; |
-moz-border-radius: 4px; |
||||||
-webkit-border-radius: 4px; |
-webkit-border-radius: 4px; |
||||||
box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25); |
box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25); |
||||||
-moz-box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25); |
-moz-box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25); |
||||||
-webkit-box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25); |
-webkit-box-shadow: 0px 1px 0px rgba(255, 255, 255, 0.25); |
||||||
} |
} |
||||||
|
|
||||||
.control > span { |
.control > span { |
||||||
cursor: default; |
cursor: default; |
||||||
float: left; |
float: left; |
||||||
height: 18px; |
height: 18px; |
||||||
margin: 5px 2px 0px; |
margin: 5px 2px 0px; |
||||||
padding: 0px; |
padding: 0px; |
||||||
user-select: none; |
user-select: none; |
||||||
-moz-user-select: none; |
-moz-user-select: none; |
||||||
-webkit-user-select: none; |
-webkit-user-select: none; |
||||||
} |
} |
||||||
|
|
||||||
.control .label { |
.control .label { |
||||||
clear: both; |
clear: both; |
||||||
float: left; |
float: left; |
||||||
font-size: 0.65em; |
font-size: 0.65em; |
||||||
margin: 2px 0px 0px; |
margin: 2px 0px 0px; |
||||||
position: relative; |
position: relative; |
||||||
text-align: center; |
text-align: center; |
||||||
width: 100%; |
width: 100%; |
||||||
} |
} |
||||||
|
|
||||||
.page { |
.page { |
||||||
width: 816px; |
width: 816px; |
||||||
height: 1056px; |
height: 1056px; |
||||||
margin: 10px auto; |
margin: 10px auto; |
||||||
} |
} |
||||||
|
|
||||||
#controls { |
#controls { |
||||||
background-color: #eee; |
background-color: #eee; |
||||||
border-bottom: 1px solid #666; |
border-bottom: 1px solid #666; |
||||||
padding: 4px 0px 0px 8px; |
padding: 4px 0px 0px 8px; |
||||||
position: fixed; |
position: fixed; |
||||||
left: 0px; |
left: 0px; |
||||||
top: 0px; |
top: 0px; |
||||||
height: 40px; |
height: 40px; |
||||||
width: 100%; |
width: 100%; |
||||||
box-shadow: 0px 2px 8px #000; |
box-shadow: 0px 2px 8px #000; |
||||||
-moz-box-shadow: 0px 2px 8px #000; |
-moz-box-shadow: 0px 2px 8px #000; |
||||||
-webkit-box-shadow: 0px 2px 8px #000; |
-webkit-box-shadow: 0px 2px 8px #000; |
||||||
} |
} |
||||||
|
|
||||||
#controls input { |
#controls input { |
||||||
user-select: text; |
user-select: text; |
||||||
-moz-user-select: text; |
-moz-user-select: text; |
||||||
-webkit-user-select: text; |
-webkit-user-select: text; |
||||||
} |
} |
||||||
|
|
||||||
#previousPageButton { |
#previousPageButton { |
||||||
background: url('images/buttons.png') no-repeat 0px -23px; |
background: url('images/buttons.png') no-repeat 0px -23px; |
||||||
cursor: default; |
cursor: default; |
||||||
display: inline-block; |
display: inline-block; |
||||||
float: left; |
float: left; |
||||||
margin: 0px; |
margin: 0px; |
||||||
width: 28px; |
width: 28px; |
||||||
height: 23px; |
height: 23px; |
||||||
} |
} |
||||||
|
|
||||||
#previousPageButton.down { |
#previousPageButton.down { |
||||||
background: url('images/buttons.png') no-repeat 0px -46px; |
background: url('images/buttons.png') no-repeat 0px -46px; |
||||||
} |
} |
||||||
|
|
||||||
#previousPageButton.disabled { |
#previousPageButton.disabled { |
||||||
background: url('images/buttons.png') no-repeat 0px 0px; |
background: url('images/buttons.png') no-repeat 0px 0px; |
||||||
} |
} |
||||||
|
|
||||||
#nextPageButton { |
#nextPageButton { |
||||||
background: url('images/buttons.png') no-repeat -28px -23px; |
background: url('images/buttons.png') no-repeat -28px -23px; |
||||||
cursor: default; |
cursor: default; |
||||||
display: inline-block; |
display: inline-block; |
||||||
float: left; |
float: left; |
||||||
margin: 0px; |
margin: 0px; |
||||||
width: 28px; |
width: 28px; |
||||||
height: 23px; |
height: 23px; |
||||||
} |
} |
||||||
|
|
||||||
#nextPageButton.down { |
#nextPageButton.down { |
||||||
background: url('images/buttons.png') no-repeat -28px -46px; |
background: url('images/buttons.png') no-repeat -28px -46px; |
||||||
} |
} |
||||||
|
|
||||||
#nextPageButton.disabled { |
#nextPageButton.disabled { |
||||||
background: url('images/buttons.png') no-repeat -28px 0px; |
background: url('images/buttons.png') no-repeat -28px 0px; |
||||||
} |
} |
||||||
|
|
||||||
#openFileButton { |
#openFileButton { |
||||||
background: url('images/buttons.png') no-repeat -56px -23px; |
background: url('images/buttons.png') no-repeat -56px -23px; |
||||||
cursor: default; |
cursor: default; |
||||||
display: inline-block; |
display: inline-block; |
||||||
float: left; |
float: left; |
||||||
margin: 0px 0px 0px 3px; |
margin: 0px 0px 0px 3px; |
||||||
width: 29px; |
width: 29px; |
||||||
height: 23px; |
height: 23px; |
||||||
} |
} |
||||||
|
|
||||||
#openFileButton.down { |
#openFileButton.down { |
||||||
background: url('images/buttons.png') no-repeat -56px -46px; |
background: url('images/buttons.png') no-repeat -56px -46px; |
||||||
} |
} |
||||||
|
|
||||||
#openFileButton.disabled { |
#openFileButton.disabled { |
||||||
background: url('images/buttons.png') no-repeat -56px 0px; |
background: url('images/buttons.png') no-repeat -56px 0px; |
||||||
} |
} |
||||||
|
|
||||||
#fileInput { |
#fileInput { |
||||||
display: none; |
display: none; |
||||||
} |
} |
||||||
|
|
||||||
#pageNumber { |
#pageNumber { |
||||||
text-align: right; |
text-align: right; |
||||||
} |
} |
||||||
|
|
||||||
#sidebar { |
#sidebar { |
||||||
background-color: rgba(0, 0, 0, 0.8); |
background-color: rgba(0, 0, 0, 0.8); |
||||||
position: fixed; |
position: fixed; |
||||||
width: 150px; |
width: 150px; |
||||||
top: 62px; |
top: 62px; |
||||||
bottom: 18px; |
bottom: 18px; |
||||||
border-top-right-radius: 8px; |
border-top-right-radius: 8px; |
||||||
border-bottom-right-radius: 8px; |
border-bottom-right-radius: 8px; |
||||||
-moz-border-radius-topright: 8px; |
-moz-border-radius-topright: 8px; |
||||||
-moz-border-radius-bottomright: 8px; |
-moz-border-radius-bottomright: 8px; |
||||||
-webkit-border-top-right-radius: 8px; |
-webkit-border-top-right-radius: 8px; |
||||||
-webkit-border-bottom-right-radius: 8px; |
-webkit-border-bottom-right-radius: 8px; |
||||||
} |
} |
||||||
|
|
||||||
#sidebarScrollView { |
#sidebarScrollView { |
||||||
position: absolute; |
position: absolute; |
||||||
overflow: hidden; |
overflow: hidden; |
||||||
overflow-y: auto; |
overflow-y: auto; |
||||||
top: 40px; |
top: 40px; |
||||||
right: 10px; |
right: 10px; |
||||||
bottom: 10px; |
bottom: 10px; |
||||||
left: 10px; |
left: 10px; |
||||||
} |
} |
||||||
|
|
||||||
#sidebarContentView { |
#sidebarContentView { |
||||||
height: auto; |
height: auto; |
||||||
width: 100px; |
width: 100px; |
||||||
} |
} |
||||||
|
|
||||||
#viewer { |
#viewer { |
||||||
margin: 44px 0px 0px; |
margin: 44px 0px 0px; |
||||||
padding: 8px 0px; |
padding: 8px 0px; |
||||||
} |
} |
||||||
|
@ -1,466 +1,458 @@ |
|||||||
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- / |
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- / |
||||||
/* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */ |
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ |
||||||
|
|
||||||
"use strict"; |
"use strict"; |
||||||
|
|
||||||
var PDFViewer = { |
var PDFViewer = { |
||||||
queryParams: {}, |
queryParams: {}, |
||||||
|
|
||||||
element: null, |
element: null, |
||||||
|
|
||||||
previousPageButton: null, |
previousPageButton: null, |
||||||
nextPageButton: null, |
nextPageButton: null, |
||||||
pageNumberInput: null, |
pageNumberInput: null, |
||||||
scaleSelect: null, |
scaleSelect: null, |
||||||
fileInput: null, |
fileInput: null, |
||||||
|
|
||||||
willJumpToPage: false, |
willJumpToPage: false, |
||||||
|
|
||||||
pdf: null, |
pdf: null, |
||||||
|
|
||||||
url: 'compressed.tracemonkey-pldi-09.pdf', |
url: 'compressed.tracemonkey-pldi-09.pdf', |
||||||
pageNumber: 1, |
pageNumber: 1, |
||||||
numberOfPages: 1, |
numberOfPages: 1, |
||||||
|
|
||||||
scale: 1.0, |
scale: 1.0, |
||||||
|
|
||||||
pageWidth: function() { |
pageWidth: function() { |
||||||
return 816 * PDFViewer.scale; |
return 816 * PDFViewer.scale; |
||||||
}, |
}, |
||||||
|
|
||||||
pageHeight: function() { |
pageHeight: function() { |
||||||
return 1056 * PDFViewer.scale; |
return 1056 * PDFViewer.scale; |
||||||
}, |
}, |
||||||
|
|
||||||
lastPagesDrawn: [], |
lastPagesDrawn: [], |
||||||
|
|
||||||
visiblePages: function() { |
visiblePages: function() { |
||||||
var pageHeight = PDFViewer.pageHeight() + 20; // Add 20 for the margins.
|
var pageHeight = PDFViewer.pageHeight() + 20; // Add 20 for the margins.
|
||||||
var windowTop = window.pageYOffset; |
var windowTop = window.pageYOffset; |
||||||
var windowBottom = window.pageYOffset + window.innerHeight; |
var windowBottom = window.pageYOffset + window.innerHeight; |
||||||
var pageStartIndex = Math.floor(windowTop / pageHeight); |
var pageStartIndex = Math.floor(windowTop / pageHeight); |
||||||
var pageStopIndex = Math.ceil(windowBottom / pageHeight); |
var pageStopIndex = Math.ceil(windowBottom / pageHeight); |
||||||
|
|
||||||
var pages = []; |
var pages = []; |
||||||
|
|
||||||
for (var i = pageStartIndex; i <= pageStopIndex; i++) { |
for (var i = pageStartIndex; i <= pageStopIndex; i++) { |
||||||
pages.push(i + 1); |
pages.push(i + 1); |
||||||
} |
} |
||||||
|
|
||||||
return pages; |
return pages; |
||||||
}, |
}, |
||||||
|
|
||||||
createPage: function(num) { |
createPage: function(num) { |
||||||
var anchor = document.createElement('a'); |
var anchor = document.createElement('a'); |
||||||
anchor.name = '' + num; |
anchor.name = '' + num; |
||||||
|
|
||||||
var div = document.createElement('div'); |
var div = document.createElement('div'); |
||||||
div.id = 'pageContainer' + num; |
div.id = 'pageContainer' + num; |
||||||
div.className = 'page'; |
div.className = 'page'; |
||||||
div.style.width = PDFViewer.pageWidth() + 'px'; |
div.style.width = PDFViewer.pageWidth() + 'px'; |
||||||
div.style.height = PDFViewer.pageHeight() + 'px'; |
div.style.height = PDFViewer.pageHeight() + 'px'; |
||||||
|
|
||||||
PDFViewer.element.appendChild(anchor); |
PDFViewer.element.appendChild(anchor); |
||||||
PDFViewer.element.appendChild(div); |
PDFViewer.element.appendChild(div); |
||||||
}, |
}, |
||||||
|
|
||||||
removePage: function(num) { |
removePage: function(num) { |
||||||
var div = document.getElementById('pageContainer' + num); |
var div = document.getElementById('pageContainer' + num); |
||||||
|
|
||||||
if (div) { |
if (div) { |
||||||
while (div.hasChildNodes()) { |
while (div.hasChildNodes()) { |
||||||
div.removeChild(div.firstChild); |
div.removeChild(div.firstChild); |
||||||
} |
} |
||||||
} |
} |
||||||
}, |
}, |
||||||
|
|
||||||
drawPage: function(num) { |
drawPage: function(num) { |
||||||
if (!PDFViewer.pdf) { |
if (!PDFViewer.pdf) { |
||||||
return; |
return; |
||||||
} |
} |
||||||
|
|
||||||
var div = document.getElementById('pageContainer' + num); |
var div = document.getElementById('pageContainer' + num); |
||||||
var canvas = document.createElement('canvas'); |
var canvas = document.createElement('canvas'); |
||||||
|
|
||||||
if (div && !div.hasChildNodes()) { |
if (div && !div.hasChildNodes()) { |
||||||
div.appendChild(canvas); |
div.appendChild(canvas); |
||||||
|
|
||||||
var page = PDFViewer.pdf.getPage(num); |
var page = PDFViewer.pdf.getPage(num); |
||||||
|
|
||||||
canvas.id = 'page' + num; |
canvas.id = 'page' + num; |
||||||
canvas.mozOpaque = true; |
canvas.mozOpaque = true; |
||||||
|
|
||||||
// Canvas dimensions must be specified in CSS pixels. CSS pixels
|
// Canvas dimensions must be specified in CSS pixels. CSS pixels
|
||||||
// are always 96 dpi. These dimensions are 8.5in x 11in at 96dpi.
|
// are always 96 dpi. These dimensions are 8.5in x 11in at 96dpi.
|
||||||
canvas.width = PDFViewer.pageWidth(); |
canvas.width = PDFViewer.pageWidth(); |
||||||
canvas.height = PDFViewer.pageHeight(); |
canvas.height = PDFViewer.pageHeight(); |
||||||
|
|
||||||
var ctx = canvas.getContext('2d'); |
var ctx = canvas.getContext('2d'); |
||||||
ctx.save(); |
ctx.save(); |
||||||
ctx.fillStyle = 'rgb(255, 255, 255)'; |
ctx.fillStyle = 'rgb(255, 255, 255)'; |
||||||
ctx.fillRect(0, 0, canvas.width, canvas.height); |
ctx.fillRect(0, 0, canvas.width, canvas.height); |
||||||
ctx.restore(); |
ctx.restore(); |
||||||
|
|
||||||
var gfx = new CanvasGraphics(ctx); |
var gfx = new CanvasGraphics(ctx); |
||||||
var fonts = []; |
var fonts = []; |
||||||
|
|
||||||
// page.compile will collect all fonts for us, once we have loaded them
|
// page.compile will collect all fonts for us, once we have loaded them
|
||||||
// we can trigger the actual page rendering with page.display
|
// we can trigger the actual page rendering with page.display
|
||||||
page.compile(gfx, fonts); |
page.compile(gfx, fonts); |
||||||
|
|
||||||
var areFontsReady = true; |
var areFontsReady = true; |
||||||
|
|
||||||
// Inspect fonts and translate the missing one
|
// Inspect fonts and translate the missing one
|
||||||
var fontCount = fonts.length; |
var fontCount = fonts.length; |
||||||
|
|
||||||
for (var i = 0; i < fontCount; i++) { |
for (var i = 0; i < fontCount; i++) { |
||||||
var font = fonts[i]; |
var font = fonts[i]; |
||||||
|
|
||||||
if (Fonts[font.name]) { |
if (Fonts[font.name]) { |
||||||
areFontsReady = areFontsReady && !Fonts[font.name].loading; |
areFontsReady = areFontsReady && !Fonts[font.name].loading; |
||||||
continue; |
continue; |
||||||
} |
} |
||||||
|
|
||||||
new Font(font.name, font.file, font.properties); |
new Font(font.name, font.file, font.properties); |
||||||
|
|
||||||
areFontsReady = false; |
areFontsReady = false; |
||||||
} |
} |
||||||
|
|
||||||
var pageInterval; |
var pageInterval; |
||||||
|
|
||||||
var delayLoadFont = function() { |
var delayLoadFont = function() { |
||||||
for (var i = 0; i < fontCount; i++) { |
for (var i = 0; i < fontCount; i++) { |
||||||
if (Fonts[font.name].loading) { |
if (Fonts[font.name].loading) { |
||||||
return; |
return; |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
clearInterval(pageInterval); |
clearInterval(pageInterval); |
||||||
|
|
||||||
while (div.hasChildNodes()) { |
while (div.hasChildNodes()) { |
||||||
div.removeChild(div.firstChild); |
div.removeChild(div.firstChild); |
||||||
} |
} |
||||||
|
|
||||||
PDFViewer.drawPage(num); |
PDFViewer.drawPage(num); |
||||||
} |
} |
||||||
|
|
||||||
if (!areFontsReady) { |
if (!areFontsReady) { |
||||||
pageInterval = setInterval(delayLoadFont, 10); |
pageInterval = setInterval(delayLoadFont, 10); |
||||||
return; |
return; |
||||||
} |
} |
||||||
|
|
||||||
page.display(gfx); |
page.display(gfx); |
||||||
} |
} |
||||||
}, |
}, |
||||||
|
|
||||||
changeScale: function(num) { |
changeScale: function(num) { |
||||||
while (PDFViewer.element.hasChildNodes()) { |
while (PDFViewer.element.hasChildNodes()) { |
||||||
PDFViewer.element.removeChild(PDFViewer.element.firstChild); |
PDFViewer.element.removeChild(PDFViewer.element.firstChild); |
||||||
} |
} |
||||||
|
|
||||||
PDFViewer.scale = num / 100; |
PDFViewer.scale = num / 100; |
||||||
|
|
||||||
var i; |
var i; |
||||||
|
|
||||||
if (PDFViewer.pdf) { |
if (PDFViewer.pdf) { |
||||||
for (i = 1; i <= PDFViewer.numberOfPages; i++) { |
for (i = 1; i <= PDFViewer.numberOfPages; i++) { |
||||||
PDFViewer.createPage(i); |
PDFViewer.createPage(i); |
||||||
} |
} |
||||||
|
|
||||||
if (PDFViewer.numberOfPages > 0) { |
if (PDFViewer.numberOfPages > 0) { |
||||||
PDFViewer.drawPage(1); |
PDFViewer.drawPage(1); |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
|
for (i = 0; i < PDFViewer.scaleSelect.childNodes; i++) { |
||||||
|
var option = PDFViewer.scaleSelect.childNodes[i]; |
||||||
|
|
||||||
for (i = 0; i < PDFViewer.scaleSelect.childNodes; i++) { |
if (option.value == num) { |
||||||
var option = PDFViewer.scaleSelect.childNodes[i]; |
if (!option.selected) { |
||||||
|
option.selected = 'selected'; |
||||||
if (option.value == num) { |
} |
||||||
if (!option.selected) { |
} else { |
||||||
option.selected = 'selected'; |
if (option.selected) { |
||||||
} |
option.removeAttribute('selected'); |
||||||
} else { |
|
||||||
if (option.selected) { |
|
||||||
option.removeAttribute('selected'); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
PDFViewer.scaleSelect.value = Math.floor(PDFViewer.scale * 100) + '%'; |
PDFViewer.scaleSelect.value = Math.floor(PDFViewer.scale * 100) + '%'; |
||||||
}, |
}, |
||||||
|
|
||||||
goToPage: function(num) { |
goToPage: function(num) { |
||||||
if (1 <= num && num <= PDFViewer.numberOfPages) { |
if (1 <= num && num <= PDFViewer.numberOfPages) { |
||||||
PDFViewer.pageNumber = num; |
PDFViewer.pageNumber = num; |
||||||
PDFViewer.pageNumberInput.value = PDFViewer.pageNumber; |
PDFViewer.pageNumberInput.value = PDFViewer.pageNumber; |
||||||
PDFViewer.willJumpToPage = true; |
PDFViewer.willJumpToPage = true; |
||||||
|
|
||||||
document.location.hash = PDFViewer.pageNumber; |
document.location.hash = PDFViewer.pageNumber; |
||||||
|
|
||||||
PDFViewer.previousPageButton.className = (PDFViewer.pageNumber === 1) ? |
PDFViewer.previousPageButton.className = (PDFViewer.pageNumber === 1) ? 'disabled' : ''; |
||||||
'disabled' : ''; |
PDFViewer.nextPageButton.className = (PDFViewer.pageNumber === PDFViewer.numberOfPages) ? 'disabled' : ''; |
||||||
PDFViewer.nextPageButton.className = (PDFViewer.pageNumber === PDFViewer.numberOfPages) ? |
} |
||||||
'disabled' : ''; |
}, |
||||||
} |
|
||||||
}, |
|
||||||
|
|
||||||
goToPreviousPage: function() { |
goToPreviousPage: function() { |
||||||
if (PDFViewer.pageNumber > 1) { |
if (PDFViewer.pageNumber > 1) { |
||||||
PDFViewer.goToPage(--PDFViewer.pageNumber); |
PDFViewer.goToPage(--PDFViewer.pageNumber); |
||||||
} |
} |
||||||
}, |
}, |
||||||
|
|
||||||
goToNextPage: function() { |
goToNextPage: function() { |
||||||
if (PDFViewer.pageNumber < PDFViewer.numberOfPages) { |
if (PDFViewer.pageNumber < PDFViewer.numberOfPages) { |
||||||
PDFViewer.goToPage(++PDFViewer.pageNumber); |
PDFViewer.goToPage(++PDFViewer.pageNumber); |
||||||
} |
} |
||||||
}, |
}, |
||||||
|
|
||||||
openURL: function(url) { |
|
||||||
PDFViewer.url = url; |
|
||||||
document.title = url; |
|
||||||
|
|
||||||
var req = new XMLHttpRequest(); |
|
||||||
req.open('GET', url); |
|
||||||
req.mozResponseType = req.responseType = 'arraybuffer'; |
|
||||||
req.expected = (document.URL.indexOf('file:') === 0) ? 0 : 200; |
|
||||||
|
|
||||||
req.onreadystatechange = function() { |
|
||||||
if (req.readyState === 4 && req.status === req.expected) { |
|
||||||
var data = req.mozResponseArrayBuffer || |
|
||||||
req.mozResponse || |
|
||||||
req.responseArrayBuffer || |
|
||||||
req.response; |
|
||||||
|
|
||||||
PDFViewer.readPDF(data); |
|
||||||
} |
|
||||||
}; |
|
||||||
|
|
||||||
req.send(null); |
openURL: function(url) { |
||||||
}, |
PDFViewer.url = url; |
||||||
|
document.title = url; |
||||||
|
|
||||||
readPDF: function(data) { |
var req = new XMLHttpRequest(); |
||||||
while (PDFViewer.element.hasChildNodes()) { |
req.open('GET', url); |
||||||
PDFViewer.element.removeChild(PDFViewer.element.firstChild); |
req.mozResponseType = req.responseType = 'arraybuffer'; |
||||||
} |
req.expected = (document.URL.indexOf('file:') === 0) ? 0 : 200; |
||||||
|
|
||||||
PDFViewer.pdf = new PDFDoc(new Stream(data)); |
req.onreadystatechange = function() { |
||||||
PDFViewer.numberOfPages = PDFViewer.pdf.numPages; |
if (req.readyState === 4 && req.status === req.expected) { |
||||||
document.getElementById('numPages').innerHTML = PDFViewer.numberOfPages.toString(); |
var data = req.mozResponseArrayBuffer || req.mozResponse || req.responseArrayBuffer || req.response; |
||||||
|
|
||||||
for (var i = 1; i <= PDFViewer.numberOfPages; i++) { |
PDFViewer.readPDF(data); |
||||||
PDFViewer.createPage(i); |
} |
||||||
} |
}; |
||||||
|
|
||||||
if (PDFViewer.numberOfPages > 0) { |
req.send(null); |
||||||
PDFViewer.drawPage(1); |
}, |
||||||
document.location.hash = 1; |
|
||||||
} |
|
||||||
|
|
||||||
PDFViewer.previousPageButton.className = (PDFViewer.pageNumber === 1) ? |
readPDF: function(data) { |
||||||
'disabled' : ''; |
while (PDFViewer.element.hasChildNodes()) { |
||||||
PDFViewer.nextPageButton.className = (PDFViewer.pageNumber === PDFViewer.numberOfPages) ? |
PDFViewer.element.removeChild(PDFViewer.element.firstChild); |
||||||
'disabled' : ''; |
|
||||||
} |
} |
||||||
|
|
||||||
|
PDFViewer.pdf = new PDFDoc(new Stream(data)); |
||||||
|
PDFViewer.numberOfPages = PDFViewer.pdf.numPages; |
||||||
|
document.getElementById('numPages').innerHTML = PDFViewer.numberOfPages.toString(); |
||||||
|
|
||||||
|
for (var i = 1; i <= PDFViewer.numberOfPages; i++) { |
||||||
|
PDFViewer.createPage(i); |
||||||
|
} |
||||||
|
|
||||||
|
if (PDFViewer.numberOfPages > 0) { |
||||||
|
PDFViewer.drawPage(1); |
||||||
|
document.location.hash = 1; |
||||||
|
} |
||||||
|
|
||||||
|
PDFViewer.previousPageButton.className = (PDFViewer.pageNumber === 1) ? 'disabled' : ''; |
||||||
|
PDFViewer.nextPageButton.className = (PDFViewer.pageNumber === PDFViewer.numberOfPages) ? 'disabled' : ''; |
||||||
|
} |
||||||
}; |
}; |
||||||
|
|
||||||
window.onload = function() { |
window.onload = function() { |
||||||
|
|
||||||
// Parse the URL query parameters into a cached object.
|
// Parse the URL query parameters into a cached object.
|
||||||
PDFViewer.queryParams = function() { |
PDFViewer.queryParams = function() { |
||||||
var qs = window.location.search.substring(1); |
var qs = window.location.search.substring(1); |
||||||
var kvs = qs.split('&'); |
var kvs = qs.split('&'); |
||||||
var params = {}; |
var params = {}; |
||||||
for (var i = 0; i < kvs.length; ++i) { |
|
||||||
var kv = kvs[i].split('='); |
|
||||||
params[unescape(kv[0])] = unescape(kv[1]); |
|
||||||
} |
|
||||||
|
|
||||||
return params; |
for (var i = 0; i < kvs.length; ++i) { |
||||||
}(); |
var kv = kvs[i].split('='); |
||||||
|
params[unescape(kv[0])] = unescape(kv[1]); |
||||||
|
} |
||||||
|
|
||||||
PDFViewer.element = document.getElementById('viewer'); |
return params; |
||||||
|
}(); |
||||||
|
|
||||||
PDFViewer.pageNumberInput = document.getElementById('pageNumber'); |
PDFViewer.element = document.getElementById('viewer'); |
||||||
PDFViewer.pageNumberInput.onkeydown = function(evt) { |
|
||||||
var charCode = evt.charCode || evt.keyCode; |
|
||||||
|
|
||||||
// Up arrow key.
|
PDFViewer.pageNumberInput = document.getElementById('pageNumber'); |
||||||
if (charCode === 38) { |
PDFViewer.pageNumberInput.onkeydown = function(evt) { |
||||||
PDFViewer.goToNextPage(); |
var charCode = evt.charCode || evt.keyCode; |
||||||
this.select(); |
|
||||||
} |
|
||||||
|
|
||||||
// Down arrow key.
|
// Up arrow key.
|
||||||
else if (charCode === 40) { |
if (charCode === 38) { |
||||||
PDFViewer.goToPreviousPage(); |
PDFViewer.goToNextPage(); |
||||||
this.select(); |
this.select(); |
||||||
} |
} |
||||||
|
|
||||||
// All other non-numeric keys (excluding Left arrow, Right arrow,
|
// Down arrow key.
|
||||||
// Backspace, and Delete keys).
|
else if (charCode === 40) { |
||||||
else if ((charCode < 48 || charCode > 57) && |
PDFViewer.goToPreviousPage(); |
||||||
charCode !== 8 && // Backspace
|
this.select(); |
||||||
charCode !== 46 && // Delete
|
} |
||||||
charCode !== 37 && // Left arrow
|
|
||||||
charCode !== 39 // Right arrow
|
|
||||||
) { |
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
return true; |
// All other non-numeric keys (excluding Left arrow, Right arrow,
|
||||||
}; |
// Backspace, and Delete keys).
|
||||||
PDFViewer.pageNumberInput.onkeyup = function(evt) { |
else if ((charCode < 48 || charCode > 57) && |
||||||
var charCode = evt.charCode || evt.keyCode; |
charCode !== 8 && // Backspace
|
||||||
|
charCode !== 46 && // Delete
|
||||||
// All numeric keys, Backspace, and Delete.
|
charCode !== 37 && // Left arrow
|
||||||
if ((charCode >= 48 && charCode <= 57) || |
charCode !== 39 // Right arrow
|
||||||
charCode === 8 || // Backspace
|
) { |
||||||
charCode === 46 // Delete
|
return false; |
||||||
) { |
} |
||||||
PDFViewer.goToPage(this.value); |
|
||||||
} |
|
||||||
|
|
||||||
this.focus(); |
return true; |
||||||
}; |
}; |
||||||
|
PDFViewer.pageNumberInput.onkeyup = function(evt) { |
||||||
|
var charCode = evt.charCode || evt.keyCode; |
||||||
|
|
||||||
|
// All numeric keys, Backspace, and Delete.
|
||||||
|
if ((charCode >= 48 && charCode <= 57) || |
||||||
|
charCode === 8 || // Backspace
|
||||||
|
charCode === 46 // Delete
|
||||||
|
) { |
||||||
|
PDFViewer.goToPage(this.value); |
||||||
|
} |
||||||
|
|
||||||
PDFViewer.previousPageButton = document.getElementById('previousPageButton'); |
this.focus(); |
||||||
PDFViewer.previousPageButton.onclick = function(evt) { |
}; |
||||||
if (this.className.indexOf('disabled') === -1) { |
|
||||||
PDFViewer.goToPreviousPage(); |
|
||||||
} |
|
||||||
}; |
|
||||||
PDFViewer.previousPageButton.onmousedown = function(evt) { |
|
||||||
if (this.className.indexOf('disabled') === -1) { |
|
||||||
this.className = 'down'; |
|
||||||
} |
|
||||||
}; |
|
||||||
PDFViewer.previousPageButton.onmouseup = function(evt) { |
|
||||||
this.className = (this.className.indexOf('disabled') !== -1) ? 'disabled' : ''; |
|
||||||
}; |
|
||||||
PDFViewer.previousPageButton.onmouseout = function(evt) { |
|
||||||
this.className = (this.className.indexOf('disabled') !== -1) ? 'disabled' : ''; |
|
||||||
}; |
|
||||||
|
|
||||||
PDFViewer.nextPageButton = document.getElementById('nextPageButton'); |
PDFViewer.previousPageButton = document.getElementById('previousPageButton'); |
||||||
PDFViewer.nextPageButton.onclick = function(evt) { |
PDFViewer.previousPageButton.onclick = function(evt) { |
||||||
if (this.className.indexOf('disabled') === -1) { |
if (this.className.indexOf('disabled') === -1) { |
||||||
PDFViewer.goToNextPage(); |
PDFViewer.goToPreviousPage(); |
||||||
} |
} |
||||||
}; |
}; |
||||||
PDFViewer.nextPageButton.onmousedown = function(evt) { |
PDFViewer.previousPageButton.onmousedown = function(evt) { |
||||||
if (this.className.indexOf('disabled') === -1) { |
if (this.className.indexOf('disabled') === -1) { |
||||||
this.className = 'down'; |
this.className = 'down'; |
||||||
} |
} |
||||||
|
}; |
||||||
|
PDFViewer.previousPageButton.onmouseup = function(evt) { |
||||||
|
this.className = (this.className.indexOf('disabled') !== -1) ? 'disabled' : ''; |
||||||
|
}; |
||||||
|
PDFViewer.previousPageButton.onmouseout = function(evt) { |
||||||
|
this.className = (this.className.indexOf('disabled') !== -1) ? 'disabled' : ''; |
||||||
|
}; |
||||||
|
|
||||||
|
PDFViewer.nextPageButton = document.getElementById('nextPageButton'); |
||||||
|
PDFViewer.nextPageButton.onclick = function(evt) { |
||||||
|
if (this.className.indexOf('disabled') === -1) { |
||||||
|
PDFViewer.goToNextPage(); |
||||||
|
} |
||||||
|
}; |
||||||
|
PDFViewer.nextPageButton.onmousedown = function(evt) { |
||||||
|
if (this.className.indexOf('disabled') === -1) { |
||||||
|
this.className = 'down'; |
||||||
|
} |
||||||
|
}; |
||||||
|
PDFViewer.nextPageButton.onmouseup = function(evt) { |
||||||
|
this.className = (this.className.indexOf('disabled') !== -1) ? 'disabled' : ''; |
||||||
|
}; |
||||||
|
PDFViewer.nextPageButton.onmouseout = function(evt) { |
||||||
|
this.className = (this.className.indexOf('disabled') !== -1) ? 'disabled' : ''; |
||||||
|
}; |
||||||
|
|
||||||
|
PDFViewer.scaleSelect = document.getElementById('scaleSelect'); |
||||||
|
PDFViewer.scaleSelect.onchange = function(evt) { |
||||||
|
PDFViewer.changeScale(parseInt(this.value)); |
||||||
|
}; |
||||||
|
|
||||||
|
if (window.File && window.FileReader && window.FileList && window.Blob) { |
||||||
|
var openFileButton = document.getElementById('openFileButton'); |
||||||
|
openFileButton.onclick = function(evt) { |
||||||
|
if (this.className.indexOf('disabled') === -1) { |
||||||
|
PDFViewer.fileInput.click(); |
||||||
|
} |
||||||
}; |
}; |
||||||
PDFViewer.nextPageButton.onmouseup = function(evt) { |
openFileButton.onmousedown = function(evt) { |
||||||
this.className = (this.className.indexOf('disabled') !== -1) ? 'disabled' : ''; |
if (this.className.indexOf('disabled') === -1) { |
||||||
|
this.className = 'down'; |
||||||
|
} |
||||||
}; |
}; |
||||||
PDFViewer.nextPageButton.onmouseout = function(evt) { |
openFileButton.onmouseup = function(evt) { |
||||||
this.className = (this.className.indexOf('disabled') !== -1) ? 'disabled' : ''; |
this.className = (this.className.indexOf('disabled') !== -1) ? 'disabled' : ''; |
||||||
}; |
}; |
||||||
|
openFileButton.onmouseout = function(evt) { |
||||||
PDFViewer.scaleSelect = document.getElementById('scaleSelect'); |
this.className = (this.className.indexOf('disabled') !== -1) ? 'disabled' : ''; |
||||||
PDFViewer.scaleSelect.onchange = function(evt) { |
|
||||||
PDFViewer.changeScale(parseInt(this.value)); |
|
||||||
}; |
}; |
||||||
|
|
||||||
if (window.File && window.FileReader && window.FileList && window.Blob) { |
PDFViewer.fileInput = document.getElementById('fileInput'); |
||||||
var openFileButton = document.getElementById('openFileButton'); |
PDFViewer.fileInput.onchange = function(evt) { |
||||||
openFileButton.onclick = function(evt) { |
var files = evt.target.files; |
||||||
if (this.className.indexOf('disabled') === -1) { |
|
||||||
PDFViewer.fileInput.click(); |
|
||||||
} |
|
||||||
}; |
|
||||||
openFileButton.onmousedown = function(evt) { |
|
||||||
if (this.className.indexOf('disabled') === -1) { |
|
||||||
this.className = 'down'; |
|
||||||
} |
|
||||||
}; |
|
||||||
openFileButton.onmouseup = function(evt) { |
|
||||||
this.className = (this.className.indexOf('disabled') !== -1) ? 'disabled' : ''; |
|
||||||
}; |
|
||||||
openFileButton.onmouseout = function(evt) { |
|
||||||
this.className = (this.className.indexOf('disabled') !== -1) ? 'disabled' : ''; |
|
||||||
}; |
|
||||||
|
|
||||||
PDFViewer.fileInput = document.getElementById('fileInput'); |
|
||||||
PDFViewer.fileInput.onchange = function(evt) { |
|
||||||
var files = evt.target.files; |
|
||||||
|
|
||||||
if (files.length > 0) { |
|
||||||
var file = files[0]; |
|
||||||
var fileReader = new FileReader(); |
|
||||||
|
|
||||||
document.title = file.name; |
if (files.length > 0) { |
||||||
|
var file = files[0]; |
||||||
|
var fileReader = new FileReader(); |
||||||
|
|
||||||
// Read the local file into a Uint8Array.
|
document.title = file.name; |
||||||
fileReader.onload = function(evt) { |
|
||||||
var data = evt.target.result; |
|
||||||
var buffer = new ArrayBuffer(data.length); |
|
||||||
var uint8Array = new Uint8Array(buffer); |
|
||||||
|
|
||||||
for (var i = 0; i < data.length; i++) { |
// Read the local file into a Uint8Array.
|
||||||
uint8Array[i] = data.charCodeAt(i); |
fileReader.onload = function(evt) { |
||||||
} |
var data = evt.target.result; |
||||||
|
var buffer = new ArrayBuffer(data.length); |
||||||
|
var uint8Array = new Uint8Array(buffer); |
||||||
|
|
||||||
PDFViewer.readPDF(uint8Array); |
for (var i = 0; i < data.length; i++) { |
||||||
}; |
uint8Array[i] = data.charCodeAt(i); |
||||||
|
} |
||||||
|
|
||||||
// Read as a binary string since "readAsArrayBuffer" is not yet
|
PDFViewer.readPDF(uint8Array); |
||||||
// implemented in Firefox.
|
|
||||||
fileReader.readAsBinaryString(file); |
|
||||||
} |
|
||||||
}; |
}; |
||||||
PDFViewer.fileInput.value = null; |
|
||||||
} else { |
|
||||||
document.getElementById('fileWrapper').style.display = 'none'; |
|
||||||
} |
|
||||||
|
|
||||||
PDFViewer.pageNumber = parseInt(PDFViewer.queryParams.page) || PDFViewer.pageNumber; |
|
||||||
PDFViewer.scale = parseInt(PDFViewer.scaleSelect.value) / 100 || 1.0; |
|
||||||
|
|
||||||
PDFViewer.openURL(PDFViewer.queryParams.file || PDFViewer.url); |
|
||||||
|
|
||||||
window.onscroll = function(evt) { |
|
||||||
var lastPagesDrawn = PDFViewer.lastPagesDrawn; |
|
||||||
var visiblePages = PDFViewer.visiblePages(); |
|
||||||
|
|
||||||
var pagesToDraw = []; |
// Read as a binary string since "readAsArrayBuffer" is not yet
|
||||||
var pagesToKeep = []; |
// implemented in Firefox.
|
||||||
var pagesToRemove = []; |
fileReader.readAsBinaryString(file); |
||||||
|
} |
||||||
var i; |
}; |
||||||
|
PDFViewer.fileInput.value = null; |
||||||
|
} else { |
||||||
|
document.getElementById('fileWrapper').style.display = 'none'; |
||||||
|
} |
||||||
|
|
||||||
|
PDFViewer.pageNumber = parseInt(PDFViewer.queryParams.page) || PDFViewer.pageNumber; |
||||||
|
PDFViewer.scale = parseInt(PDFViewer.scaleSelect.value) / 100 || 1.0; |
||||||
|
|
||||||
|
PDFViewer.openURL(PDFViewer.queryParams.file || PDFViewer.url); |
||||||
|
|
||||||
|
window.onscroll = function(evt) { |
||||||
|
var lastPagesDrawn = PDFViewer.lastPagesDrawn; |
||||||
|
var visiblePages = PDFViewer.visiblePages(); |
||||||
|
|
||||||
|
var pagesToDraw = []; |
||||||
|
var pagesToKeep = []; |
||||||
|
var pagesToRemove = []; |
||||||
|
|
||||||
|
var i; |
||||||
|
|
||||||
|
// Determine which visible pages were not previously drawn.
|
||||||
|
for (i = 0; i < visiblePages.length; i++) { |
||||||
|
if (lastPagesDrawn.indexOf(visiblePages[i]) === -1) { |
||||||
|
pagesToDraw.push(visiblePages[i]); |
||||||
|
PDFViewer.drawPage(visiblePages[i]); |
||||||
|
} else { |
||||||
|
pagesToKeep.push(visiblePages[i]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
// Determine which visible pages were not previously drawn.
|
// Determine which previously drawn pages are no longer visible.
|
||||||
for (i = 0; i < visiblePages.length; i++) { |
for (i = 0; i < lastPagesDrawn.length; i++) { |
||||||
if (lastPagesDrawn.indexOf(visiblePages[i]) === -1) { |
if (visiblePages.indexOf(lastPagesDrawn[i]) === -1) { |
||||||
pagesToDraw.push(visiblePages[i]); |
pagesToRemove.push(lastPagesDrawn[i]); |
||||||
PDFViewer.drawPage(visiblePages[i]); |
PDFViewer.removePage(lastPagesDrawn[i]); |
||||||
} else { |
} |
||||||
pagesToKeep.push(visiblePages[i]); |
} |
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
// Determine which previously drawn pages are no longer visible.
|
PDFViewer.lastPagesDrawn = pagesToDraw.concat(pagesToKeep); |
||||||
for (i = 0; i < lastPagesDrawn.length; i++) { |
|
||||||
if (visiblePages.indexOf(lastPagesDrawn[i]) === -1) { |
|
||||||
pagesToRemove.push(lastPagesDrawn[i]); |
|
||||||
PDFViewer.removePage(lastPagesDrawn[i]); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
PDFViewer.lastPagesDrawn = pagesToDraw.concat(pagesToKeep); |
// Update the page number input with the current page number.
|
||||||
|
if (!PDFViewer.willJumpToPage && visiblePages.length > 0) { |
||||||
// Update the page number input with the current page number.
|
PDFViewer.pageNumber = PDFViewer.pageNumberInput.value = visiblePages[0]; |
||||||
if (!PDFViewer.willJumpToPage && visiblePages.length > 0) { |
PDFViewer.previousPageButton.className = (PDFViewer.pageNumber === 1) ? 'disabled' : ''; |
||||||
PDFViewer.pageNumber = PDFViewer.pageNumberInput.value = visiblePages[0]; |
PDFViewer.nextPageButton.className = (PDFViewer.pageNumber === PDFViewer.numberOfPages) ? 'disabled' : ''; |
||||||
PDFViewer.previousPageButton.className = (PDFViewer.pageNumber === 1) ? |
} else { |
||||||
'disabled' : ''; |
PDFViewer.willJumpToPage = false; |
||||||
PDFViewer.nextPageButton.className = (PDFViewer.pageNumber === PDFViewer.numberOfPages) ? |
} |
||||||
'disabled' : ''; |
}; |
||||||
} else { |
|
||||||
PDFViewer.willJumpToPage = false; |
|
||||||
} |
|
||||||
}; |
|
||||||
}; |
}; |
||||||
|
Loading…
Reference in new issue