Skip to content

Instantly share code, notes, and snippets.

@dinhnguyen
Created May 13, 2015 06:50
Show Gist options
  • Save dinhnguyen/a7c7e04a46301f00a03c to your computer and use it in GitHub Desktop.
Save dinhnguyen/a7c7e04a46301f00a03c to your computer and use it in GitHub Desktop.
tét
<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