facet code eval with $value, $count and $checked
[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 var toggle_checkbox = function() {
61                 this.checked = ! this.checked;
62 };
63
64 $('a#included').click( function(){
65     $("label.included input[type='checkbox']:not([disabled='disabled'])").each( toggle_checkbox );
66         update_checked_count(1);
67 });
68
69 $('a#excluded').click( function(){
70     $("label.excluded input[type='checkbox']:not([disabled='disabled'])").each( toggle_checkbox );
71         update_checked_count(1);
72 });
73
74 $('input[name=filter_regex]').focusout( function(e) {
75         console.debug( this, e );
76         var r = new RegExp( this.value ,'i');
77         var included = 0;
78         var excluded = 0;
79     $("input[type='checkbox']:not([disabled='disabled'])").each( function(i,element){
80                 if ( r.test( this.value ) ) {
81                         $(this).parent().removeClass('excluded').addClass('included');
82                         included++;
83                 } else {
84                         $(this).parent().removeClass('included').addClass('excluded');
85                         excluded++;
86                 }
87         });
88
89         $('a#included').text(included).show();
90         $('a#excluded').text(excluded).show();
91 });
92
93 update_checked_count(1);
94
95 }); // document.ready
96
97 </script>
98