mirror of
https://github.com/rr-/szurubooru.git
synced 2025-07-17 08:26:24 +00:00
client/posts: skip thumbnail placeholder if fullsize image is in cache
This commit is contained in:
@ -5,11 +5,12 @@ const views = require("../util/views.js");
|
|||||||
const optimizedResize = require("../util/optimized_resize.js");
|
const optimizedResize = require("../util/optimized_resize.js");
|
||||||
|
|
||||||
class PostContentControl {
|
class PostContentControl {
|
||||||
constructor(hostNode, post, viewportSizeCalculator, fitFunctionOverride) {
|
constructor(hostNode, post, isMediaCached, viewportSizeCalculator, fitFunctionOverride) {
|
||||||
this._post = post;
|
this._post = post;
|
||||||
this._viewportSizeCalculator = viewportSizeCalculator;
|
this._viewportSizeCalculator = viewportSizeCalculator;
|
||||||
this._hostNode = hostNode;
|
this._hostNode = hostNode;
|
||||||
this._template = views.getTemplate("post-content");
|
this._template = views.getTemplate("post-content");
|
||||||
|
this._isMediaCached = isMediaCached;
|
||||||
|
|
||||||
let fitMode = settings.get().fitMode;
|
let fitMode = settings.get().fitMode;
|
||||||
if (typeof fitFunctionOverride !== "undefined") {
|
if (typeof fitFunctionOverride !== "undefined") {
|
||||||
@ -150,9 +151,11 @@ class PostContentControl {
|
|||||||
newNode.firstElementChild.style.backgroundImage = "";
|
newNode.firstElementChild.style.backgroundImage = "";
|
||||||
}
|
}
|
||||||
if (["image", "flash"].includes(this._post.type)) {
|
if (["image", "flash"].includes(this._post.type)) {
|
||||||
newNode.firstElementChild.style.backgroundImage = "url("+this._post.originalThumbnailUrl+")";
|
if (this._post.type !== "image" || !this._isMediaCached) {
|
||||||
|
newNode.firstElementChild.style.backgroundImage = "url("+this._post.originalThumbnailUrl+")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (this._post.type == "image") {
|
if (this._post.type == "image" && !this._isMediaCached) {
|
||||||
newNode.firstElementChild.addEventListener("load", load);
|
newNode.firstElementChild.addEventListener("load", load);
|
||||||
} else if (settings.get().transparencyGrid) {
|
} else if (settings.get().transparencyGrid) {
|
||||||
newNode.classList.add("transparency-grid");
|
newNode.classList.add("transparency-grid");
|
||||||
|
@ -211,6 +211,15 @@ function getPrettyName(tag) {
|
|||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isMediaCached(post) {
|
||||||
|
if (post.type !== "image") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const img = new Image()
|
||||||
|
img.src = post.contentUrl;
|
||||||
|
return img.complete;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
range: range,
|
range: range,
|
||||||
formatRelativeTime: formatRelativeTime,
|
formatRelativeTime: formatRelativeTime,
|
||||||
@ -229,4 +238,5 @@ module.exports = {
|
|||||||
escapeSearchTerm: escapeSearchTerm,
|
escapeSearchTerm: escapeSearchTerm,
|
||||||
dataURItoBlob: dataURItoBlob,
|
dataURItoBlob: dataURItoBlob,
|
||||||
getPrettyName: getPrettyName,
|
getPrettyName: getPrettyName,
|
||||||
|
isMediaCached: isMediaCached,
|
||||||
};
|
};
|
||||||
|
@ -62,6 +62,7 @@ class HomeView {
|
|||||||
this._postContentControl = new PostContentControl(
|
this._postContentControl = new PostContentControl(
|
||||||
this._postContainerNode,
|
this._postContainerNode,
|
||||||
postInfo.featuredPost,
|
postInfo.featuredPost,
|
||||||
|
misc.isMediaCached(postInfo.featuredPost),
|
||||||
() => {
|
() => {
|
||||||
return [window.innerWidth * 0.8, window.innerHeight * 0.7];
|
return [window.innerWidth * 0.8, window.innerHeight * 0.7];
|
||||||
},
|
},
|
||||||
|
@ -31,6 +31,7 @@ class PostMainView {
|
|||||||
this._postContentControl = new PostContentControl(
|
this._postContentControl = new PostContentControl(
|
||||||
postContainerNode,
|
postContainerNode,
|
||||||
ctx.post,
|
ctx.post,
|
||||||
|
misc.isMediaCached(ctx.post),
|
||||||
() => {
|
() => {
|
||||||
const margin = sidebarNode.getBoundingClientRect().left;
|
const margin = sidebarNode.getBoundingClientRect().left;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user