Skip to content

Commit 2a7f7bc

Browse files
committed
feat: set max dimension such that when its not defined we can use it
1 parent fb16931 commit 2a7f7bc

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,6 +1934,9 @@ function RemoteFunctions(config = {}) {
19341934
this.allImages = [];
19351935
this.imagesPerPage = 10;
19361936
this.scrollPosition = 0;
1937+
this.maxWidth = '800px'; // when current image dimension is not defined we use this as unsplash images are very large
1938+
this.maxHeight = '600px';
1939+
19371940
this.create();
19381941
}
19391942

@@ -2637,8 +2640,9 @@ function RemoteFunctions(config = {}) {
26372640

26382641
// show hovered image along with dimensions
26392642
thumbDiv.addEventListener('mouseenter', () => {
2640-
this.element.style.width = this._originalImageStyle.width;
2641-
this.element.style.height = this._originalImageStyle.height;
2643+
this.element.style.width = this._originalImageStyle.width || this.maxWidth;
2644+
this.element.style.height = this._originalImageStyle.height || this.maxHeight;
2645+
26422646
this.element.style.objectFit = this._originalImageStyle.objectFit || 'cover';
26432647
this.element.src = image.url || image.thumb_url;
26442648
});
@@ -2689,7 +2693,14 @@ function RemoteFunctions(config = {}) {
26892693
e.preventDefault();
26902694
const filename = this._generateFilename(image);
26912695
const extnName = ".jpg";
2692-
this._useImage(image.url, filename, extnName, false);
2696+
2697+
const targetWidth = this._originalImageStyle.width || this.maxWidth;
2698+
const targetHeight = this._originalImageStyle.height || this.maxHeight;
2699+
const widthNum = parseInt(targetWidth);
2700+
const heightNum = parseInt(targetHeight);
2701+
2702+
const downloadUrl = image.url ? `${image.url}?w=${widthNum}&h=${heightNum}&fit=crop` : image.thumb_url;
2703+
this._useImage(downloadUrl, filename, extnName, false);
26932704
});
26942705

26952706
thumbDiv.appendChild(img);

0 commit comments

Comments
 (0)