mirror of
https://github.com/simon987/sist2.git
synced 2025-04-19 02:06:46 +00:00
Image placeholder
This commit is contained in:
parent
ba81748a74
commit
fc22e52eae
@ -15,7 +15,7 @@ store_t *store_create(char *path) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (open_ret != 0) {
|
if (open_ret != 0) {
|
||||||
fprintf(stderr, "Error while opening store: %s", mdb_strerror(open_ret));
|
fprintf(stderr, "Error while opening store: %s (%s)\n", mdb_strerror(open_ret), path);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#define EPILOG "Made by simon987 <me@simon987.net>. Released under GPL-3.0"
|
#define EPILOG "Made by simon987 <me@simon987.net>. Released under GPL-3.0"
|
||||||
|
|
||||||
|
|
||||||
static const char *const Version = "1.1.3";
|
static const char *const Version = "1.1.4";
|
||||||
static const char *const usage[] = {
|
static const char *const usage[] = {
|
||||||
"sist2 scan [OPTION]... PATH",
|
"sist2 scan [OPTION]... PATH",
|
||||||
"sist2 index [OPTION]... INDEX",
|
"sist2 index [OPTION]... INDEX",
|
||||||
|
File diff suppressed because one or more lines are too long
@ -75,6 +75,18 @@ function shouldPlayVideo(hit) {
|
|||||||
return videoc !== "hevc" && videoc !== "mpeg2video" && videoc !== "wmv3";
|
return videoc !== "hevc" && videoc !== "mpeg2video" && videoc !== "wmv3";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function makePlaceholder(w, h) {
|
||||||
|
const calc = w > h
|
||||||
|
? (175 / w / h) >= 272
|
||||||
|
? (175 * w / h)
|
||||||
|
: 175
|
||||||
|
: 175;
|
||||||
|
|
||||||
|
const el = document.createElement("div");
|
||||||
|
el.setAttribute("style", `height: ${calc}px`);
|
||||||
|
return el;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param hit
|
* @param hit
|
||||||
@ -119,14 +131,22 @@ function createDocCard(hit) {
|
|||||||
thumbnail = document.createElement("video");
|
thumbnail = document.createElement("video");
|
||||||
addVidSrc("f/" + hit["_id"], hit["_source"]["mime"], thumbnail);
|
addVidSrc("f/" + hit["_id"], hit["_source"]["mime"], thumbnail);
|
||||||
|
|
||||||
|
const placeholder = makePlaceholder(hit["_source"]["width"], hit["_source"]["height"]);
|
||||||
|
imgWrapper.appendChild(placeholder);
|
||||||
|
|
||||||
thumbnail.setAttribute("class", "fit");
|
thumbnail.setAttribute("class", "fit");
|
||||||
thumbnail.setAttribute("loop", "");
|
|
||||||
thumbnail.setAttribute("controls", "");
|
thumbnail.setAttribute("controls", "");
|
||||||
thumbnail.setAttribute("preload", "none");
|
thumbnail.setAttribute("preload", "none");
|
||||||
thumbnail.setAttribute("poster", `t/${hit["_source"]["index"]}/${hit["_id"]}`);
|
thumbnail.setAttribute("poster", `t/${hit["_source"]["index"]}/${hit["_id"]}`);
|
||||||
thumbnail.addEventListener("dblclick", function () {
|
thumbnail.addEventListener("dblclick", function () {
|
||||||
thumbnail.webkitRequestFullScreen();
|
thumbnail.webkitRequestFullScreen();
|
||||||
});
|
});
|
||||||
|
const poster = new Image();
|
||||||
|
poster.src = thumbnail.getAttribute('poster');
|
||||||
|
poster.addEventListener("load", function () {
|
||||||
|
placeholder.remove();
|
||||||
|
imgWrapper.appendChild(thumbnail);
|
||||||
|
});
|
||||||
} else if ((hit["_source"].hasOwnProperty("width") && hit["_source"]["width"] > 20 && hit["_source"]["height"] > 20)
|
} else if ((hit["_source"].hasOwnProperty("width") && hit["_source"]["width"] > 20 && hit["_source"]["height"] > 20)
|
||||||
|| hit["_source"]["mime"] === "application/pdf"
|
|| hit["_source"]["mime"] === "application/pdf"
|
||||||
|| hit["_source"]["mime"] === "application/epub+zip"
|
|| hit["_source"]["mime"] === "application/epub+zip"
|
||||||
@ -136,9 +156,17 @@ function createDocCard(hit) {
|
|||||||
thumbnail = document.createElement("img");
|
thumbnail = document.createElement("img");
|
||||||
thumbnail.setAttribute("class", "card-img-top fit");
|
thumbnail.setAttribute("class", "card-img-top fit");
|
||||||
thumbnail.setAttribute("src", `t/${hit["_source"]["index"]}/${hit["_id"]}`);
|
thumbnail.setAttribute("src", `t/${hit["_source"]["index"]}/${hit["_id"]}`);
|
||||||
|
|
||||||
|
const placeholder = makePlaceholder(hit["_source"]["width"], hit["_source"]["height"]);
|
||||||
|
imgWrapper.appendChild(placeholder);
|
||||||
|
|
||||||
thumbnail.addEventListener("error", () => {
|
thumbnail.addEventListener("error", () => {
|
||||||
imgWrapper.remove();
|
imgWrapper.remove();
|
||||||
});
|
});
|
||||||
|
thumbnail.addEventListener("load", () => {
|
||||||
|
placeholder.remove();
|
||||||
|
imgWrapper.appendChild(thumbnail);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//Thumbnail overlay
|
//Thumbnail overlay
|
||||||
@ -206,7 +234,6 @@ function createDocCard(hit) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (thumbnail !== null) {
|
if (thumbnail !== null) {
|
||||||
imgWrapper.appendChild(thumbnail);
|
|
||||||
docCard.appendChild(imgWrapper);
|
docCard.appendChild(imgWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user