$(function() { function intersects( list1, list2 ) { return _.intersection( list1, list2 ).length > 0; } WOF.showPolicyMapPopup = function(d, tooltip, payload){ // Accepts a payload of interventinos, and a dom element to update // updates the policy map popup with the correct numbers of intervention // present, based on the current active filters log.debug("Defaulting to the normal behaviour for now"); // find function to return a list of interventions in the payload // that have the same active filters // WOF.selectedCategories; counter = 0; _.each(payload.interventions_with_kinds, function(p) { p.kinds }); tooltip.html(d.properties.hover.split("\n").join('
')); log.debug(payload); log.debug(tooltip); }; WOF.filterDetailPanel = function() { $interventionTable = $('table.policy-intervention-table'); $noInterventions = $('.no-policy-interventions'); var rowsVisible = 0; $interventionTable.find('tbody tr').each(function() { var $row = $(this); var rowCategories = $(this).data('intervention-types'); var showRow = intersects( rowCategories, WOF.selectedCategories ); if(showRow) { $row.show(); rowsVisible++; } else { $row.hide(); } }); if(rowsVisible > 0) { $interventionTable.show(); $noInterventions.hide(); } else { $interventionTable.hide(); $noInterventions.show(); } $('.filtered-count').text(rowsVisible); }; function filterMap() { var matchingCountries = _.filter(WOF.allCountryData, function(country) { if(country.payload.length > 0) { return intersects(country.payload[0].kinds, WOF.selectedCategories); } return false; }); var matchingCountryIds = _.pluck(matchingCountries, 'iso3166_a3'); WOF.resetMap(function(countryId) { var data = _.contains(matchingCountryIds, countryId) ? 1 : 0; return data; }); } function setFilterCategories() { WOF.selectedCategories = []; $('.policy-map-controls input:checked').each(function() { WOF.selectedCategories.push( $(this).attr('name') ); }); } $('.policy-map-controls input[type=checkbox]').change(function() { $(this).parent().toggleClass('inactive'); setFilterCategories(); filterMap(); WOF.filterDetailPanel(); }); setFilterCategories(); });