diff --git a/src/infiniteGrid.js b/src/infiniteGrid.js index 0ea2517..4d831a6 100644 --- a/src/infiniteGrid.js +++ b/src/infiniteGrid.js @@ -180,7 +180,7 @@ eg.module("infiniteGrid", ["jQuery", eg, window, document], function($, ns, glob var self = this; this._resizeTimeout = setTimeout(function() { self._refreshViewport(); - self.layout(self.items, true); + (self.$el.innerWidth() !== self._containerWidth) && self.layout(self.items, true); self._resizeTimeout = null; }, 100); }, diff --git a/test/unit/js/infiniteGrid.test.js b/test/unit/js/infiniteGrid.test.js index 77f2517..7ced94a 100644 --- a/test/unit/js/infiniteGrid.test.js +++ b/test/unit/js/infiniteGrid.test.js @@ -789,4 +789,32 @@ QUnit.test("check a clear after scrolling", function(assert) { done(); }, 100); }); +}); + +QUnit.test("if width is not changed, layout should be not called on resize event.", function(assert) { + // Given + var done = assert.async(); + var resizeCount = 0; + var layoutCount = 0; + var $global = $(window); + var inst = this.inst = new eg.InfiniteGrid("#grid"); + this.inst.on("layoutComplete", function(e) { + this.off("layoutComplete"); + this.on("layoutComplete", function(e) { + assert.ok(false, "layoutComplete event should not be called"); + }); + }); + $global.on("resize", function(e) { + resizeCount++; + }); + + // When + $global.trigger("resize"); + + // Then + setTimeout(function() { + assert.ok(resizeCount > 0, "should exist resize event"); + assert.equal(inst.$el.innerWidth(), inst._containerWidth, "width is not changed"); + done(); + },100); }); \ No newline at end of file