diff --git a/docs/changelog.md b/docs/changelog.md index c86f1fc..d01565e 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -7,6 +7,7 @@ #### v1.2.0 + Use `constructor.defaults` for default options ++ add `needsResizeLayout()` for [#9](https://github.com/metafizzy/outlayer/issues/9) ### v1.1 diff --git a/outlayer.js b/outlayer.js index 5084c77..0a6c04c 100644 --- a/outlayer.js +++ b/outlayer.js @@ -676,17 +676,25 @@ Outlayer.prototype.onresize = function() { // debounced, layout on resize Outlayer.prototype.resize = function() { // don't trigger if size did not change - var size = getSize( this.element ); - // check that this.size and size are there - // IE8 triggers resize on body size change, so they might not be - var hasSizes = this.size && size; - if ( hasSizes && size.innerWidth === this.size.innerWidth ) { + // or if resize was unbound. See #9 + if ( !this.isResizeBound || !this.needsResizeLayout() ) { return; } this.layout(); }; +/** + * check if layout is needed post layout + * @returns Boolean + */ +Outlayer.prototype.needsResizeLayout = function() { + var size = getSize( this.element ); + // check that this.size and size are there + // IE8 triggers resize on body size change, so they might not be + var hasSizes = this.size && size; + return hasSizes && size.innerWidth !== this.size.innerWidth; +}; // -------------------------- methods -------------------------- // diff --git a/test/destroy.js b/test/destroy.js index d100bae..b01641b 100644 --- a/test/destroy.js +++ b/test/destroy.js @@ -24,4 +24,14 @@ test( 'destroy', function() { checkStyle( itemElem, 'top' ); } + // try to force a resize + container.style.width = '300px'; + layout.resize(); + + checkStyle( container, 'height' ); + checkStyle( container, 'position' ); + checkStyle( items[0], 'position' ); + checkStyle( items[0], 'left' ); + checkStyle( items[0], 'top' ); + });