Skip to content

Commit 750c4cf

Browse files
author
sherwinski
authored
fix: do not add drift-loading class after first hover (#317)
1 parent da6fede commit 750c4cf

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/js/ZoomPane.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,13 @@ export default class ZoomPane {
182182
this.isShowing = true;
183183

184184
addClasses(this.el, this.openClasses);
185-
addClasses(this.el, this.loadingClasses);
186185

187-
this.imgEl.addEventListener("load", this._handleLoad, false);
188-
this._setImageURL(imageURL);
186+
if (this.imgEl.getAttribute("src") != imageURL) {
187+
addClasses(this.el, this.loadingClasses);
188+
this.imgEl.addEventListener("load", this._handleLoad, false);
189+
this._setImageURL(imageURL);
190+
}
191+
189192
this._setImageSize(triggerWidth, triggerHeight);
190193

191194
if (this._isInline) {

test/testZoomPane.js

+19
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,23 @@ describe("ZoomPane", () => {
7777

7878
expect(zoomPane.imgEl.style.width).toBe(`${triggerWidth * zoomPane.settings.zoomFactor}px`);
7979
});
80+
81+
it("does not add the drift-loading class after first hover", () => {
82+
const zoomPane = new ZoomPane(zoomPaneOptions());
83+
const testSrc = "http://assets.imgix.net/unsplash/pretty2.jpg";
84+
const triggerWidth = 400;
85+
86+
zoomPane.show(testSrc, triggerWidth);
87+
expect(zoomPane.el.classList.toString()).toContain("drift-loading");
88+
89+
zoomPane.hide();
90+
setTimeout(function() {
91+
expect(zoomPane.el.classList.toString()).not.toContain("drift-loading");
92+
}, 1000);
93+
94+
zoomPane.show(testSrc, triggerWidth);
95+
setTimeout(function() {
96+
expect(zoomPane.el.classList.toString()).not.toContain("drift-loading");
97+
}, 1000);
98+
});
8099
});

0 commit comments

Comments
 (0)