我使用JavaScript插件在一组网站页面上启用过滤功能。目前没有任何内容可以过滤页面,因此无需显示所有过滤选项。我想要做的是设置当前过滤器jquery以使过滤器默认折叠,而不是像现在那样扩展。下面是我用于过滤器的jquery。
var searchHashName = "#loadSearch-";
var searchTypeKey = "searchType";
var dayIDKey = "dayID";
var currentSearchType = "";
var dayID = "";
var useNavDropdown = true;
var dayTimeSearch = false;
$(function(){
windowBinder();
$('#searchContainer').addClass("ui-tabs ui-widget")
.find("ul").addClass("ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all")
.find("li").addClass("ui-state-default ui-corner-top").hover(
function(){$(this).addClass("ui-state-hover")},
function(){$(this).removeClass("ui-state-hover")}
);
$('#searchContainer ul').css('visibility', 'visible');
$('#searchContainer ul a').click(function(){
var $li = $(this).closest('li');
currentSearchType = getURLParam(this.href, searchTypeKey);
if(currentSearchType === "attendee"){
ConnectAjax.checkLogin(function(result){
if(result == false){
var url = window.location.pathname;
$('#templateHeader').load(url + ' #templateHeader');
$li.hide().siblings().filter(':visible').first().find('a').click();
loginDialog();
}
else{
$('#templateContent .selectedFilters').show();
submitSearch({tabClick:true});
}
});
}
else{
//show hide filters
if(currentSearchType === "all") {$('#templateContent .selectedFilters').hide();}
else $('#templateContent .selectedFilters').show();
submitSearch({tabClick:true});
}
return false;
});
$('#searchContainer ul a').bind('click.setCurrent', function(){
$('#searchContainer li').removeClass('ui-state-active ui-tabs-active');
$(this).closest('li').addClass('ui-state-active ui-tabs-active ');
currentSearchType = getURLParam(this.href, searchTypeKey);
$('#searchFilters div.searchFilter').hide().filter("#"+currentSearchType+"Search").show();
$("#searchFilters #"+currentSearchType+"Search .boxed-filter").trigger('filter-onload');
showHideSortOptions();
});
$('#searchContainer li.ui-tabs-active a').triggerHandler('click.setCurrent');
$('#searchForm .phraseDiv').keywordSearch({ onClear: submitSearch }).css('visibility', 'visible');
if($('#searchForm .searchPhrase').data('blank') !== true){
populateHiddenPhrase();
highlightSearchString();
}
$('#searchFilters input[name=profileValueBaseKey]').attr('name','p').val(''); //prevent base key from showing in the address bar
loadCurrentHash();
$("#searchResult")
.on("click", "a.openInPopup", function(){
showDetail(this.href, this.title);
return false;
})
.on('click', '.download', downloadDocs)
.on("click", ".mapItem", mapItemClick);
$('#searchForm').submit(function(){
submitSearch();
return false;
});
if(useNavDropdown){
var siteMenuTxt = $('#siteMenuTxt').html();
var navDropdown = $('<div id="navDropdown"></div>').html('<div class="downLink ui-state-default ui-corner-bl">'+ siteMenuTxt +'<span class="ui-icon ui-icon-triangle-1-s"></span></div>').prependTo('nav').append($("#mainNav"))
.hover(
function(){
$('#navDropdown .downLink').addClass('ui-state-hover').removeClass('ui-corner-bl');
$('#mainNav').addClass('ui-corner-bl').show();
},
function(){
$('#navDropdown .downLink').removeClass('ui-state-hover').addClass('ui-corner-bl');
$('#mainNav').hide()
}
);
$('#mainNav').css("position", "absolute").addClass('ui-corner-bl');
}
else{
$("#mainNav").show();
}
});