Skip to content

Commit

Permalink
Merge pull request #43 from alan16742/master
Browse files Browse the repository at this point in the history
支持pdf预览
  • Loading branch information
vcheckzen authored Jul 30, 2024
2 parents 5e5a18b + 484c575 commit c3737d0
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions front-end/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,8 @@
].contains(suffix)
) {
return "office";
} else if (["pdf"].contains(suffix)) {
return "pdf";
} else if (["md"].contains(suffix)) {
return "markdown";
}
Expand Down Expand Up @@ -1183,6 +1185,30 @@
content.appendChild(iframe);
}
break;
case "pdf":
const pdfOnline =
// "pdfjs/web/viewer.html?file=" +
"//mozilla.github.io/pdf.js/web/viewer.html?file=" +
encodeURIComponent(url);
let pdfDiv = document.createElement("div");
pdfDiv.style.lineHeight = "2em";
pdfDiv.style.background = "rgba(218, 215, 215, 0.21)";
pdfDiv.style.webkitTapHighlightColor = "rgba(0, 0, 0, 0)";
pdfDiv.style.cursor = "pointer";
pdfDiv.style.textAlign = "center";
pdfDiv.innerHTML = "新窗口打开";
pdfDiv.addEventListener("click", () => window.open(pdfOnline));
content.innerHTML = "";
content.appendChild(pdfDiv);
if (document.body.clientWidth >= 480) {
let pdfIframe = document.createElement("iframe");
pdfIframe.width = "100%";
pdfIframe.style.height = "41em";
pdfIframe.style.border = "0";
pdfIframe.src = pdfOnline;
content.appendChild(pdfIframe);
}
break;
default:
let textWrapper = document.createElement("div");
textWrapper.style.textAlign = "center";
Expand Down

0 comments on commit c3737d0

Please sign in to comment.