Skip to content

Instantly share code, notes, and snippets.

@nilocortex
Created March 18, 2020 15:18
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 nilocortex/02c299da98133e0e2bd3b664293bf30d to your computer and use it in GitHub Desktop.
Save nilocortex/02c299da98133e0e2bd3b664293bf30d to your computer and use it in GitHub Desktop.
Blank Search Query Patch
initHeader: function (container) {
var self = this;
var $container = $(container);
var isAndroid = navigator.userAgent.indexOf("Android") > -1;
if (isAndroid) {
$('#searchInputMobile', container).focus(function () {
$('body').addClass("fixfixed");
});
$('#searchInputMobile', container).blur(function () {
$('body').removeClass("fixfixed");
});
}
$container.find(self._selectors.openSearch).click(
function (e) {
e.stopPropagation();
if ($container.find(self._selectors.searchContainer).hasClass(self._classes.searching)) {
self._closeSearch($container);
} else {
self._openSearch($container);
}
}
);
$container.find(self._selectors.mobileSearchOpen).click(function () { self._openMobileSearch($container); });
$container.find(self._selectors.mobileSearchExit).click(function () { self._closeMobileSearch($container); });
//Search submission
$container.find(self._selectors.searchNavSubmit).click(function (e) {
e.preventDefault();
var $container = $(this).closest('form');
//Get the base search text
var searchText = $(self._selectors.searchTextInput, $container).val();
var searchQuery = "q=" + (searchText === '' ? '' : encodeURIComponent(searchText));
//Gather the filters
var searchFilters = '';
var typeSelection = $(self._selectors.searchTypeSelect + ' option:selected', $container).val();
var vendorSelection = $(self._selectors.searchVendorSelect + ' option:selected', $container).val();
var productType = $(self._selectors.searchProdTypeSelect + ' option:selected', $container).val();
if (vendorSelection && vendorSelection !== '') {
searchFilters += " vendor:" + encodeURIComponent(vendorSelection);
}
if (productType && productType !== '') {
if (searchFilters != '') searchFilters += ' '
searchFilters += 'product_type:' + encodeURIComponent(productType);
}
if (typeSelection && typeSelection !== '') {
searchFilters += '&type=' + encodeURIComponent(typeSelection);
}
if (searchFilters != '') {
if (searchQuery != '') {
searchQuery += searchFilters;
} else {
searchQuery += '??' + searchFilters;
}
}
window.location.href = '/search?' + searchQuery;
});
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment