all values must be arrays
[MojoFacets.git] / templates / all_checkboxes.html.ep
1 <a id="all"  href="#">all</a>
2 <a id="toggle" href="#">toggle</a>
3 <a id="none" href="#">none</a>
4
5 <label for=filter_regex>regex:
6 <input type=text name=filter_regex>
7 <span class=hint>tab or click outside to apply</span>
8 <a id="included" href="#" style="display:none">included</a>
9 <a id="excluded" href="#" style="display:none">excluded</a>
10 </label>
11
12
13 <script type="text/javascript">
14
15 $(document).ready( function(){
16
17 $('label span.hint').position({
18         my: 'left bottom',
19         at: 'left top',
20         of: $('label input'),
21 });
22
23 $('a#all').click( function(){
24     $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', true);
25          $('#checked-count').text( $('#facet-count').text() );
26 });
27
28 $('a#none').click( function(){
29     $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', false);
30         $('#checked-count').text( 0 );
31 });
32
33 $('a#toggle').click( function(){
34         var count = 0;
35     $("input[type='checkbox']:not([disabled='disabled'])").each( function() {
36                 this.checked = ! this.checked;
37                 if ( this.checked ) count++;
38         });
39         $('#checked-count').text( count );
40 });
41
42 function update_checked_count(full) {
43         var count = $('#checked-count');
44         var nr = -1;
45         if ( full ) {
46                 nr = $("label input[type='checkbox']:checked").length;
47         } else {
48                 nr = parseInt( count.text() );
49                 if ( this.checked ) {
50                         nr++;
51                 } else {
52                         nr--;
53                 }
54         }
55         count.text( nr );
56 }
57
58 $("input[type='checkbox']").bind( 'click', update_checked_count );
59
60 $('a#included').click( function(){
61     $("label.included input[type='checkbox']:not([disabled='disabled'])").attr('checked', true);
62         update_checked_count(1);
63 });
64
65 $('a#excluded').click( function(){
66     $("label.excluded input[type='checkbox']:not([disabled='disabled'])").attr('checked', true);
67         update_checked_count(1);
68 });
69
70 $('input[name=filter_regex]').focusout( function(e) {
71         console.debug( this, e );
72         var r = new RegExp( this.value ,'i');
73         var included = 0;
74         var excluded = 0;
75     $("input[type='checkbox']:not([disabled='disabled'])").each( function(i,element){
76                 if ( r.test( this.value ) ) {
77                         $(this).parent().removeClass('excluded').addClass('included');
78                         included++;
79                 } else {
80                         $(this).parent().removeClass('included').addClass('excluded');
81                         excluded++;
82                 }
83         });
84
85         $('a#included').text(included).show();
86         $('a#excluded').text(excluded).show();
87 });
88
89 update_checked_count(1);
90
91 }); // document.ready
92
93 </script>
94