Skip to content

Instantly share code, notes, and snippets.

@v9n
Forked from 140bytes/LICENSE.txt
Created August 3, 2011 02:10
Show Gist options
  • Save v9n/1121737 to your computer and use it in GitHub Desktop.
Save v9n/1121737 to your computer and use it in GitHub Desktop.
Element Filter V2 (ref#1120350)

140byt.es

A tweet-sized, fork-to-play, community-curated collection of JavaScript.

How to play

  1. Click the Fork button above to fork this gist.
  2. Modify all the files to according to the rules below.
  3. Save your entry and tweet it up!

Keep in mind that thanks to the awesome sensibilities of the GitHub team, gists are just repos. So feel free to clone yours and work locally for a more comfortable environment, and to allow commit messages.

Rules

All entries must exist in an index.js file, whose contents are

  1. an assignable, valid Javascript expression that
  2. contains no more than 140 bytes, and
  3. does not leak to the global scope.

All entries must also be licensed under the WTFPL or equally permissive license.

For more information

See the 140byt.es site for a showcase of entries (built itself using 140-byte entries!), and follow @140bytes on Twitter.

To learn about byte-saving hacks for your own code, or to contribute what you've learned, head to the wiki.

140byt.es is brought to you by Jed Schmidt, with help from Alex Kloss. It was inspired by work from Thomas Fuchs and Dustin Diaz.

function(
n, //Navigation jQuery Object
s, //Source jQuery object (element container)
l //item selector inside source object
)
{
n.click(function(){
n=$(this); //Saving variable name
$(l,s).hide().each( //Hide all element inside containers
function(i,e){
$(e).hasClass(n.attr('class'))&&$(e).fadeIn() //We just display element has the same class with navigation filter
})
})
}
function(n,s,l){n.click(function(){n=$(this);$(l,s).hide().each(function(i,e){$(e).hasClass(n.attr('class'))&&$(e).fadeIn()})})}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "filter",
"description": "Filter Elements",
"keywords": [
"gallery",
"filter",
"container",
"quicksand",
"isotope"
]
}
<!DOCTYPE html>
<head>
<style>
a {text-decoration: none; margin: 5px;}
li {display: inline-block;}
#portfolio-nav > a {height: 20px; font-size: 1.2em; color: red;}
#portfolio-nav > a:target {color: magenta;}
ul > li {margin: 10px; list-style: none}
ul:after {content: ""; display: block; clear: both}
</style>
</head>
<body>
<title>Element Filter</title>
<p>
Simple kind of <a href="http://razorjack.net/quicksand/">jQuery Quicksand</a>. The same effect without many animations,
but easy to implement ;). View source to learn more.
It's hard to name this kind of effect but you can take a look <a href="http://axcoto.com/labs/140byt/filter/v2/test.html#magento">here</a>
</p>
<p>
This version use only one place holder for elements. Version 1 can be see <a href="https://gist.github.com/1120350">here</a>
</p>
<div id="portfolio-nav">
<a id="all" class="all" href="test.html#all">All</a>
<a id="app" class="webapp" href="test.html#app">Web/App</a>
<a id="wordpress" class="wordpress" href="test.html#wordpress">Wordpress</a>
<a id="ee" class="ee" href="test.html#ee">ExpressionEngine</a>
<a id="joomla" class="joomla" href="test.html#joomla">Joomla</a>
<a id="magento" class="magento" href="test.html#magento">Magento</a>
</div>
</div>
<ul id="portfolio">
<li class="start all wordpress">
<a href="#" >Asia</a>
</li>
<li class=" all zendcart">
<a href="#" >Bagvine</a>
</li>
<li class=" all joomla">
<a href="#" >Broadway</a>
</li>
<li class="last all zendcart">
<a href="#" >carkey</a>
</li>
<li class="start all webapp">
<a href="#" >Freshbox</a>
</li>
<li class=" all webapp">
<a href="#" >AGBA</a>
</li>
<li class=" all joomla">
<a href="#" >HueCt</a>
</li>
<li class="last all zendcart">
<a href="#" >Moda</a>
</li>
<li class="start all wordpress">
<a href="#" >QuickTIme</a>
</li>
<li class=" all zendcart">
<a href="#" >Plaza</a>
</li>
<li class=" all zendcart">
<a href="#" >SolarLink</a>
</li>
<li class="last all wordpress">
<a href="#" >WBC</a>
</li>
<li class="start all wordpress">
<a href="#" >FKC</a>
</li>
<li class=" all ee">
<a href="#" >EE</a>
</li>
<li class=" all magento">
<a href="#" >GReen Boom</a>
</li>
<li class="last all wordpress">
<a href="#" >Hospital</a>
</li>
<li class="start all webapp">
<a href="#" >Alta</a>
</li>
<li class=" all ee">
<a href="#" >EFL</a>
</li>
<li class=" all wordpress">
<a href="#" >FBC</a>
</li>
<li class="last all wordpress">
<a href="#" >Greenworld</a>
</li>
<li class="start all wordpress">
<a href="#" >Happy Hour</a>
</li>
<li class=" all ee">
<a href="#" >InfoCreek</a>
</li>
<li class=" all wordpress">
<a href="#" >Just Stance</a>
</li>
<li class="last all wordpress">
<a href="#" >Wayout Tech</a>
</li>
<li class="start all webapp">
<a href="#" >Ritelogic</a>
</li>
<li class=" all webapp">
<a href="#" >Twbadge</a>
</li>
<li class=" all webapp">
<a href="#" >Pocoo</a>
</li>
<li class="last all webapp">
<a href="#" >MangaAndMe</a>
</li>
<li class="start all wordpress">
<a href="#" >DMV</a>
</li>
<li class=" all webapp">
<a href="#" >Buzz</a>
</li>
</ul>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script>
$(document).ready(function () {
/**
n: nav
s: source
l: sub item selector
*/
var filterElements=
function(n,s,l){n.click(function(){n=$(this);$(l,s).hide().each(function(i,e){$(e).hasClass(n.attr('class'))&&$(e).fadeIn()})})}
var buttons = $('#portfolio-nav > a');
var folioContainer = $('#portfolio');
filterElements(buttons, folioContainer, 'li');
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment