Permalink
Browse files

Optimized or-filter example.

  • Loading branch information...
1 parent d1de8ed commit 695ba4a8c23249cea85c8f1c2cd2183bb5bafb1c @Sebobo Sebobo committed Apr 14, 2013
Showing with 12 additions and 15 deletions.
  1. +0 −1 example-filter/css/style.css
  2. +12 −14 example-filter/or-filter.html
@@ -28,7 +28,6 @@
#tiles li.inactive {
opacity: 0;
- display: none !important;
}
#tiles li img {
@@ -100,8 +100,7 @@
<script type="text/javascript">
$(document).ready(new function() {
// This filter is later used as the selector for which grid items to show.
- var filter = '';
- var handler;
+ var filter = '', handler;
// Prepare layout options.
var options = {
@@ -131,22 +130,22 @@
* If they have changed, it also calls a refresh (see above).
*/
var updateFilters = function() {
- var oldFilter = filter;
- filter = '';
- var filters = [];
+ var oldFilter = filter,
+ filters = [];
// Collect filter list.
- var lis = $('#filters li');
- var i=0, length=lis.length, li;
- for(; i<length; i++) {
- li = $(lis[i]);
- if(li.hasClass('active')) {
- filters.push('#tiles li.'+li.attr('data-filter'));
+ var items = $('#filters li'),
+ i = 0, length = items.length, item;
+
+ for(; i < length; i++) {
+ item = items.eq(i);
+ if(item.hasClass('active')) {
+ filters.push('#tiles li.' + item.attr('data-filter'));
}
}
// If no filters active, set default to show all.
- if(filters.length == 0) {
+ if (filters.length == 0) {
filters.push('#tiles li');
}
@@ -163,9 +162,8 @@
* When a filter is clicked, toggle it's active state and refresh.
*/
var onClickFilter = function(event) {
- var item = $(event.currentTarget);
$('#filters li').removeClass('active');
- item.toggleClass('active');
+ $(event.currentTarget).toggleClass('active');
updateFilters();
}

0 comments on commit 695ba4a

Please sign in to comment.