forked from shpatinag/Shopify-Collection-Filter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjQuery.filters.js
37 lines (31 loc) · 1.36 KB
/
jQuery.filters.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
$( document ).ready(function() {
jQuery('.advanced-filter').each(function() {
var el = jQuery(this)
,group = el.data('group');
if ( el.hasClass('active-filter') ) { //Remove class hidden
el.parents('.sb-filter').find('a.clear-filter').removeClass('hidden');
}
});
jQuery('.advanced-filter').on('click', function(e) {
var el = $(this)
,group = el.data('group')
,url = el.find('a').attr('href')
// Continue as normal if we're clicking on the active link
if ( el.hasClass('active-filter') ) {
return;
}
var _logic = jQuery(".filters-sidebar").data('logic');
if( _logic ){
// Get active group link (unidentified if there isn't one)
activeTag = $('.active-filter[data-group="'+ group +'"]');
// If a tag from this group is already selected, remove it from the new tag's URL and continue
if ( activeTag && activeTag.data('group') === group ) {
e.preventDefault();
activeHandle = activeTag.data('handle') + '+';
// Create new URL without the currently active handle
url = url.replace(activeHandle, '');
window.location = url;
}
}
});
});