From c0e7adcc42558c2f7c80aebd8f680c76bde2498f Mon Sep 17 00:00:00 2001 From: James Collins Date: Mon, 13 Mar 2023 22:33:13 +1000 Subject: [PATCH] improve imageLoad methiod --- resources/js/helpers/image.ts | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/resources/js/helpers/image.ts b/resources/js/helpers/image.ts index afe62f4..11b2c89 100644 --- a/resources/js/helpers/image.ts +++ b/resources/js/helpers/image.ts @@ -1,4 +1,5 @@ import { ImportMetaExtras } from "../../../import-meta"; +import { urlStripAttributes } from "./url"; type ImageLoadCallback = (url: string) => void; @@ -7,16 +8,30 @@ export const imageLoad = ( callback: ImageLoadCallback, postfix = "size=thumb" ) => { - callback(`${url}?${postfix}`); - const tmp = new Image(); - tmp.onload = function () { + if ( + url.startsWith((import.meta as ImportMetaExtras).env.APP_URL) === true + ) { + callback(urlStripAttributes(url) + "?" + postfix); + const tmp = new Image(); + tmp.onload = function () { + callback(url); + }; + tmp.src = url; + } else { + // Image is not one we control callback(url); - }; - tmp.src = url; + } }; export const imageSize = (size: string, url: string) => { - const availableSizes = ["thumb", "small", "medium", "large", "xlarge"]; + const availableSizes = [ + "thumb", + "small", + "medium", + "large", + "xlarge", + "xxlarge", + ]; if (availableSizes.includes(size)) { if ( url.startsWith((import.meta as ImportMetaExtras).env.APP_URL) === @@ -54,6 +69,11 @@ export const imageXLarge = (url: string) => { return imageSize("xlarge", url); }; +// Large 2560 x 2560 +export const imageXXLarge = (url: string) => { + return imageSize("xxlarge", url); +}; + // Full size export const imageFull = (url: string) => { return imageSize("full", url);