Skip to content

Commit

Permalink
src & docs : add containerStyle option; v2.1.02
Browse files Browse the repository at this point in the history
  • Loading branch information
desandro committed Jan 25, 2012
1 parent 8d07ab3 commit b5fad36
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 23 deletions.
11 changes: 11 additions & 0 deletions _posts/docs/2011-05-02-options.mdown
Expand Up @@ -7,6 +7,7 @@ body_class: options
toc :
- { title: animationOptions, anchor: animationoptions }
- { title: columnWidth, anchor: columnwidth }
- { title: containerStyle, anchor: containerstyle }
- { title: gutterWidth, anchor: gutterwidth }
- { title: isAnimated, anchor: isanimated }
- { title: isFitWidth, anchor: isfitwidth }
Expand Down Expand Up @@ -72,6 +73,16 @@ $('#container').masonry({

[See Demo: Fluid](../demos/fluid.html).

## containerStyle

<dl class="clearfix">
<dt><code>columnWidth</code></dt>
<dd class="option-type">Object</dd>
<dd class="default"><code>{ position: <span class="s1">'relative'</span> }</code></dd>
</dl>

CSS properties applied to the container. Masonry uses relative/absolute positioning to position item elements.

## gutterWidth

<dl class="clearfix">
Expand Down
43 changes: 22 additions & 21 deletions jquery.masonry.js
@@ -1,5 +1,5 @@
/**
* jQuery Masonry v2.1.01
* jQuery Masonry v2.1.02
* A dynamic layout plugin for jQuery
* The flip-side of CSS Floats
* http://masonry.desandro.com
Expand Down Expand Up @@ -61,10 +61,7 @@
this._create( options );
this._init();
};

// styles of container element we want to keep track of
var masonryContainerStyles = [ 'position', 'height' ];


$.Mason.settings = {
isResizable: true,
isAnimated: false,
Expand All @@ -74,7 +71,10 @@
},
gutterWidth: 0,
isRTL: false,
isFitWidth: false
isFitWidth: false,
containerStyle: {
position: 'relative'
}
};

$.Mason.prototype = {
Expand All @@ -97,24 +97,22 @@
_create : function( options ) {

this.options = $.extend( true, {}, $.Mason.settings, options );

this.styleQueue = [];
// need to get bricks
this.reloadItems();


// get original styles in case we re-apply them in .destroy()
var elemStyle = this.element[0].style;
this.originalStyle = {};
for ( var i=0, len = masonryContainerStyles.length; i < len; i++ ) {
var prop = masonryContainerStyles[i];
this.originalStyle = {
// get height
height: elemStyle.height || ''
};
// get other styles that will be overwritten
var containerStyle = this.options.containerStyle;
for ( var prop in containerStyle ) {
this.originalStyle[ prop ] = elemStyle[ prop ] || '';
}

this.element.css({
position : 'relative'
});

this.element.css( containerStyle );

this.horizontalDirection = this.options.isRTL ? 'right' : 'left';

this.offset = {
Expand All @@ -136,7 +134,11 @@
instance.resize();
});
}



// need to get bricks
this.reloadItems();

},

// _init fires when instance is first created
Expand Down Expand Up @@ -365,11 +367,10 @@

// re-apply saved container styles
var elemStyle = this.element[0].style;
for ( var i=0, len = masonryContainerStyles.length; i < len; i++ ) {
var prop = masonryContainerStyles[i];
for ( var prop in this.originalStyle ) {
elemStyle[ prop ] = this.originalStyle[ prop ];
}

this.element
.unbind('.masonry')
.removeClass('masonry')
Expand Down
4 changes: 2 additions & 2 deletions jquery.masonry.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b5fad36

Please sign in to comment.