added filters javascript shared all over the place
authorDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 3 Jan 2017 09:09:53 +0000 (10:09 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 3 Jan 2017 09:10:15 +0000 (10:10 +0100)
html/filters.js [new file with mode: 0644]

diff --git a/html/filters.js b/html/filters.js
new file mode 100644 (file)
index 0000000..f5cdbbf
--- /dev/null
@@ -0,0 +1,81 @@
+
+function toc_count_update(type_cat) {
+       var selector = '#toc-count-'+type_cat.replace(/\./g,'-');
+       var e = $(selector);
+       if ( ! e )  {
+               console.error(selector, 'not found');
+               return;
+       }
+       var old_val = e.text();
+       var new_val = type_cat_count[type_cat];
+
+       if ( old_val != new_val ) {
+               e.text(new_val);
+               console.debug( selector, 'old', old_val, 'new', new_val);
+
+               var cat = type_cat.split('-')[0];
+               var val = type_cat_count['_toc_count'][cat] += new_val - old_val;
+               console.log(cat, val);
+               $('#toc-count-'+cat).text(val);
+
+       }
+}
+
+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');
+               }
+               toc_count_update(type_cat);
+       }
+}
+
+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');
+               }
+               toc_count_update(type_cat);
+       }
+}
+
+function toggle_year(year, el) {
+       if ( el.checked ) {
+               year_show(year);
+       } else {
+               year_hide(year);
+       }
+}
+
+function all_years( turn_on ) {
+       $('input[name=year_selection]').each( function(i,el) {
+               if ( turn_on ) {
+                       if ( ! el.checked ) {
+                               el.checked = true;
+                               year_show( el.value );
+                       }
+               } else {
+                       if ( el.checked ) {
+                               el.checked = false;
+                               year_hide( el.value );
+                       }
+               }
+       } );
+}
+
+$(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);
+       });
+
+});