-
-
Save dinhnguyen/a7c7e04a46301f00a03c to your computer and use it in GitHub Desktop.
tét
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
Shopify.queryParams = {}; | |
if (location.search.length) { | |
for (var aKeyValue, i = 0, aCouples = location.search.substr(1).split('&'); i < aCouples.length; i++) { | |
aKeyValue = aCouples[i].split('='); | |
if (aKeyValue.length > 1) { | |
Shopify.queryParams[decodeURIComponent(aKeyValue[0])] = decodeURIComponent(aKeyValue[1]); | |
} | |
} | |
} | |
var collFilters = jQuery('.coll-filter'); | |
collFilters.change(function() { | |
var newTags = []; | |
var newURL = ''; | |
delete Shopify.queryParams.page; | |
collFilters.each(function() { | |
if (jQuery(this).val()) { | |
newTags.push(jQuery(this).val()); | |
} | |
}); | |
{% if collection.alias %} | |
newURL = '/collections/' + '{{ collection.alias }}'; | |
if (newTags.length) { | |
newURL += '/' + newTags.join('+'); | |
} | |
var search = jQuery.param(Shopify.queryParams); | |
if (search.length) { | |
newURL += '?' + search; | |
} | |
location.href = newURL; | |
{% else %} | |
if (newTags.length) { | |
Shopify.queryParams.constraint = newTags.join('+'); | |
} | |
else { | |
delete Shopify.queryParams.constraint; | |
} | |
location.search = jQuery.param(Shopify.queryParams).replace(/\+/g, '%20'); | |
{% endif %} | |
}); | |
jQuery('.sort-by') | |
.val('{{ collection.sort_by | default: collection.default_sort_by }}') | |
.bind('change', function() { | |
Shopify.queryParams.sort_by = jQuery(this).val(); | |
location.search = jQuery.param(Shopify.queryParams).replace(/\+/g, '%20'); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment