-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display a notification on the sidebarToggle
button for PDF documents with outline/attachments
#7959
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -51,16 +51,26 @@ var PDFAttachmentViewer = (function PDFAttachmentViewerClosure() { | |||
this.container = options.container; | ||||
this.eventBus = options.eventBus; | ||||
this.downloadManager = options.downloadManager; | ||||
|
||||
this._renderedCapability = pdfjsLib.createPromiseCapability(); | ||||
this.eventBus.on('fileattachmentannotation', | ||||
this._appendAttachment.bind(this)); | ||||
} | ||||
|
||||
PDFAttachmentViewer.prototype = { | ||||
reset: function PDFAttachmentViewer_reset() { | ||||
reset: function PDFAttachmentViewer_reset(keepRenderedCapability) { | ||||
this.attachments = null; | ||||
|
||||
var container = this.container; | ||||
while (container.firstChild) { | ||||
container.removeChild(container.firstChild); | ||||
} | ||||
|
||||
if (!keepRenderedCapability) { | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you elaborate a bit on why we need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to make sure that we're on the same page, a bit of background first: Now, when resetting Since this isn't an option that anyone should pass in when using Line 595 in a917443
Sorry, this became a bit long. Hopefully it's enough to answer your question! Edit: It just occurred to me that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I now understand why we need to have this. Indeed, an inline comment (and no JSDoc comment) would be helpful to avoid any confusion. I'm also fine with moving the option to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Addressed in the latest version of the PR; please do let me know if the comment isn't clear enough! |
||||
// NOTE: The *only* situation in which the `_renderedCapability` should | ||||
// not be replaced is when appending file attachment annotations. | ||||
this._renderedCapability = pdfjsLib.createPromiseCapability(); | ||||
} | ||||
}, | ||||
|
||||
/** | ||||
|
@@ -70,8 +80,10 @@ var PDFAttachmentViewer = (function PDFAttachmentViewerClosure() { | |||
function PDFAttachmentViewer_dispatchEvent(attachmentsCount) { | ||||
this.eventBus.dispatch('attachmentsloaded', { | ||||
source: this, | ||||
attachmentsCount: attachmentsCount | ||||
attachmentsCount: attachmentsCount, | ||||
}); | ||||
|
||||
this._renderedCapability.resolve(); | ||||
}, | ||||
|
||||
/** | ||||
|
@@ -89,11 +101,13 @@ var PDFAttachmentViewer = (function PDFAttachmentViewerClosure() { | |||
* @param {PDFAttachmentViewerRenderParameters} params | ||||
*/ | ||||
render: function PDFAttachmentViewer_render(params) { | ||||
var attachments = (params && params.attachments) || null; | ||||
params = params || {}; | ||||
var attachments = params.attachments || null; | ||||
var attachmentsCount = 0; | ||||
|
||||
if (this.attachments) { | ||||
this.reset(); | ||||
var keepRenderedCapability = params.keepRenderedCapability === true; | ||||
this.reset(keepRenderedCapability); | ||||
} | ||||
this.attachments = attachments; | ||||
|
||||
|
@@ -120,7 +134,35 @@ var PDFAttachmentViewer = (function PDFAttachmentViewerClosure() { | |||
} | ||||
|
||||
this._dispatchEvent(attachmentsCount); | ||||
} | ||||
}, | ||||
|
||||
/** | ||||
* Used to append FileAttachment annotations to the sidebar. | ||||
* @private | ||||
*/ | ||||
_appendAttachment: function PDFAttachmentViewer_appendAttachment(item) { | ||||
this._renderedCapability.promise.then(function (id, filename, content) { | ||||
var attachments = this.attachments; | ||||
|
||||
if (!attachments) { | ||||
attachments = Object.create(null); | ||||
} else { | ||||
for (var name in attachments) { | ||||
if (id === name) { | ||||
return; // Ignore the new attachment if it already exists. | ||||
} | ||||
} | ||||
} | ||||
attachments[id] = { | ||||
filename: filename, | ||||
content: content, | ||||
}; | ||||
this.render({ | ||||
attachments: attachments, | ||||
keepRenderedCapability: true, | ||||
}); | ||||
}.bind(this, item.id, item.filename, item.content)); | ||||
}, | ||||
}; | ||||
|
||||
return PDFAttachmentViewer; | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused why we don't use
this.filename
andthis.content
in these three lines instead. Especially the file name has been sanitized then.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to make sure that what we (eventually) pass on to
pdf_attachment_viewer.js
has the exact same format as whatPDFDocumentProxy_getAttachments
returns, by explicitly using the file attachment data from the API side here, to avoid any possible issues/surprises later on.Please note that we already need to use
getFilenameFromUrl
inpdf_attachment_viewer.js
, so using it here as well does not help us much and again wouldn't be compatible with what we get fromPDFDocumentProxy_getAttachments
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the intention now, thanks!