$(document).ready(function() { function refresh_type_options() { var categories = {}, category; $('.PubEventCont:visible').each(function(i, el){ category = $(el).data('type'); if (categories.hasOwnProperty(category)) { categories[category] += 1; } else { categories[category] = 1; } }); $("#type option").hide(); $("#type option[value='all']").show(); for (var key in categories) $("#type option[value='"+key+"']").show(); } function refresh_country() { if($("#country").find("option:selected").val()!="all") { $(".PubEventCont").hide(); $(".PubEventCont[data-country='"+$("#country").find("option:selected").val()+"']").fadeIn(); refresh_type_options(); } else { $(".PubEventCont").show(); refresh_type_options(); refresh_type(); } } function refresh_type() { if($("#type").find("option:selected").val()!="all") { if($("#country").find("option:selected").val()!="all") { $(".PubEventCont[data-country='"+$("#country").find("option:selected").val()+"']").hide(); $(".PubEventCont[data-country='"+$("#country").find("option:selected").val()+"'][data-type='"+$("#type").find("option:selected").val()+"']").fadeIn(); } else { $(".PubEventCont").hide(); $(".PubEventCont[data-type='"+$("#type").find("option:selected").val()+"']").fadeIn(); } } /* $("#type").show(); $(".PubEventCont").hide(); $(".PubEventCont[data-country='"+$("#country").find("option:selected").val()+"']").fadeIn(); if($("#type").find("option:selected").val()!="") { $(".PubEventCont[data-country='"+$("#country").find("option:selected").val()+"'][data-type='"+$("#type")+"']".find("option:selected").val()+"']").fadeIn(); } else { $(".PubEventCont[data-country='"+$("#country").find("option:selected").val()+"']").fadeIn(); } } else { $(".PubEventCont").show(); } */ } $("#country").on("change", function() { $("#type").show(); $("#type option[value='all']").prop('selected', true); refresh_country(); }); $("#type").on("change", function() { refresh_type(); }); refresh_country(); refresh_type_options(); refresh_type(); }); //# sourceURL=public.js