edit table cells in place
[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( 0 );
30 });
31
32 function update_checked_count(full) {
33         var count = $('#checked-count');
34         var nr = -1;
35         if ( full ) {
36                 nr = $("label input[type='checkbox']:checked").length;
37         } else {
38                 nr = parseInt( count.text() );
39                 if ( this.checked ) {
40                         nr++;
41                 } else {
42                         nr--;
43                 }
44         }
45         count.text( nr );
46 }
47
48 $("input[type='checkbox']").bind( 'click', update_checked_count );
49
50 $('a#included').click( function(){
51     $("label.included input[type='checkbox']:not([disabled='disabled'])").attr('checked', true);
52         update_checked_count(1);
53 }).hide();
54
55 $('a#excluded').click( function(){
56     $("label.excluded input[type='checkbox']:not([disabled='disabled'])").attr('checked', true);
57         update_checked_count(1);
58 }).hide();
59
60 $('input[name=filter_regex]').change( function(e) {
61         console.debug( this, e );
62         var r = new RegExp( this.value ,'i');
63         var included = 0;
64         var excluded = 0;
65     $("input[type='checkbox']:not([disabled='disabled'])").each( function(i,element){
66                 if ( r.test( this.value ) ) {
67                         $(this).parent().removeClass('excluded').addClass('included');
68                         included++;
69                 } else {
70                         $(this).parent().removeClass('included').addClass('excluded');
71                         excluded++;
72                 }
73         });
74
75         $('a#included').text(included).show();
76         $('a#excluded').text(excluded).show();
77 });
78
79 update_checked_count(1);
80
81 }); // document.ready
82
83 </script>
84