Skip to content

Commit

Permalink
add needsResizeLayout. Fixes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
desandro committed Mar 4, 2014
1 parent 0535309 commit de270bd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 13 additions & 5 deletions outlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 -------------------------- //

Expand Down
10 changes: 10 additions & 0 deletions test/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' );

});

0 comments on commit de270bd

Please sign in to comment.