' ); wp.ajax.post( 'bkg_geo_map_display_default_data', { map_id:mapID,law:lawID } ).done(function(response) { if(response){ //jQuery( '#default_'+mapID ).html( response ); jQuery( '#map_data_content').html( response ); iMapsManager.clearSelected( mapID ); }else{ jQuery( '#map_data_content' ).val('Sorry unable to get data at this time.'); } }); setmapcolors(); }); function mapclick(state_id){ var get_text = jQuery('#st_'+state_id).text(); jQuery('.state_dropdown_wrapper.active').removeClass('active'); jQuery( '#map_data_content' ).html( '
Loading...
' ); jQuery('.state_dropdown_wrapper span').text(get_text); jQuery('.state_dropdown_wrapper li.active_state').removeClass('active_state'); jQuery('#st_'+state_id).addClass('active_state'); wp.ajax.post( 'bkg_geo_map_display_state_data', { state_id:state_id,law:lawID } ).done(function(response) { if(response){ jQuery( '#map_data_content' ).html( response ); }else{ jQuery( '#map_data_content' ).val('Sorry unable to get data at this time.'); } }); } // STATE DROPDOWN jQuery(document).on('click','.state_dropdown li',function(){ var get_rel = jQuery(this).attr('rel'); var get_text = jQuery(this).text(); jQuery('.state_dropdown_wrapper span').text(get_text); jQuery('.state_dropdown_wrapper.active').removeClass('active'); if(get_rel=="reset"){ jQuery( '#map_data_content' ).html( '
Loading...
' ); wp.ajax.post( 'bkg_geo_map_display_default_data', { map_id:mapID,law:lawID } ).done(function(response) { if(response){ //jQuery( '#default_'+mapID ).html( response ); jQuery( '#map_data_content').html( response ); jQuery('.state_dropdown_wrapper.active').removeClass('active'); iMapsManager.clearSelected( mapID ); }else{ jQuery( '#map_data_content' ).val('Sorry unable to get data at this time.'); } }); }else{ iMapsManager.select(mapID,'US-'+get_rel); } }); jQuery(document).on('click','.state_dropdown_wrapper',function(){ jQuery('.state_laws_dropdown_wrapper.active').removeClass('active'); if(jQuery(this).hasClass('active')){ jQuery(this).removeClass('active'); }else{ jQuery(this).addClass('active'); } }); jQuery(document).on('click','.state_dropdown_wrapper .state_dropdown',function(){ jQuery(this).parent('.active').removeClass('active'); }); jQuery(document).on('click','.state_dropdown_wrapper .state_dropdown li',function(){ jQuery('.state_dropdown .active_state').removeClass('active_state'); jQuery('.state_laws_dropdown .active_state').removeClass('active_state'); jQuery(this).addClass('active_state'); jQuery('.state_dropdown.active').removeClass('active'); jQuery('.state_laws_dropdown_wrapper.active').removeClass('active'); }); // STATE LAWS DROPDOWN jQuery(document).on('click','.state_laws_dropdown li',function(){ var law_id = jQuery(this).attr('rel'); jQuery('.state_laws_dropdown_wrapper.active').removeClass('active'); jQuery( '#map_data_content' ).html( '
Loading...
' ); let path = window.location.href.split('?')[0] if(law_id=='reset'){ window.location.replace(path); }else{ window.location.replace(path+"?law="+law_id); } }); jQuery(document).on('click','.state_laws_dropdown_wrapper',function(){ jQuery('.state_dropdown_wrapper.active').removeClass('active'); if(jQuery(this).hasClass('active')){ jQuery(this).removeClass('active'); }else{ jQuery(this).addClass('active'); } }); jQuery(document).on('click','.state_laws_dropdown_wrapper .state_laws_dropdown li',function(){ jQuery('.state_laws_dropdown .active_state').removeClass('active_state'); jQuery('.state_dropdown .active_state').removeClass('active_state'); jQuery(this).addClass('active_state'); jQuery('.state_dropdown.active').removeClass('active'); jQuery('.state_laws_dropdown_wrapper.active').removeClass('active'); }); // STATE DATA TABS jQuery(document).on('click','.state_data_wrapper .state_data_tabs .state_tab',function(){ var get_rel = jQuery(this).attr('rel'); jQuery('.state_data_wrapper .state_data_tabs .state_tab.active').removeClass('active'); jQuery('.state_data_wrapper ul.active').removeClass('active'); jQuery(this).addClass('active'); jQuery('.state_data_wrapper ul.'+get_rel).addClass('active'); }); // CHECK IF MAP STAGE IS DARK AND CHANGE STATE ABV COLOR TO WHITE function setmapcolors(){ jQuery( ".set_map_text_color" ).each(function( index ) { var get_state = jQuery( this ).attr('data-state'); var get_color = jQuery( this ).attr('data-color'); const avoidstates = ["VT","MA","CT","MD","DC","NH","RI","NJ","DE"]; if (isTooDark(get_color)){ if(!avoidstates.includes(get_state) ){ jQuery('.imapsContainer .imapsSeries-group tspan:contains("'+get_state+'")').css('fill', '#ffffff'); } } }); jQuery("#custom_legends_wrapper").insertAfter(jQuery("#map_container")).show(); } function isTooDark(hexcolor){ var r = parseInt(hexcolor.substr(1,2),16); var g = parseInt(hexcolor.substr(3,2),16); var b = parseInt(hexcolor.substr(4,2),16); var yiq = ((r*299)+(g*587)+(b*114))/1000; // Return new color if to dark, else return the original //return (yiq < 40) ? '#2980b9' : hexcolor; return (yiq < 120); // RETURNS TRUE OR FALSE }