mirror of https://github.com/metafizzy/isotope
Filter & sort magical layouts
http://isotope.metafizzy.co
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
126 lines
3.2 KiB
126 lines
3.2 KiB
14 years ago
|
---
|
||
14 years ago
|
title: Category rows
|
||
14 years ago
|
layout: default
|
||
13 years ago
|
category: custom-layout-modes
|
||
14 years ago
|
---
|
||
|
|
||
|
<section id="copy">
|
||
13 years ago
|
<p>This demo uses a <a href="../docs/extending-isotope.html">custom layout mode</a>, <code>categoryRows</code> that arranges elements into rows based on their category. The layout mode logic relies on sorting to define rows.</p>
|
||
14 years ago
|
</section>
|
||
|
|
||
|
<section id="options" class="clearfix">
|
||
|
|
||
14 years ago
|
{% include filter-buttons.html %}
|
||
14 years ago
|
|
||
|
<h3>Etc</h3>
|
||
|
|
||
14 years ago
|
<ul id="etc" class="clearfix">
|
||
14 years ago
|
<li id="toggle-sizes"><a href="#toggle-sizes">Toggle variable sizes</a></li>
|
||
14 years ago
|
<li id="insert"><a href="#insert">Insert new elements</a></li>
|
||
|
</ul>
|
||
|
</section> <!-- #options -->
|
||
|
|
||
|
<div id="container" class="clearfix">
|
||
|
{% for elem_number in site.random_order | limit:60 %}
|
||
|
{% assign element = site.elements[elem_number] %}
|
||
|
{% include element-partial.html %}
|
||
|
{% endfor %}
|
||
|
</div>
|
||
|
|
||
|
<script src="../{{ site.jquery_js }}"></script>
|
||
|
<script src="../{{ site.isotope_js }}"></script>
|
||
|
<script src="../js/fake-element.js"></script>
|
||
|
<script>
|
||
|
|
||
|
// categoryRows custom layout mode
|
||
|
$.extend( $.Isotope.prototype, {
|
||
|
|
||
|
_categoryRowsReset : function() {
|
||
|
this.categoryRows = {
|
||
14 years ago
|
x : 0,
|
||
|
y : 0,
|
||
|
height : 0,
|
||
|
currentCategory : null
|
||
14 years ago
|
};
|
||
|
},
|
||
|
|
||
|
_categoryRowsLayout : function( $elems ) {
|
||
14 years ago
|
var instance = this,
|
||
|
containerWidth = this.element.width(),
|
||
14 years ago
|
sortBy = this.options.sortBy,
|
||
|
props = this.categoryRows;
|
||
14 years ago
|
|
||
14 years ago
|
$elems.each( function() {
|
||
|
var $this = $(this),
|
||
|
atomW = $this.outerWidth(true),
|
||
|
atomH = $this.outerHeight(true),
|
||
|
category = $.data( this, 'isotope-sort-data' )[ sortBy ],
|
||
|
x, y;
|
||
14 years ago
|
|
||
14 years ago
|
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;
|
||
|
}
|
||
14 years ago
|
|
||
14 years ago
|
// position the atom
|
||
|
instance._pushPosition( $this, props.x, props.y );
|
||
|
|
||
|
props.height = Math.max( props.y + atomH, props.height );
|
||
|
props.x += atomW;
|
||
|
|
||
14 years ago
|
});
|
||
14 years ago
|
},
|
||
14 years ago
|
|
||
14 years ago
|
_categoryRowsGetContainerSize : function () {
|
||
|
return { height : this.categoryRows.height };
|
||
14 years ago
|
},
|
||
|
|
||
14 years ago
|
_categoryRowsResizeChanged : function() {
|
||
|
return true;
|
||
14 years ago
|
}
|
||
|
|
||
|
});
|
||
|
|
||
14 years ago
|
$(function(){
|
||
|
|
||
|
var $container = $('#container');
|
||
14 years ago
|
|
||
|
{% include random-sizes.js %}
|
||
|
|
||
14 years ago
|
$container.isotope({
|
||
|
itemSelector : '.element',
|
||
|
layoutMode : 'categoryRows',
|
||
|
categoryRows : {
|
||
14 years ago
|
gutter : 20
|
||
14 years ago
|
},
|
||
|
getSortData : {
|
||
|
category : function( $elem ) {
|
||
14 years ago
|
return $elem.attr('data-category');
|
||
|
}
|
||
|
},
|
||
14 years ago
|
sortBy: 'category'
|
||
14 years ago
|
});
|
||
|
|
||
14 years ago
|
{% include option-set-buttons.js %}
|
||
|
|
||
|
{% include add-buttons.js %}
|
||
|
|
||
|
// toggle variable sizes of all elements
|
||
|
$('#toggle-sizes').find('a').click(function(){
|
||
|
$container
|
||
|
.toggleClass('variable-sizes')
|
||
|
.isotope('reLayout');
|
||
|
return false;
|
||
|
});
|
||
|
|
||
14 years ago
|
});
|
||
|
</script>
|
||
|
|
||
|
|