From e72d0f84429021225e6b54f42844fc5994089d6c Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 13 Jan 2015 11:35:42 +0100 Subject: [PATCH] show correct selection of years on load because of caching, checkboxes state will be preserved over reloads, so we need to check them and display appropriate years --- html.pl | 53 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 17 deletions(-) diff --git a/html.pl b/html.pl index 26d1433..949563d 100755 --- a/html.pl +++ b/html.pl @@ -432,7 +432,7 @@ foreach my $row ( sort { $a->{full_name} cmp $b->{full_name} } @authors ) { print $fh qq|Godine:|; my $type_cat_count = {}; foreach my $year ( sort { $b <=> $a } keys %$years ) { - print $fh qq| \n|; + print $fh qq| \n|; foreach my $type_cat ( keys %{ $years->{$year} } ) { $type_cat_count->{ $type_cat } += $years->{$year}->{$type_cat}; } @@ -446,27 +446,46 @@ var years = |, encode_json($years), q|; var type_cat_count = |, encode_json($type_cat_count), q|; +function year_show(year) { + $('.y'+year).show(); + console.debug('show', year); + for(var type_cat in years[year]) { + if ( ( type_cat_count[ type_cat ] += years[year][type_cat] ) == years[year][type_cat]) { + $('a[name="'+type_cat+'"]').show(); + console.debug(type_cat, 'show'); + } + } +} + +function year_hide(year) { + $('.y'+year).hide(); + console.debug('hide', year); + for(var type_cat in years[year]) { + if ( ( type_cat_count[ type_cat ] -= years[year][type_cat] ) == 0 ) { + $('a[name="'+type_cat+'"]').hide(); + console.debug(type_cat, 'hide'); + } + } +} + function toggle_year(year, el) { if ( el.checked ) { - $('.y'+year).show(); - console.debug('show', year, el.checked); - for(var type_cat in years[year]) { - if ( ( type_cat_count[ type_cat ] += years[year][type_cat] ) == years[year][type_cat]) { - $('a[name="'+type_cat+'"]').show(); - console.debug(type_cat, 'show'); - } - } + year_show(year); } else { - $('.y'+year).hide(); - console.debug('hide', year, el.checked); - for(var type_cat in years[year]) { - if ( ( type_cat_count[ type_cat ] -= years[year][type_cat] ) == 0 ) { - $('a[name="'+type_cat+'"]').hide(); - console.debug(type_cat, 'hide'); - } - } + year_hide(year); } } + +$(document).ready( function() { + console.info('ready'); + + $('input[name=year_selection]').each( function(i, el) { + var year = el.value; + console.debug( 'on load', year, el.checked ); + if (! el.checked) year_hide(year); + }); + +}); |; -- 2.20.1