Browse Source

docs : update category rows custom layout mode logic

pull/96/head
David DeSandro 14 years ago
parent
commit
e4d7293afc
  1. 95
      _posts/demos/2011-05-22-category-rows.html

95
_posts/demos/2011-05-22-category-rows.html

@ -6,7 +6,7 @@ related: layouts
--- ---
<section id="copy"> <section id="copy">
<p>This demo uses a custom layout mode that arranges elements into columns based on an attribute.</p> <p>This demo uses a custom layout mode, <code>categoryRows</code> that arranges elements into rows based on their category. The layout mode logic relies on sorting to define rows.</p>
</section> </section>
<section id="options" class="clearfix"> <section id="options" class="clearfix">
@ -33,6 +33,7 @@ related: layouts
<h3>Etc</h3> <h3>Etc</h3>
<ul id="etc" class="floated clearfix"> <ul id="etc" class="floated clearfix">
<li id="toggle-sizes"><a href="#toggle-sizes">Toggle variable sizes</a></li>
<li id="insert"><a href="#insert">Insert new elements</a></li> <li id="insert"><a href="#insert">Insert new elements</a></li>
</ul> </ul>
</section> <!-- #options --> </section> <!-- #options -->
@ -53,73 +54,60 @@ related: layouts
$.extend( $.Isotope.prototype, { $.extend( $.Isotope.prototype, {
_categoryRowsReset : function() { _categoryRowsReset : function() {
// reset namespace properties
this.categoryRows = { this.categoryRows = {
rowIndex : 0, x : 0,
// the x & y position in each row y : 0,
position : { height : 0,
x : this.posLeft, currentCategory : null
y : this.posTop
}
}; };
this._getSegments('categoryRows', true);
return this;
}, },
_categoryRowsLayout : function( $elems ) { _categoryRowsLayout : function( $elems ) {
var instance = this, var instance = this,
// namespaced properties
position = this.categoryRows.position,
sortBy = this.options.sortBy,
containerWidth = this.element.width(), containerWidth = this.element.width(),
currentRowName, nextX; sortBy = this.options.sortBy,
$elems.each(function(){ props = this.categoryRows;
var $this = $(this),
// get row based on function passed in options
rowName = $this.data('isotope-sort-data')[ sortBy ],
atomWidth = $this.outerWidth(true);
// for new row
if ( !currentRowName ) {
currentRowName = rowName;
} else if ( currentRowName !== rowName ) {
instance._categoryRowsNewRow();
currentRowName = rowName;
}
// if item doesn't fit on row $elems.each( function() {
nextX = position.x + atomWidth; var $this = $(this),
if ( nextX >= containerWidth ) { atomW = $this.outerWidth(true),
instance._categoryRowsNewRow(); atomH = $this.outerHeight(true),
category = $.data( this, 'isotope-sort-data' )[ sortBy ],
x, y;
if ( category !== props.currentCategory ) {
// new category, new row
props.x = 0;
props.height += props.currentCategory ? instance.options.categoryRows.gutter : 0;
props.y = props.height;
props.currentCategory = category;
} else if ( props.x !== 0 && atomW + props.x > containerWidth ) {
// if this element cannot fit in the current row
props.x = 0;
props.y = props.height;
} }
instance._pushPosition( $this, position.x, position.y ); // position the atom
instance._pushPosition( $this, props.x, props.y );
position.x += atomWidth; props.height = Math.max( props.y + atomH, props.height );
props.x += atomW;
}); });
return this;
},
// convience method
_categoryRowsNewRow : function() {
var props = this.categoryRows;
props.position.x = this.posLeft;
props.position.y += props.rowHeight;
}, },
_categoryRowsGetContainerSize : function() { _categoryRowsGetContainerSize : function () {
return { height: this.categoryRows.position.y + this.categoryRows.rowHeight }; return { height : this.categoryRows.height };
}, },
_categoryRowsResize : function() { _categoryRowsResizeChanged : function() {
this.reLayout(); return true;
} }
}); });
$(function(){
var $container = $('#container'); var $container = $('#container');
$('#filters').find('a').click(function(){ $('#filters').find('a').click(function(){
@ -132,16 +120,21 @@ related: layouts
{% include add-buttons.js %} {% include add-buttons.js %}
{% include option-buttons.js %} // toggle variable sizes of all elements
$('#toggle-sizes').find('a').click(function(){
$container
.toggleClass('variable-sizes')
.isotope('reLayout');
return false;
});
$(function(){ {% include option-buttons.js %}
$container.isotope({ $container.isotope({
itemSelector : '.element', itemSelector : '.element',
layoutMode : 'categoryRows', layoutMode : 'categoryRows',
categoryRows : { categoryRows : {
rowHeight : 120 gutter : 20
}, },
getSortData : { getSortData : {
category : function( $elem ) { category : function( $elem ) {

Loading…
Cancel
Save