update checked-count via javascript
[MojoFacets.git] / templates / all_checkboxes.html.ep
1 <a id="all"  href="#">all</a>
2 <a id="none" href="#">none</a>
3
4 <label for=filter_regex>regex:
5 <input type=text name=filter_regex>
6 <span class=hint>tab or click outside to apply</span>
7 <a id="included" href="#">included</a>
8 <a id="excluded" href="#">excluded</a>
9 </label>
10
11
12 <script type="text/javascript">
13
14 $(document).ready( function(){
15
16 $('label span.hint').position({
17         my: 'left bottom',
18         at: 'left top',
19         of: $('label input'),
20 });
21
22 $('a#all').click( function(){
23     $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', true);
24          $('#checked-count').text( $('#facet-count').text() );
25 });
26
27 $('a#none').click( function(){
28     $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', false);
29         $('#checked-count').text( '-' );
30 });
31
32 $('a#included').click( function(){
33         var count = 0;
34     $("label.included input[type='checkbox']:not([disabled='disabled'])").each( function() {
35                 this.checked = true;
36                 count++;
37         });
38         $('#checked-count').text( count );
39 }).hide();
40
41 $('a#excluded').click( function(){
42         var count = 0;
43     $("label.excluded input[type='checkbox']:not([disabled='disabled'])").each( function() {
44                 this.checked = true;
45                 count++;
46         });
47         $('#checked-count').text( count );
48 }).hide();
49
50 $('input[name=filter_regex]').change( function(e) {
51         console.debug( this, e );
52         var r = new RegExp( this.value ,'i');
53         var included = 0;
54         var excluded = 0;
55     $("input[type='checkbox']:not([disabled='disabled'])").each( function(i,element){
56                 if ( r.test( this.value ) ) {
57                         $(this).parent().removeClass('excluded').addClass('included');
58                         included++;
59                 } else {
60                         $(this).parent().removeClass('included').addClass('excluded');
61                         excluded++;
62                 }
63         });
64
65         $('a#included').text('+' + included).show();
66         $('a#excluded').text('-' + excluded).show();
67 });
68
69 }); // document.ready
70
71 </script>
72