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.
406 lines
19 KiB
406 lines
19 KiB
<!doctype html> |
|
<html lang="en"> |
|
<head> |
|
<meta charset="utf-8" /> |
|
<title>jQuery Mercutio › Filtering hashes</title> |
|
|
|
<link rel="stylesheet" href="css/style.css" media="screen" /> |
|
<style> |
|
.wrap { overflow: hidden;} |
|
</style> |
|
|
|
<!-- scripts are located at the bottom of the markup --> |
|
|
|
</head> |
|
<body> |
|
|
|
<div id="site-nav"> |
|
<h1>jQuery Mercutio</h1> |
|
<ul> |
|
<li><a href=".">Primer</a></li> |
|
<li><a href="basic-single-column.html">Basic single-column</a></li> |
|
<li><a href="basic-multi-column.html">Basic multi-column</a></li> |
|
<li><a href="tumblelog.html">Tumblelog</a></li> |
|
<li><a href="appending.html">Appending</a></li> |
|
<li><a href="infinite-scroll.html">Infinite Scroll</a></li> |
|
<li><a href="animating-jquery.html">Animating with jQuery</a></li> |
|
<li><a href="animating-css-transitions.html">Animating with CSS transitions</a></li> |
|
<li><a href="filtering.html">Filtering</a></li> |
|
<li class="selected"><a href="filtering-hashes.html#red">Filtering hashes</a> |
|
<ul> |
|
<li><a href="#content">Top</a></li> |
|
<li><a href="#code">Code</a></li> |
|
<li><a href="#demo">Demo</a></li> |
|
</ul> |
|
</li> |
|
</ul> |
|
</div> |
|
|
|
<div id="content"> |
|
|
|
<h1>Filtering hashes</h1> |
|
|
|
<div class="copy"> |
|
<p>This example builds on the filtering demo, taking into consideration URL hashes. This way, users can enter in a URL with a hash and be presented with content that is automatically filtered. For example, in these docs, the link to this page includes <code>#red</code>. On <code>$(window).load</code> the hash tag is check to see if it matches the colors used to filter the elements, red, gray, and black. If there is a match, the elements are filtered and then the layout is arranged.</p> |
|
|
|
<pre id="code"><code><span class="storage">var</span> |
|
speed <span class="keyword">=</span> <span class="constant">1000</span>, <span class="comment">// animation speed</span> |
|
<span class="keyword">$</span>wall <span class="keyword">=</span> <span class="keyword">$</span>(<span class="string">'#demo'</span>).find(<span class="string">'.wrap'</span>), |
|
|
|
mercutioOptions <span class="keyword">=</span> { <span class="comment">// initial mercutio options</span> |
|
columnWidth: <span class="constant">100</span>, |
|
itemSelector: <span class="string">'.box:not(.invis)'</span>, |
|
animate: <span class="constant">true</span>, |
|
animationOptions: { |
|
duration: speed, |
|
queue: <span class="constant">false</span> |
|
} |
|
} |
|
; |
|
|
|
<span class="comment">// run on window.load so we can capture any incoming hashes</span> |
|
<span class="keyword">$</span>(<span class="id">window</span>).load(<span class="storage">function</span>(){ |
|
<span class="comment">// run mercutio on start-up to capture all the boxes we'll need</span> |
|
<span class="keyword">$</span>wall.mercutio(mercutioOptions); |
|
<span class="keyword">if</span> ( <span class="id">window</span>.<span class="keyword">location</span>.<span class="keyword">hash</span> ) { |
|
<span class="comment">// get rid of the '#' from the hash</span> |
|
<span class="storage">var</span> possibleFilterClass <span class="keyword">=</span> <span class="id">window</span>.<span class="keyword">location</span>.<span class="keyword">hash</span>.replace(<span class="string">'#'</span>, <span class="string">''</span>); |
|
<span class="keyword">switch</span> (possibleFilterClass) { |
|
<span class="comment">// if the hash matches the following words</span> |
|
<span class="keyword">case</span> <span class="string">'red'</span> : <span class="keyword">case</span> <span class="string">'gray'</span> : <span class="keyword">case</span> <span class="string">'black'</span> : |
|
<span class="comment">// set mercutio options animate to false</span> |
|
mercutioOptions.animate <span class="keyword">=</span> false; |
|
<span class="comment">// hide boxes that don't match the filter class</span> |
|
<span class="keyword">$</span>wall.children().not(<span class="string">'.'</span><span class="keyword">+</span>possibleFilterClass) |
|
.toggleClass(<span class="string">'invis'</span>).hide(); |
|
<span class="comment">// run mercutio again, this time with the necessary stuff hidden</span> |
|
<span class="keyword">$</span>wall.mercutio(mercutioOptions); |
|
<span class="keyword">break</span>; |
|
} |
|
} |
|
}); |
|
|
|
<span class="keyword">$</span>(<span class="string">'#filtering-nav a'</span>).click(<span class="storage">function</span>(){ |
|
<span class="storage">var</span> |
|
color <span class="keyword">=</span> <span class="keyword">$</span>(<span class="constant">this</span>).attr(<span class="string">'class'</span>), |
|
filterClass <span class="keyword">=</span> <span class="string">'.'</span> <span class="keyword">+</span> color; |
|
; |
|
|
|
<span class="keyword">if</span> (filterClass <span class="keyword">==</span> <span class="string">'.all'</span>) { |
|
<span class="comment">// show all hidden boxes</span> |
|
<span class="keyword">$</span>wall.children(<span class="string">'.invis'</span>) |
|
.toggleClass(<span class="string">'invis'</span>).fadeIn(speed); |
|
} <span class="keyword">else</span> { |
|
<span class="comment">// hide visible boxes </span> |
|
<span class="keyword">$</span>wall.children().not(filterClass).not(<span class="string">'.invis'</span>) |
|
.toggleClass(<span class="string">'invis'</span>).fadeOut(speed); |
|
<span class="comment">// show hidden boxes</span> |
|
<span class="keyword">$</span>wall.children(filterClass<span class="keyword">+</span>'.invis') |
|
.toggleClass(<span class="string">'invis'</span>).fadeIn(speed); |
|
} |
|
<span class="keyword">$</span>wall.mercutio({ animate: <span class="constant">true</span> }); |
|
<span class="comment">// set hash in URL</span> |
|
<span class="id">window</span>.<span class="keyword">location</span>.<span class="keyword">hash</span> <span class="keyword">=</span> color; |
|
<span class="keyword">return</span> <span class="constant">false</span>; |
|
});</code></pre> |
|
|
|
</div><!-- .copy --> |
|
|
|
<div id="demo"> |
|
|
|
<ul id="filtering-nav"> |
|
<li><a class="gray" href="#gray">Gray</a></li> |
|
<li><a class="red" href="#red">Red</a></li> |
|
<li><a class="black" href="#black">Black</a></li> |
|
<li><a class="all" href="#all">All</a></li> |
|
</ul> |
|
|
|
|
|
<div class="wrap"> |
|
|
|
<div class="box col2 gray"> |
|
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio. Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper suscipit, posuere a, pede.</p> |
|
</div> |
|
|
|
<div class="box col1 red"> |
|
<p>Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris sit amet orci. </p> |
|
</div> |
|
|
|
<div class="box col1 black"> |
|
<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula </p> |
|
</div> |
|
|
|
<div class="box gray"> |
|
<h2>This is the box with no width set</h2> |
|
</div> |
|
|
|
<div class="box col1 red"> |
|
<h2>Sit amet mi ullamcorper vehicula</h2> |
|
</div> |
|
|
|
<div class="box col1 gray"> |
|
<p>adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus.</p> |
|
</div> |
|
|
|
<div class="box col2 gray"> |
|
<p>Sit amet mi ullamcorper vehicula</p> |
|
</div> |
|
|
|
<div class="box col1 black"> |
|
<p>Phasellus pede arcu, dapibus eu, fermentum et, dapibus sed, urna.</p> |
|
</div> |
|
|
|
<div class="box col2 gray"> |
|
<p>Ut condimentum mi vel tellus. Suspendisse laoreet. Fusce ut est sed dolor gravida convallis. Morbi vitae ante. Vivamus ultrices luctus nunc. Suspendisse et dolor. Etiam dignissim. Proin malesuada adipiscing lacus. Donec metus. Curabitur gravida.</p> |
|
<p>Phasellus pede arcu, dapibus eu, fermentum et, dapibus sed, urna.</p> |
|
</div> |
|
|
|
<div class="box col3 black"> |
|
<p>Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus. Sed vel lacus. Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus. Nunc tellus ante, mattis eget, gravida vitae, ultricies ac, leo. Integer leo pede, ornare a, lacinia eu, vulputate vel, nisl.</p> |
|
</div> |
|
|
|
<div class="box col1 red"> |
|
<p>Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus. Praesent elementum hendrerit tortor. Sed semper lorem at felis.</p> |
|
</div> |
|
|
|
<div class="box col2 gray"> |
|
<p>Vestibulum volutpat, lacus a ultrices sagittis,</p> |
|
<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula </p> |
|
</div> |
|
|
|
<div class="box col2 black"> |
|
<p>Sit amet mi ullamcorper vehicula</p> |
|
</div> |
|
|
|
<div class="box col1 gray"> |
|
<p>Morbi purus libero</p> |
|
</div> |
|
|
|
<div class="box col1 black"> |
|
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio. Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper suscipit, posuere a, pede.</p> |
|
</div> |
|
|
|
<div class="box col3 black"> |
|
<p>Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris sit amet orci. Aenean dignissim pellentesque felis.</p> |
|
<p>Vestibulum volutpat, lacus a ultrices sagittis,</p> |
|
<ul> |
|
<li>Lacus a ultrices sagittis</li> |
|
<li>Democratis</li> |
|
<li>Plummus</li> |
|
</ul> |
|
</div> |
|
|
|
<div class="box col1 red"> |
|
<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula </p> |
|
</div> |
|
|
|
<div class="box col1 gray"> |
|
<p>Sit amet mi ullamcorper vehicula</p> |
|
</div> |
|
|
|
<div class="box col1 black"> |
|
<h2>Morbi purus libero</h2> |
|
</div> |
|
|
|
|
|
<div class="box col2 gray"> |
|
<p>Ut condimentum mi vel tellus. Suspendisse laoreet. Fusce ut est sed dolor gravida convallis. Morbi vitae ante. Vivamus ultrices luctus nunc. Suspendisse et dolor. Etiam dignissim. Proin malesuada adipiscing lacus. Donec metus. Curabitur gravida.</p> |
|
<p>Phasellus pede arcu, dapibus eu, fermentum et, dapibus sed, urna.</p> |
|
</div> |
|
|
|
<div class="box col1 gray"> |
|
<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula</p> |
|
</div> |
|
|
|
<div class="box col3 red"> |
|
<p>Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus. Praesent elementum hendrerit tortor. Sed semper lorem at felis.</p> |
|
<p>Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus. Sed vel lacus. Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus. Nunc tellus ante, mattis eget, gravida vitae, ultricies ac, leo. Integer leo pede, ornare a, lacinia eu, vulputate vel, nisl.</p> |
|
<p>Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus. Sed vel lacus. Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus. Nunc tellus ante, mattis eget, gravida vitae, ultricies ac, leo. Integer leo pede, ornare a, lacinia eu, vulputate vel, nisl.</p> |
|
</div> |
|
|
|
|
|
<div class="box col1 black"> |
|
<p>adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus.</p> |
|
</div> |
|
|
|
<div class="box col2 red"> |
|
<p>Sit amet mi ullamcorper vehicula</p> |
|
</div> |
|
|
|
<div class="box col1 red"> |
|
<p>Phasellus pede arcu, dapibus eu, fermentum et, dapibus sed, urna.</p> |
|
</div> |
|
|
|
<div class="box col1 black"> |
|
<h2>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula </h2> |
|
</div> |
|
|
|
<div class="box col2 black"> |
|
<p>Ut convallis, sem sit amet interdum consectetuer, odio augue aliquam leo, nec dapibus tortor nibh sed augue.</p> |
|
<p>Ut condimentum mi vel tellus. Suspendisse laoreet. Fusce ut est sed dolor gravida convallis. Morbi vitae ante. Vivamus ultrices luctus nunc. Suspendisse et dolor. Etiam dignissim. Proin malesuada adipiscing lacus. Donec metus. Curabitur gravida.</p> |
|
</div> |
|
|
|
<div class="box col1 red"> |
|
|
|
<ul> |
|
<li>Lacus a ultrices sagittis</li> |
|
<li>Democratis</li> |
|
<li>Plummus</li> |
|
</ul> |
|
</div> |
|
|
|
<div class="box col1 gray"> |
|
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio. Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper suscipit, posuere a, pede.</p> |
|
</div> |
|
|
|
<div class="box col1 red"> |
|
<p>Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus. Praesent elementum hendrerit tortor. Sed semper lorem at felis.</p> |
|
</div> |
|
<div class="box col1 red"> |
|
<p>Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus. Sed vel lacus. </p> |
|
</div> |
|
|
|
|
|
<div class="box col1 black"> |
|
<p>Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris sit amet orci. </p> |
|
</div> |
|
|
|
<div class="box col1 red"> |
|
<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula </p> |
|
</div> |
|
|
|
<div class="box col1 gray"> |
|
<h2>Sit amet mi ullamcorper vehicula adipiscing varius</h2> |
|
</div> |
|
<div class="box col1 gray"> |
|
<p>Nunc tellus ante, mattis eget, gravida vitae, ultricies ac, leo. Integer leo pede, ornare a, lacinia eu, vulputate vel, nisl.</p> |
|
</div> |
|
|
|
|
|
<div class="box col3 red"> |
|
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Phasellus hendrerit. Pellentesque aliquet nibh nec urna. In nisi neque, aliquet vel, dapibus id, mattis vel, nisi. Sed pretium, ligula sollicitudin laoreet viverra, tortor libero sodales leo, eget blandit nunc tortor eu nibh. Nullam mollis. Ut justo. Suspendisse potenti.</p> |
|
<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula </p> |
|
<p>Morbi interdum mollis sapien. Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus.</p> |
|
</div> |
|
|
|
<div class="box col2 gray"> |
|
<p>adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus.</p> |
|
<p>Ut convallis, sem sit amet interdum consectetuer, odio augue aliquam leo, nec dapibus tortor nibh sed augue. Sed vel lacus. Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus. Nunc tellus ante, mattis eget, gravida vitae, ultricies ac, leo. Integer leo pede, ornare a, lacinia eu, vulputate vel, nisl.</p> |
|
</div> |
|
|
|
<div class="box col1 red"> |
|
<p>Phasellus pede arcu, dapibus eu, fermentum et, dapibus sed, urna.</p> |
|
</div> |
|
|
|
<div class="box col1 black"> |
|
<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula</p> |
|
</div> |
|
|
|
<div class="box col3 gray"> |
|
<p>Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus. Praesent elementum hendrerit tortor. Sed semper lorem at felis.</p> |
|
<p>Sed ac risus. Phasellus lacinia, magna a ullamcorper laoreet, lectus arcu pulvinar risus, vitae facilisis libero dolor a purus. Sed vel lacus. Mauris nibh felis, adipiscing varius, adipiscing in, lacinia vel, tellus. Suspendisse ac urna. Etiam pellentesque mauris ut lectus. Nunc tellus ante, mattis eget, gravida vitae, ultricies ac, leo. Integer leo pede, ornare a, lacinia eu, vulputate vel, nisl.</p> |
|
</div> |
|
|
|
|
|
|
|
<div class="box col1 black"> |
|
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec odio. Quisque volutpat mattis eros. Nullam malesuada erat ut turpis. Suspendisse urna nibh, viverra non, semper suscipit, posuere a, pede.</p> |
|
</div> |
|
|
|
<div class="box col1 black"> |
|
<p>Donec nec justo eget felis facilisis fermentum. Aliquam porttitor mauris sit amet orci. </p> |
|
</div> |
|
|
|
<div class="box col1 red"> |
|
<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula </p> |
|
</div> |
|
|
|
<div class="box col2 gray"> |
|
<p>Vestibulum volutpat, lacus a ultrices sagittis,</p> |
|
<p>Fusce accumsan mollis eros. Pellentesque a diam sit amet mi ullamcorper vehicula </p> |
|
<p>Morbi purus libero, faucibus adipiscing, commodo quis, gravida id, est. Sed lectus. Praesent elementum hendrerit tortor. Sed semper lorem at felis.</p> |
|
</div> |
|
|
|
</div> <!-- .wrap --> |
|
|
|
</div> <!-- #demo --> |
|
|
|
<p id="footer"> |
|
jQuery Mercutio by <a href="http://desandro.com/">David DeSandro</a> |
|
</p> |
|
|
|
</div> <!-- #content --> |
|
|
|
<script src="js/jquery-1.4.2.min.js"></script> |
|
<script src="../jquery.mercutio.js"></script> |
|
<script> |
|
$(function(){ |
|
|
|
var |
|
speed = 1000, // animation speed |
|
$wall = $('#demo').find('.wrap'), |
|
|
|
mercutioOptions = { // initial mercutio options |
|
columnWidth: 100, |
|
itemSelector: '.box:not(.invis)', |
|
animate: true, |
|
animationOptions: { |
|
duration: speed, |
|
queue: false |
|
} |
|
} |
|
; |
|
|
|
// run on window.load so we can capture any incoming hashes |
|
$(window).load(function(){ |
|
// run mercutio on start-up to capture all the boxes we'll need |
|
$wall.mercutio(mercutioOptions); |
|
if ( window.location.hash ) { |
|
// get rid of the '#' from the hash |
|
var possibleFilterClass = window.location.hash.replace('#', ''); |
|
switch (possibleFilterClass) { |
|
// if the hash matches the following words |
|
case 'red' : case 'gray' : case 'black' : |
|
// set mercutio options animate to false |
|
mercutioOptions.animate = false; |
|
// hide boxes that don't match the filter class |
|
$wall.children().not('.'+possibleFilterClass) |
|
.toggleClass('invis').hide(); |
|
// run mercutio again, this time with the necessary stuff hidden |
|
$wall.mercutio(mercutioOptions); |
|
break; |
|
} |
|
} |
|
|
|
}); |
|
|
|
$('#filtering-nav a').click(function(){ |
|
var |
|
color = $(this).attr('class'), |
|
filterClass = '.' + color; |
|
; |
|
|
|
if(filterClass=='.all') { |
|
// show all hidden boxes |
|
$wall.children('.invis') |
|
.toggleClass('invis').fadeIn(speed); |
|
} else { |
|
// hide visible boxes |
|
$wall.children().not(filterClass).not('.invis') |
|
.toggleClass('invis').fadeOut(speed); |
|
// show hidden boxes |
|
$wall.children(filterClass+'.invis') |
|
.toggleClass('invis').fadeIn(speed); |
|
|
|
} |
|
$wall.mercutio({ animate: true }); |
|
// set hash in URL |
|
window.location.hash = color; |
|
return false; |
|
}); |
|
|
|
}); |
|
</script> |
|
|
|
</body> |
|
</html> |