|
|
|
@ -116,16 +116,19 @@ var RenderingQueue = (function RenderingQueueClosure() {
@@ -116,16 +116,19 @@ var RenderingQueue = (function RenderingQueueClosure() {
|
|
|
|
|
var FirefoxCom = (function FirefoxComClosure() { |
|
|
|
|
return { |
|
|
|
|
/** |
|
|
|
|
* Creates an event that hopefully the extension is listening for and will |
|
|
|
|
* Creates an event that the extension is listening for and will |
|
|
|
|
* synchronously respond to. |
|
|
|
|
* NOTE: It is reccomended to use request() instead since one day we may not |
|
|
|
|
* be able to synchronously reply. |
|
|
|
|
* @param {String} action The action to trigger. |
|
|
|
|
* @param {String} data Optional data to send. |
|
|
|
|
* @return {*} The response. |
|
|
|
|
*/ |
|
|
|
|
request: function(action, data) { |
|
|
|
|
requestSync: function(action, data) { |
|
|
|
|
var request = document.createTextNode(''); |
|
|
|
|
request.setUserData('action', action, null); |
|
|
|
|
request.setUserData('data', data, null); |
|
|
|
|
request.setUserData('sync', true, null); |
|
|
|
|
document.documentElement.appendChild(request); |
|
|
|
|
|
|
|
|
|
var sender = document.createEvent('Events'); |
|
|
|
@ -134,6 +137,39 @@ var FirefoxCom = (function FirefoxComClosure() {
@@ -134,6 +137,39 @@ var FirefoxCom = (function FirefoxComClosure() {
|
|
|
|
|
var response = request.getUserData('response'); |
|
|
|
|
document.documentElement.removeChild(request); |
|
|
|
|
return response; |
|
|
|
|
}, |
|
|
|
|
/** |
|
|
|
|
* Creates an event that the extension is listening for and will |
|
|
|
|
* asynchronously respond by calling the callback. |
|
|
|
|
* @param {String} action The action to trigger. |
|
|
|
|
* @param {String} data Optional data to send. |
|
|
|
|
* @param {Function} callback Optional response callback that will be called |
|
|
|
|
* with one data argument. |
|
|
|
|
*/ |
|
|
|
|
request: function(action, data, callback) { |
|
|
|
|
var request = document.createTextNode(''); |
|
|
|
|
request.setUserData('action', action, null); |
|
|
|
|
request.setUserData('data', data, null); |
|
|
|
|
request.setUserData('sync', false, null); |
|
|
|
|
if (callback) { |
|
|
|
|
request.setUserData('callback', callback, null); |
|
|
|
|
|
|
|
|
|
document.addEventListener('pdf.js.response', function listener(event) { |
|
|
|
|
var node = event.target, |
|
|
|
|
callback = node.getUserData('callback'), |
|
|
|
|
response = node.getUserData('response'); |
|
|
|
|
|
|
|
|
|
document.documentElement.removeChild(node); |
|
|
|
|
|
|
|
|
|
document.removeEventListener('pdf.js.response', listener, false); |
|
|
|
|
return callback(response); |
|
|
|
|
}, false); |
|
|
|
|
} |
|
|
|
|
document.documentElement.appendChild(request); |
|
|
|
|
|
|
|
|
|
var sender = document.createEvent('HTMLEvents'); |
|
|
|
|
sender.initEvent('pdf.js.message', true, false); |
|
|
|
|
return request.dispatchEvent(sender); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
})(); |
|
|
|
@ -160,7 +196,7 @@ var Settings = (function SettingsClosure() {
@@ -160,7 +196,7 @@ var Settings = (function SettingsClosure() {
|
|
|
|
|
var database = null; |
|
|
|
|
var index; |
|
|
|
|
if (isFirefoxExtension) |
|
|
|
|
database = FirefoxCom.request('getDatabase', null) || '{}'; |
|
|
|
|
database = FirefoxCom.requestSync('getDatabase', null) || '{}'; |
|
|
|
|
else if (isLocalStorageEnabled) |
|
|
|
|
database = localStorage.getItem('database') || '{}'; |
|
|
|
|
else |
|
|
|
@ -193,7 +229,7 @@ var Settings = (function SettingsClosure() {
@@ -193,7 +229,7 @@ var Settings = (function SettingsClosure() {
|
|
|
|
|
file[name] = val; |
|
|
|
|
var database = JSON.stringify(this.database); |
|
|
|
|
if (isFirefoxExtension) |
|
|
|
|
FirefoxCom.request('setDatabase', database); |
|
|
|
|
FirefoxCom.requestSync('setDatabase', database); |
|
|
|
|
else if (isLocalStorageEnabled) |
|
|
|
|
localStorage.setItem('database', database); |
|
|
|
|
}, |
|
|
|
@ -224,6 +260,7 @@ var PDFView = {
@@ -224,6 +260,7 @@ var PDFView = {
|
|
|
|
|
container: null, |
|
|
|
|
initialized: false, |
|
|
|
|
fellback: false, |
|
|
|
|
pdfDocument: null, |
|
|
|
|
// called once when the document is loaded
|
|
|
|
|
initialize: function pdfViewInitialize() { |
|
|
|
|
this.container = document.getElementById('viewerContainer'); |
|
|
|
@ -348,6 +385,7 @@ var PDFView = {
@@ -348,6 +385,7 @@ var PDFView = {
|
|
|
|
|
PDFView.loadingBar = new ProgressBar('#loadingBar', {}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.pdfDocument = null; |
|
|
|
|
var self = this; |
|
|
|
|
self.loading = true; |
|
|
|
|
PDFJS.getDocument(parameters).then( |
|
|
|
@ -384,9 +422,37 @@ var PDFView = {
@@ -384,9 +422,37 @@ var PDFView = {
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
download: function pdfViewDownload() { |
|
|
|
|
function noData() { |
|
|
|
|
FirefoxCom.request('download', { originalUrl: url }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var url = this.url.split('#')[0]; |
|
|
|
|
if (PDFJS.isFirefoxExtension) { |
|
|
|
|
FirefoxCom.request('download', url); |
|
|
|
|
// Document isn't ready just try to download with the url.
|
|
|
|
|
if (!this.pdfDocument) { |
|
|
|
|
noData(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
this.pdfDocument.getData().then( |
|
|
|
|
function getDataSuccess(data) { |
|
|
|
|
var bb = new MozBlobBuilder(); |
|
|
|
|
bb.append(data.buffer); |
|
|
|
|
var blobUrl = window.URL.createObjectURL( |
|
|
|
|
bb.getBlob('application/pdf')); |
|
|
|
|
|
|
|
|
|
FirefoxCom.request('download', { blobUrl: blobUrl, originalUrl: url }, |
|
|
|
|
function response(err) { |
|
|
|
|
if (err) { |
|
|
|
|
// This error won't really be helpful because it's likely the
|
|
|
|
|
// fallback won't work either (or is already open).
|
|
|
|
|
PDFView.error('PDF failed to download.'); |
|
|
|
|
} |
|
|
|
|
window.URL.revokeObjectURL(blobUrl); |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
noData // Error ocurred try downloading with just the url.
|
|
|
|
|
); |
|
|
|
|
} else { |
|
|
|
|
url += '#pdfjs.action=download', '_parent'; |
|
|
|
|
window.open(url, '_parent'); |
|
|
|
@ -544,6 +610,8 @@ var PDFView = {
@@ -544,6 +610,8 @@ var PDFView = {
|
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.pdfDocument = pdfDocument; |
|
|
|
|
|
|
|
|
|
var errorWrapper = document.getElementById('errorWrapper'); |
|
|
|
|
errorWrapper.setAttribute('hidden', 'true'); |
|
|
|
|
|
|
|
|
@ -1520,7 +1588,7 @@ window.addEventListener('load', function webViewerLoad(evt) {
@@ -1520,7 +1588,7 @@ window.addEventListener('load', function webViewerLoad(evt) {
|
|
|
|
|
PDFJS.disableTextLayer = (hashParams['disableTextLayer'] === 'true'); |
|
|
|
|
|
|
|
|
|
if ('pdfBug' in hashParams && |
|
|
|
|
(!PDFJS.isFirefoxExtension || FirefoxCom.request('pdfBugEnabled'))) { |
|
|
|
|
(!PDFJS.isFirefoxExtension || FirefoxCom.requestSync('pdfBugEnabled'))) { |
|
|
|
|
PDFJS.pdfBug = true; |
|
|
|
|
var pdfBug = hashParams['pdfBug']; |
|
|
|
|
var enabled = pdfBug.split(','); |
|
|
|
@ -1529,7 +1597,7 @@ window.addEventListener('load', function webViewerLoad(evt) {
@@ -1529,7 +1597,7 @@ window.addEventListener('load', function webViewerLoad(evt) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!PDFJS.isFirefoxExtension || |
|
|
|
|
(PDFJS.isFirefoxExtension && FirefoxCom.request('searchEnabled'))) { |
|
|
|
|
(PDFJS.isFirefoxExtension && FirefoxCom.requestSync('searchEnabled'))) { |
|
|
|
|
document.querySelector('#viewSearch').classList.remove('hidden'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|