Skip to content

Commit

Permalink
fix newtab with non local protocole
Browse files Browse the repository at this point in the history
protocols other than file:// base64 encode the image in the url
  • Loading branch information
jonathanpoelen committed May 5, 2024
1 parent 0b2d964 commit f53df7f
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions htmlviewer
Original file line number Diff line number Diff line change
Expand Up @@ -1401,11 +1401,9 @@ const rotate = function(deg) {
img.setAttribute("style", `transform:rotate(${deg}deg)`);
};
const openInNewTab = function(type) {
mode.syncIFile();
const url = filenames[ifile];
const _openInNewTab = function(type, url) {
if (type === 2) {
window.open(url, url);
window.open(url);
}
else {
const a = document.createElement("a");
Expand All @@ -1424,6 +1422,21 @@ const openInNewTab = function(type) {
}
};
const openInNewTab = function(type) {
mode.syncIFile();
const filename = filenames[ifile];
if (isLocalProtocol || !fileByFilename) {
_openInNewTab(type, filename);
}
else {
const reader = new FileReader();
reader.onload = (e) => {
_openInNewTab(type, e.target.result);
};
reader.readAsDataURL(fileByFilename[filename]);
}
};
const toBottomOnLoad = function(image) {
image.onload = function(e) {
body.scrollTop = image.clientHeight;
Expand Down Expand Up @@ -1465,12 +1478,13 @@ const setImage = (function(){
};
}
const reader = new FileReader();
reader.onload = (e) => {
img.src = e.target.result;
};
return function(img, filename) {
if (fileByFilename) {
const reader = new FileReader();
reader.onload = (e) => {
img.src = e.target.result;
};
reader.readAsDataURL(fileByFilename[filename]);
}
else {
Expand Down

0 comments on commit f53df7f

Please sign in to comment.