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