Skip to content

Instantly share code, notes, and snippets.

@Mausglov
Created May 15, 2015 14:19
Show Gist options
  • Save Mausglov/b296e919462548191369 to your computer and use it in GitHub Desktop.
Save Mausglov/b296e919462548191369 to your computer and use it in GitHub Desktop.
function prepare_query(event){
if (Ajax.activeRequestCount == 0) {
var a = Event.findElement(event, "a");
var attribute = a.readAttribute('data-attribute') || "";
var option = a.readAttribute('data-option') || "";
if(typeof window.layerFilters === 'undefined'){
window.layerFilters = query2array(window.location.href.split('?')[1]);
}
if(a.hasClassName('amshopby-attr-selected')){
var index = window.layerFilters[attribute].indexOf(option);
window.layerFilters[attribute].splice(index, 1);
if(window.layerFilters[attribute].length == 0){
var index = window.layerFilters.indexOf(attribute);
delete window.layerFilters[attribute];
}
}else{
if (typeof window.layerFilters[attribute] === "undefined"){
window.layerFilters[attribute] = [];
}
window.layerFilters[attribute].push(option);
}
var query = array2query(window.layerFilters);
a.toggleClassName('amshopby-attr-selected');
a.toggleClassName('amshopby-attr');
check_count(query, event);
}
Event.stop(event);
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment