Skip to content

Instantly share code, notes, and snippets.

@jronallo
Created November 3, 2012 00:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jronallo/4005269 to your computer and use it in GitHub Desktop.
Save jronallo/4005269 to your computer and use it in GitHub Desktop.
jQuery snippet for experimental quicksearch filtering on http://www.lib.ncsu.edu/findingaids
/* Copyright 2012 North Carolina State University
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
This snippet depends on jquery.quicksearch.js and on the exact markup structure found on a collection guide page at http://www.lib.ncsu.edu/findingaids.
*/
$('#container_filtering').show();
$('#turn_on_container_filtering').click(function(){
$('#turn_on_container_filtering').hide();
$('#container_filtering_body').show();
$('#container_filter_clear').click(function(){
$('#quicksearch').attr('value','');
$('#dsc').removeHighlight();
$('.hideshort').removeClass('hideshort');
$('.hidepart').removeClass('hidepart');
$('#nofilterresults').hide();
return false;
});
$('input#quicksearch').quicksearch(searchquick, {
'delay': 300,
'loader': '.loader',
'noResults': '#nofilterresults',
'onBefore': function(){
$('#dsc').removeHighlight();
if ($('input#quicksearch').val()) {
$('#dsc').highlight( $('input#quicksearch').val() );
}
},
'hide': function(){
$(this).addClass('hideshort');
//console.log($(this).parent().children(".hideshort").length);
if ($(this).parent().children("div.line").length == $(this).parent().children("div.hideshort").length ){
//console.log($(this).parent().children().not('.container-level-info'));
if ( $(this).parent().find('.highlight').not('.container-level-info').length == 0 ) {
$(this).parent().children().not('.container-level-info').not('.nomatching').not('.line_did').addClass('hidepart');
}
if ($(this).parent().find('.highlight').length == 0 ) {
$(this).parent().find('.c01-not-head').addClass('hidepart');
}
if ( $(this).parent().find('.nomatching').length == 0 ) {
$(this).parent().append('<div class="nomatching">No matching content.</div>');
}
}
},
'show': function(){
$(this).parent().find('.nomatching').remove();
$(this).addClass('filterable');
$(this).parent().removeClass('hideshort');
$(this).parent().find('.c01-not-head').removeClass('hidepart');
$(this).removeClass('hideshort');
$(this).removeClass('hidepart');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment