Skip to content

Commit

Permalink
fix img lazy loading
Browse files Browse the repository at this point in the history
  • Loading branch information
URenko committed Jul 5, 2023
1 parent f66c7b9 commit 316d3ba
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ EPUB...

## Other front-end
- e-hentai, with ehunter and EhSyringe support
- mobile
4 changes: 3 additions & 1 deletion comiclib/LANraragi/public/js/jxl.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
decode(el, false, true);
else if (el instanceof Element && getComputedStyle(el).backgroundImage.endsWith('.jxl")'))
decode(el, true, false);
else
return;
el.dispatchEvent(new Event('load'));
}

function imgDataToDataURL(img, imgData, isCSS, isSource) {
Expand Down Expand Up @@ -57,7 +60,6 @@
}

async function decode(img, isCSS, isSource) {
img.dispatchEvent(new Event('load'));
const jxlSrc = img.dataset.jxlSrc = isCSS ? getComputedStyle(img).backgroundImage.slice(5, -2) : isSource ? img.srcset : img.currentSrc;
if (!isCSS && !isSource) {
img.srcset = '';
Expand Down
4 changes: 3 additions & 1 deletion comiclib/LANraragi/public/js/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,11 @@ Reader.initInfiniteScrollView = function () {

Reader.pages.slice(1).forEach((source) => {
const img = new Image();
img.src = source;
img.id = `page-${Reader.pages.indexOf(source)}`;
img.loading = "lazy";
img.height = 800;
img.width = 600;
img.src = source;
$(img).addClass("reader-image");
$("#display").append(img);
observer.observe(img);
Expand Down
2 changes: 1 addition & 1 deletion comiclib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def get_archive_metadata(id: str, db: Session = Depends(get_db)):
a = db.get(Archive, id)
if a is None:
return JSONResponse({"operation": "metadata", "error": "This ID doesn't exist on the server.", "success": 0}, status.HTTP_400_BAD_REQUEST)
return {"arcid": a.id, "isnew": "false", "pagecount": a.pagecount, "progress": 0, "tags": ", ".join(map(lambda t: t.tag, a.tags)), "title": a.title}
return {"arcid": a.id, "isnew": "false", "pagecount": a.pagecount, "progress": 1, "tags": ", ".join(map(lambda t: t.tag, a.tags)), "title": a.title}


@app.put("/api/archives/{id}/metadata")
Expand Down

0 comments on commit 316d3ba

Please sign in to comment.