mirror of https://github.com/metafizzy/isotope
1 changed files with 203 additions and 0 deletions
@ -0,0 +1,203 @@
|
||||
--- |
||||
title: centered masonry |
||||
layout: demo |
||||
category: tests |
||||
--- |
||||
|
||||
<style> |
||||
#container { |
||||
margin: 0 auto 20px; |
||||
} |
||||
</style> |
||||
|
||||
<section id="copy"> |
||||
<p>Isotope’s capabilities are designed to be used together cohesively. You can do it all — filter, sort, change layout modes, add items — and Isotope will handle it with ease.</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> |
||||
|
||||
{% include sort-buttons.html %} |
||||
|
||||
<h3>Etc</h3> |
||||
|
||||
<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="append"><a href='#append'>Append new elements</a></li> |
||||
<!-- <li id="shuffle"><a href='#shuffle'>Shuffle</a></li> --> |
||||
</ul> |
||||
</section> <!-- #options --> |
||||
|
||||
<div id="container" class="clickable clearfix"> |
||||
{% for elem_number in site.best_of_order %} |
||||
{% 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> |
||||
|
||||
$.Isotope.prototype._getCenteredMasonryColumns = function() { |
||||
this.width = this.element.width(); |
||||
|
||||
var parentWidth = this.element.parent().width(); |
||||
|
||||
// i.e. options.masonry && options.masonry.columnWidth |
||||
colW = this.options.masonry && this.options.masonry.columnWidth || |
||||
// or use the size of the first item |
||||
this.$filteredAtoms.outerWidth(true) || |
||||
// if there's no items, use size of container |
||||
parentWidth; |
||||
|
||||
cols = Math.floor( parentWidth / colW ); |
||||
cols = Math.max( cols, 1 ); |
||||
|
||||
// i.e. this.masonry.cols = .... |
||||
this.masonry.cols = cols; |
||||
// i.e. this.masonry.columnWidth = ... |
||||
this.masonry.columnWidth = colW; |
||||
|
||||
return this; |
||||
}; |
||||
|
||||
$.Isotope.prototype._masonryReset = function() { |
||||
// layout-specific props |
||||
this.masonry = {}; |
||||
// FIXME shouldn't have to call this again |
||||
this._getCenteredMasonryColumns(); |
||||
var i = this.masonry.cols; |
||||
this.masonry.colYs = []; |
||||
while (i--) { |
||||
this.masonry.colYs.push( this.posTop ); |
||||
} |
||||
return this; |
||||
}; |
||||
|
||||
$.Isotope.prototype._masonryResize = function() { |
||||
var prevColCount = this.masonry.cols; |
||||
// get updated colCount |
||||
this._getCenteredMasonryColumns(); |
||||
if ( this.masonry.cols !== prevColCount ) { |
||||
// if column count has changed, do a new column cound |
||||
this.reLayout(); |
||||
} |
||||
|
||||
return this; |
||||
}; |
||||
|
||||
$.Isotope.prototype._masonryGetContainerSize = function() { |
||||
var itemsTotalWidth = 0; |
||||
this.$filteredAtoms.each(function(){ |
||||
itemsTotalWidth += $(this).outerWidth(true); |
||||
}); |
||||
|
||||
var layoutWidth = this.masonry.cols * this.masonry.columnWidth, |
||||
size = { |
||||
height : Math.max.apply( Math, this.masonry.colYs ) - this.posTop, |
||||
width : Math.min(layoutWidth, itemsTotalWidth ) |
||||
}; |
||||
return size; |
||||
|
||||
}; |
||||
|
||||
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 sort-buttons.js %} |
||||
|
||||
// change size of clicked element |
||||
$container.find('.element').live('click', function(){ |
||||
$(this).toggleClass('large'); |
||||
$container.isotope('reLayout'); |
||||
}); |
||||
|
||||
// toggle variable sizes of all elements |
||||
$('#toggle-sizes').find('a').click(function(){ |
||||
$container |
||||
.toggleClass('variable-sizes') |
||||
.isotope('reLayout'); |
||||
return false; |
||||
}); |
||||
|
||||
{% include add-buttons.js %} |
||||
|
||||
$('#shuffle a').click(function(){ |
||||
$container.isotope('shuffle'); |
||||
return false; |
||||
}); |
||||
|
||||
{% include option-buttons.js %} |
||||
|
||||
|
||||
$(function(){ |
||||
|
||||
// hacky way of adding random size classes |
||||
$container.find('.element').each(function(){ |
||||
if ( Math.random() > 0.6 ) { |
||||
$(this).addClass('width2'); |
||||
} |
||||
if ( Math.random() > 0.6 ) { |
||||
$(this).addClass('height2'); |
||||
} |
||||
}); |
||||
|
||||
|
||||
$container.isotope({ |
||||
itemSelector : '.element', |
||||
masonry : { |
||||
columnWidth : 120 |
||||
}, |
||||
animationEngine : $.browser.opera ? 'jquery' : 'best-available', |
||||
getSortData : { |
||||
symbol : function( $elem ) { |
||||
return $elem.attr('data-symbol'); |
||||
}, |
||||
category : function( $elem ) { |
||||
return $elem.attr('data-category'); |
||||
}, |
||||
number : function( $elem ) { |
||||
return parseInt( $elem.find('.number').text(), 10 ); |
||||
}, |
||||
weight : function( $elem ) { |
||||
return parseFloat( $elem.find('.weight').text().replace( /[\(\)]/g, '') ); |
||||
}, |
||||
name : function ( $elem ) { |
||||
return $elem.find('.name').text(); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
|
||||
}); |
||||
</script> |
Loading…
Reference in new issue