|
|
|
---
|
|
|
|
title: Category rows
|
|
|
|
layout: demo
|
|
|
|
category: demos
|
|
|
|
related: layouts
|
|
|
|
---
|
|
|
|
|
|
|
|
<section id="copy">
|
|
|
|
<p>This demo uses a custom layout mode that arranges elements into columns based on an attribute.</p>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
<section id="options" class="clearfix">
|
|
|
|
|
|
|
|
<h3>Filters</h3>
|
|
|
|
|
|
|
|
<ul id="filters" class="option-set floated clearfix">
|
|
|
|
<li><a href="#show-all" class="selected">show all</a></li>
|
|
|
|
<li><a href="#metalloid">metalloid</a></li>
|
|
|
|
<li><a href="#metal">metal</a></li>
|
|
|
|
<li><a href="#alkali">alkali</a></li>
|
|
|
|
<li><a href="#alkaline-earth">alkaline-earth</a></li>
|
|
|
|
<li><a href="#inner-transition">inner-transition</a></li>
|
|
|
|
<li><a href="#lanthanoid">lanthanoid</a></li>
|
|
|
|
<li><a href="#actinoid">actinoid</a></li>
|
|
|
|
<li><a href="#transition">transition</a></li>
|
|
|
|
<li><a href="#post-transition">post-transition</a></li>
|
|
|
|
<li><a href="#nonmetal">nonmetal</a></li>
|
|
|
|
<li><a href="#other">other</a></li>
|
|
|
|
<li><a href="#halogen">halogen</a></li>
|
|
|
|
<li><a href="#noble-gas">noble-gas</a></li>
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
<h3>Etc</h3>
|
|
|
|
|
|
|
|
<ul id="etc" class="floated clearfix">
|
|
|
|
<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() {
|
|
|
|
// reset namespace properties
|
|
|
|
this.categoryRows = {
|
|
|
|
rowIndex : 0,
|
|
|
|
// the x & y position in each row
|
|
|
|
position : {
|
|
|
|
x : this.posLeft,
|
|
|
|
y : this.posTop
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this._getSegments('categoryRows', true);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
_categoryRowsLayout : function( $elems ) {
|
|
|
|
var instance = this,
|
|
|
|
// namespaced properties
|
|
|
|
position = this.categoryRows.position,
|
|
|
|
sortBy = this.options.sortBy,
|
|
|
|
containerWidth = this.element.width(),
|
|
|
|
currentRowName, nextX;
|
|
|
|
$elems.each(function(){
|
|
|
|
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
|
|
|
|
nextX = position.x + atomWidth;
|
|
|
|
if ( nextX >= containerWidth ) {
|
|
|
|
instance._categoryRowsNewRow();
|
|
|
|
}
|
|
|
|
|
|
|
|
instance._pushPosition( $this, position.x, position.y );
|
|
|
|
|
|
|
|
position.x += atomWidth;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
// convience method
|
|
|
|
_categoryRowsNewRow : function() {
|
|
|
|
var props = this.categoryRows;
|
|
|
|
props.position.x = this.posLeft;
|
|
|
|
props.position.y += props.rowHeight;
|
|
|
|
},
|
|
|
|
|
|
|
|
_categoryRowsGetContainerSize : function() {
|
|
|
|
return { height: this.categoryRows.position.y + this.categoryRows.rowHeight };
|
|
|
|
},
|
|
|
|
|
|
|
|
_categoryRowsResize : function() {
|
|
|
|
this.reLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
var $container = $('#container');
|
|
|
|
|
|
|
|
$('#filters').find('a').click(function(){
|
|
|
|
// get href attribute, minus the #, plus a . to make it a class
|
|
|
|
var filterName = '.' + $(this).attr('href').slice(1);
|
|
|
|
filterName = filterName === '.show-all' ? '*' : filterName;
|
|
|
|
$container.isotope({ filter: filterName })
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
{% include add-buttons.js %}
|
|
|
|
|
|
|
|
{% include option-buttons.js %}
|
|
|
|
|
|
|
|
|
|
|
|
$(function(){
|
|
|
|
|
|
|
|
$container.isotope({
|
|
|
|
itemSelector : '.element',
|
|
|
|
layoutMode : 'categoryRows',
|
|
|
|
categoryRows : {
|
|
|
|
rowHeight : 120
|
|
|
|
},
|
|
|
|
getSortData : {
|
|
|
|
category : function( $elem ) {
|
|
|
|
return $elem.attr('data-category');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
sortBy: 'category',
|
|
|
|
animationEngine : $.browser.opera ? 'jquery' : 'best-available'
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|