-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #466 from stevenjoezhang/pdfjs
New Feature: PDFObject and PDF.js support
- Loading branch information
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{% if theme.pdf.enable %} | ||
{% set is_index_has_pdf = false %} | ||
|
||
{# At home, check if there has `pdf: true` post #} | ||
{% if is_home() %} | ||
{% for post in page.posts %} | ||
{% if post.pdf and not is_index_has_pdf %} | ||
{% set is_index_has_pdf = true %} | ||
{% endif %} | ||
{% endfor %} | ||
{% endif %} | ||
|
||
{% if not theme.pdf.per_page or (is_index_has_pdf or page.pdf) %} | ||
<script type="text/javascript" src="{{ theme.pdf.pdfobject.cdn }}"></script> | ||
<script type="text/javascript"> | ||
var options = { | ||
pdfOpenParams: { | ||
navpanes: 0, | ||
toolbar: 0, | ||
statusbar: 0, | ||
pagemode: "thumbs", | ||
view: "FitV" | ||
}, | ||
PDFJS_URL: "/lib/pdf/web/viewer.html", | ||
height: "{{ theme.pdf.pdfobject.height }}" | ||
}; | ||
$("#main a").each(function() { | ||
var href = $(this).attr("href"); | ||
if (!href) return; | ||
if (href.endsWith(".pdf") || href.endsWith(".pdf/")) { | ||
var id = "pdf" + Math.floor(Math.random() * 10000); | ||
$(this).after("<div id='" + id + "'></div>").remove(); | ||
PDFObject.embed(href, "#" + id, options); | ||
} | ||
}); | ||
</script> | ||
<style> | ||
.pdfobject-container { | ||
position: relative; | ||
overflow: auto; | ||
width: 100%; | ||
height: {{ theme.pdf.pdfobject.height }}; | ||
} | ||
</style> | ||
{% endif %} | ||
{% endif %} |