Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var currentCity, currentAge;
- function globalFilter(currentCity, currentAge) {
- console.log('current city is: ' + currentCity + ' & current age is: ' + currentAge);
- $('ul.the_loop').children('li').each(function() {
- if ($(this).data('age') == 'post_' + currentAge && $(this).hasClass("tag-" + currentCity)) {
- $(this).show();
- } else if (currentAge == undefined) {
- } else {
- $(this).hide();
- }
- });
- }
- function activeSelector(element) {
- if (element.hasClass('active-button')) {
- element.removeClass('active-button');
- } else {
- element.addClass('active-button');
- element.siblings('a').removeClass('active-button');
- }
- }
- $('#city-filter a').on('click', function() {
- clickCity = $(this).attr("id").split('-')[1];
- if (clickCity == currentCity) {
- currentCity = undefined;
- } else {
- currentCity = clickCity;
- }
- globalFilter(currentCity, currentAge);
- activeSelector($(this));
- });
- $('#age-filter a').on('click', function() {
- clickAge = $(this).attr("id").split('_')[1];
- if (clickAge == currentAge) {
- currentAge = undefined;
- } else {
- currentAge = clickAge;
- }
- globalFilter(currentCity, currentAge);
- activeSelector($(this));
- });
Advertisement
Add Comment
Please, Sign In to add comment