Make viewer.js compatible with the content type handler addon

This commit is contained in:
Vivien Nicolas 2011-07-26 16:11:09 +02:00
parent 1af6732ba9
commit f1a8a98757

View File

@ -29,6 +29,9 @@ function queryParams() {
function open(url) { function open(url) {
document.title = url; document.title = url;
if (url.indexOf("http") == 0)
return;
var req = new XMLHttpRequest(); var req = new XMLHttpRequest();
req.open('GET', url); req.open('GET', url);
req.mozResponseType = req.responseType = 'arraybuffer'; req.mozResponseType = req.responseType = 'arraybuffer';
@ -37,13 +40,21 @@ function open(url) {
if (req.readyState == 4 && req.status == req.expected) { if (req.readyState == 4 && req.status == req.expected) {
var data = (req.mozResponseArrayBuffer || req.mozResponse || var data = (req.mozResponseArrayBuffer || req.mozResponse ||
req.responseArrayBuffer || req.response); req.responseArrayBuffer || req.response);
loadDocument(data);
}
};
req.send(null);
}
window.addEventListener("pdfloaded", function(aEvent) {
loadDocument(aEvent.detail);
}, true);
function loadDocument(data) {
pdfDocument = new PDFDoc(new Stream(data)); pdfDocument = new PDFDoc(new Stream(data));
numPages = pdfDocument.numPages; numPages = pdfDocument.numPages;
document.getElementById('numPages').innerHTML = numPages.toString(); document.getElementById('numPages').innerHTML = numPages.toString();
goToPage(pageNum); goToPage(pageNum);
}
};
req.send(null);
} }
function gotoPage(num) { function gotoPage(num) {