Unfortunately there is no URL where you can see the code working. I hope you all can figure out what the code does simply by looking at it.
var FilteredNav = {
wrapper: $(".dept-filters")
, init: function() {
FilteredNav.changeUrl();
FilteredNav.createUrl();
}
, createUrl: function() {
var url = null
, urlItems = null;
$.each(FilteredNav.wrapper, function() {
// clean it all up before creating the url
urlItems = [];
var self = $(this)
, checkedInput = self.find('input[type="checkbox"]:checked')
, submitButton = self.find('.refinar-btn');
// select only the relevant items
$.each(checkedInput, function(i, item) {
urlItems.push($(item).attr("rel"));
});
if (checkedInput.length) {
// create the url
url = document.location.protocol
+ "//"
+ document.location.host
+ "/"
+ self.attr("data-dept")
+ "/?"
+ urlItems.join("&");
// add new url as href of 'refine' button
submitButton.removeClass("hide").attr("href", url);
} else {
submitButton.addClass("hide");
}
});
}
, changeUrl: function() {
FilteredNav.wrapper.find('input[type="checkbox"]').bind("change", FilteredNav.createUrl);
}
};
// uncomment this line when testing on the console
// FilteredNav.init();
// comment this line when testing on the console
$(document).ready(function() {
FilteredNav.init();
});