+<a id="all" href="#">all</a>
+<a id="none" href="#">none</a>
+
+<label for=filter_regex>regex:
+<input type=text name=filter_regex>
+<span class=hint>tab or click outside to apply</span>
+<a id="included" href="#">included</a>
+<a id="excluded" href="#">excluded</a>
+</label>
+
+
<script type="text/javascript">
-function all_checkboxes(checked) {
- $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', checked);
+
+$(document).ready( function(){
+
+$('label span.hint').position({
+ my: 'left bottom',
+ at: 'left top',
+ of: $('label input'),
+});
+
+$('a#all').click( function(){
+ $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', true);
+ $('#checked-count').text( $('#facet-count').text() );
+});
+
+$('a#none').click( function(){
+ $("input[type='checkbox']:not([disabled='disabled'])").attr('checked', false);
+ $('#checked-count').text( 0 );
+});
+
+function update_checked_count(full) {
+ var count = $('#checked-count');
+ var nr = -1;
+ if ( full ) {
+ nr = $("label input[type='checkbox']:checked").length;
+ } else {
+ nr = parseInt( count.text() );
+ if ( this.checked ) {
+ nr++;
+ } else {
+ nr--;
+ }
+ }
+ count.text( nr );
}
-</script>
-<a href="#" onClick="all_checkboxes(true); return false;">all</a>
-<a href="#" onClick="all_checkboxes(false); return false;">none</a>
+$("input[type='checkbox']").bind( 'click', update_checked_count );
+
+$('a#included').click( function(){
+ $("label.included input[type='checkbox']:not([disabled='disabled'])").attr('checked', true);
+ update_checked_count(1);
+}).hide();
+
+$('a#excluded').click( function(){
+ $("label.excluded input[type='checkbox']:not([disabled='disabled'])").attr('checked', true);
+ update_checked_count(1);
+}).hide();
+
+$('input[name=filter_regex]').change( function(e) {
+ console.debug( this, e );
+ var r = new RegExp( this.value ,'i');
+ var included = 0;
+ var excluded = 0;
+ $("input[type='checkbox']:not([disabled='disabled'])").each( function(i,element){
+ if ( r.test( this.value ) ) {
+ $(this).parent().removeClass('excluded').addClass('included');
+ included++;
+ } else {
+ $(this).parent().removeClass('included').addClass('excluded');
+ excluded++;
+ }
+ });
+
+ $('a#included').text(included).show();
+ $('a#excluded').text(excluded).show();
+});
+
+update_checked_count(1);
+
+}); // document.ready
+
+</script>