mirror of https://github.com/metafizzy/isotope
1 changed files with 151 additions and 0 deletions
@ -0,0 +1,151 @@
|
||||
--- |
||||
title: Category columns |
||||
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> |
||||
<li id="append"><a href='#append'>Append 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> |
||||
|
||||
{% include footer.html %} |
||||
|
||||
<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 = { |
||||
// the number of rows |
||||
rows : 0, |
||||
// the x & y position in each row |
||||
positions : {} |
||||
}; |
||||
|
||||
return this; |
||||
}, |
||||
|
||||
_categoryRowsLayout : function( $elems ) { |
||||
var instance = this; |
||||
options = this.options.categoryRows, |
||||
// namespaced properties |
||||
props = this.categoryRows; |
||||
$elems.each(function(){ |
||||
var $this = $(this), |
||||
// get row based on function passed in options |
||||
rowName = options.getRow( $this ); |
||||
|
||||
if ( !props.positions[ rowName ] ) { |
||||
// if row does not exists, create it |
||||
props.positions[ rowName ] = { |
||||
x : instance.posLeft, |
||||
y : instance.posTop + options.rowHeight * props.rows |
||||
}; |
||||
// increment rows |
||||
props.rows ++; |
||||
} |
||||
|
||||
instance._pushPosition( $this, props.positions[ rowName ].x, props.positions[ rowName ].y ); |
||||
|
||||
props.positions[ rowName ].x += $this.outerWidth(true); |
||||
|
||||
}); |
||||
|
||||
return this; |
||||
}, |
||||
|
||||
_categoryRowsGetContainerSize : function() { |
||||
var y = this.categoryRows.rows * this.options.categoryRows.rowHeight + this.posTop, |
||||
maxX = 0, |
||||
rowName, position; |
||||
|
||||
// get max X position from the positions object |
||||
for ( rowName in this.categoryRows.positions ) { |
||||
position = this.categoryRows.positions[ rowName ] |
||||
maxX = position.x > maxX ? position.x : maxX; |
||||
} |
||||
return { width: maxX, height: y }; |
||||
}, |
||||
|
||||
_categoryRowsResize : function() { |
||||
return this; |
||||
} |
||||
|
||||
}); |
||||
|
||||
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, |
||||
getRow : function( $elem ) { |
||||
return $elem.attr('data-category'); |
||||
} |
||||
}, |
||||
animationEngine : $.browser.opera ? 'jquery' : 'best-available' |
||||
}); |
||||
|
||||
|
||||
}); |
||||
</script> |
||||
|
||||
|
Loading…
Reference in new issue