-
-
Notifications
You must be signed in to change notification settings - Fork 7
feat(PdfViewer): add UseGoogleDocs parameter #454
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
Changes from 1 commit
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 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,8 +8,7 @@ export async function init(id, invoke, options) { | |||||||||||||
| const pdfViewer = { el, invoke, options }; | ||||||||||||||
| Data.set(id, pdfViewer); | ||||||||||||||
|
|
||||||||||||||
| const url = el.getAttribute('data-bb-url'); | ||||||||||||||
| await loadPdf(id, url); | ||||||||||||||
| await loadPdf(id, options.url); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| export async function loadPdf(id, url) { | ||||||||||||||
|
|
@@ -21,6 +20,9 @@ export async function loadPdf(id, url) { | |||||||||||||
| return; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| delete pdfViewer.frame; | ||||||||||||||
| el.innerHTML = ''; | ||||||||||||||
|
|
||||||||||||||
| if (url) { | ||||||||||||||
| const { frame } = pdfViewer; | ||||||||||||||
| const viewer = frame || createFrame(el); | ||||||||||||||
|
|
@@ -29,12 +31,13 @@ export async function loadPdf(id, url) { | |||||||||||||
| invoke.invokeMethodAsync(options.loadedCallaback); | ||||||||||||||
| }; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| const useGoogleDocs = el.getAttribute('data-bb-google-docs') === 'true'; | ||||||||||||||
| if (useGoogleDocs) { | ||||||||||||||
| url = `http://docs.google.com/viewer?url=${url}` | ||||||||||||||
|
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. issue (code-quality): Don't reassign parameter - url ( ExplanationReassigning parameters can lead to unexpected behavior, especially when accessing the arguments object. It can also cause optimization issues, especially in V8.From the Airbnb JavaScript Style Guide |
||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+36
to
+38
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. suggestion (bug_risk): Use HTTPS and encode URL when loading Google Docs viewer Update the protocol to
Suggested change
|
||||||||||||||
| viewer.src = url; | ||||||||||||||
| } | ||||||||||||||
| else { | ||||||||||||||
| delete pdfViewer.frame; | ||||||||||||||
| el.innerHTML = ''; | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| const createFrame = el => { | ||||||||||||||
|
|
||||||||||||||
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.
issue (complexity): Consider removing the unused property and simplifying the rerender logic in OnAfterRenderAsync with a single if/else block.
These two changes preserve all behavior while removing dead code and flattening the rerender logic.