speedup selected facet count
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 21 May 2010 18:29:21 +0000 (20:29 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 21 May 2010 18:29:21 +0000 (20:29 +0200)
templates/all_checkboxes.html.ep
templates/data/facet.html.ep

index 11cfbe9..7c2b16f 100644 (file)
@@ -26,25 +26,35 @@ $('a#all').click( function(){
 
 $('a#none').click( function(){
     $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', false);
-       $('#checked-count').text( '-' );
+       $('#checked-count').text( 0 );
 });
 
+function update_checked_count(full) {
+       var count = $('#checked-count');
+       var nr = -1;
+       if ( full ) {
+               nr = $("label input[type='checkbox']:checked").length;
+       } else {
+               nr = parseInt( count.text() );
+               if ( this.checked ) {
+                       nr++;
+               } else {
+                       nr--;
+               }
+       }
+       count.text( nr );
+}
+
+$("input[type='checkbox']").bind( 'click', update_checked_count );
+
 $('a#included').click( function(){
-       var count = 0;
-    $("label.included input[type='checkbox']:not([disabled='disabled'])").each( function() {
-               this.checked = true;
-               count++;
-       });
-       $('#checked-count').text( count );
+    $("label.included input[type='checkbox']:not([disabled='disabled'])").attr('checked', true);
+       update_checked_count(1);
 }).hide();
 
 $('a#excluded').click( function(){
-       var count = 0;
-    $("label.excluded input[type='checkbox']:not([disabled='disabled'])").each( function() {
-               this.checked = true;
-               count++;
-       });
-       $('#checked-count').text( count );
+    $("label.excluded input[type='checkbox']:not([disabled='disabled'])").attr('checked', false);
+       update_checked_count(1);
 }).hide();
 
 $('input[name=filter_regex]').change( function(e) {
@@ -62,10 +72,12 @@ $('input[name=filter_regex]').change( function(e) {
                }
        });
 
-       $('a#included').text('+' + included).show();
-       $('a#excluded').text('-' + excluded).show();
+       $('a#included').text(included).show();
+       $('a#excluded').text(excluded).show();
 });
 
+update_checked_count(1);
+
 }); // document.ready
 
 </script>
index 9158d98..6ff7097 100644 (file)
@@ -13,7 +13,7 @@
 <a id=checked-count href="<%= url_for->query( name => $name, all => 0 ) %>" title="reload selected facets"><%= $checked_count %></a>
 %  }
 % } else {
-<span id=checked-count>-</span>
+<span id=checked-count>0</span>
 % }
 <span id=facet-count title="total"><%= $facet_count %></span>
 </span>