Browse Source

Merge branch 'master' of github.com:desandro/isotope

pull/96/head
David DeSandro 14 years ago
parent
commit
b9b44ac8b3
  1. 23
      Makefile
  2. 159
      _posts/demos/2011-05-22-category-rows.html

23
Makefile

@ -1,23 +1,24 @@
JS_ENGINE ?= `which node nodejs`
ISO = jquery.isotope.js
ISO_MIN = jquery.isotope.min.js
JS = jquery.isotope.js
JS_MIN = jquery.isotope.min.js
SITE = isotope-site
# minifies jquery.isotope.js
# requires NodeJS and global uglify-js
min: ${ISO}
@@if test ! -z ${JS_ENGINE}; then \
echo "Minifying" ${ISO}; \
uglifyjs ${ISO} > ${ISO_MIN}.tmp; \
echo ';' >> ${ISO_MIN}.tmp; \
sed 's/\*\//&§/; y/§/\n/;' ${ISO_MIN}.tmp > ${ISO_MIN}; \
rm ${ISO_MIN}.tmp; \
echo "Minifying" ${JS}; \
uglifyjs ${JS} > ${JS_MIN}.tmp; \
echo ';' >> ${JS_MIN}.tmp; \
sed 's/\*\//&§/g; y/§/\n/;' ${JS_MIN}.tmp > ${JS_MIN}; \
rm ${JS_MIN}.tmp; \
else \
echo "NodeJS required for minification."; \
fi
# creates zip file of site
zip: _site
mkdir isotope-site
cp -r _site/ isotope-site
zip -r ~/Desktop/isotope-site.zip isotope-site/
rm -rf isotope-site
mkdir ${SITE}
cp -r _site/ ${SITE}
zip -r ~/Desktop/${SITE}.zip ${SITE}/
rm -rf ${SITE}

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

@ -0,0 +1,159 @@
---
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>
Loading…
Cancel
Save