Guest User

filter-jquery

a guest
Oct 13th, 2013
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var currentCity, currentAge;
  2.  
  3. function globalFilter(currentCity, currentAge) {
  4.     console.log('current city is: ' + currentCity + ' & current age is: ' + currentAge);
  5.  
  6.     $('ul.the_loop').children('li').each(function() {
  7.         if ($(this).data('age') == 'post_' + currentAge && $(this).hasClass("tag-" + currentCity)) {
  8.             $(this).show();
  9.         } else if (currentAge == undefined) {
  10.            
  11.         } else {
  12.             $(this).hide();
  13.         }
  14.     });
  15.    
  16.    
  17. }
  18.  
  19. function activeSelector(element) {
  20.     if (element.hasClass('active-button')) {
  21.         element.removeClass('active-button');
  22.     } else {
  23.         element.addClass('active-button');
  24.         element.siblings('a').removeClass('active-button');
  25.     }
  26. }
  27.  
  28. $('#city-filter a').on('click', function() {
  29.     clickCity = $(this).attr("id").split('-')[1];
  30.     if (clickCity == currentCity) {
  31.         currentCity = undefined;
  32.     } else {
  33.         currentCity = clickCity;
  34.     }
  35.     globalFilter(currentCity, currentAge);
  36.     activeSelector($(this));
  37. });
  38.  
  39. $('#age-filter a').on('click', function() {
  40.     clickAge = $(this).attr("id").split('_')[1];
  41.     if (clickAge == currentAge) {
  42.         currentAge = undefined;
  43.     } else {
  44.         currentAge = clickAge;
  45.     }
  46.     globalFilter(currentCity, currentAge);
  47.     activeSelector($(this));
  48. });
Advertisement
Add Comment
Please, Sign In to add comment