function checkedFilters(){
var opts = [];
$checkboxes.each(function(){
if(this.checked){
opts.push(this.id);
}
});
return opts;
}
var $checkboxes = $("input:checkbox");
$checkboxes.on("change", function(){
var opts = checkedFilters();
var $orderBy = $("#by-price").val();
fetchData(opts, $orderBy);
});
$checkboxes.trigger("change");
$("#by-price").on("change", function() {
var opts = checkedFilters();
var $orderBy = $("#by-price").val();
fetchData(opts, $orderBy);
});
function fetchData (opts, $orderBy){
$.ajax({
type: 'post',
url: 'submit.php',
dataType : 'json',
cache: false,
success: function(records){
globalContent(jQuery.parseJSON(formatData(records)), opts, $orderBy);
}
});
}
Array.prototype.contains = function(obj) {
var i = this.length;
while (i--) {
if (this[i] == obj) {
return true;
}
}
return false;
};
function globalContent (result, opts, $orderBy) {
var orderBy = $orderBy;
var results = [];
var filterOpt = opts;
for (var x = 0; x < result.length; x++) {
for (var i = 0; i < filterOpt.length; i++) {
if (result[x].colors[i] !== null) {
if (result[x].colors.contains(filterOpt[i]) || filterOpt[i] === result[x].brand || filterOpt[i] === result[x].format) {
if (results.contains(result[x]) === false) {
results.push(result[x]);
}
}
}
}
}
if (results.length == 0) {
if (orderBy == 1) {
result.sort(function (a, b) {
return parseInt(a.price, 10) - parseInt(b.price, 10);
});
$('#products-section').html(makeContent(result));
} else {
result.sort(function (a, b) {
return parseInt(b.price, 10) - parseInt(a.price, 10);
});
$('#products-section').html(makeContent(result));
}
}
else {
if (orderBy == 1) {
results.sort(function (a, b) {
return parseInt(a.price, 10) - parseInt(b.price, 10);
});
$('#products-section').html(makeContent(results));
} else {
results.sort(function (a, b) {
return parseInt(b.price, 10) - parseInt(a.price, 10);
});
$('#products-section').html(makeContent(results));
}
}
$(".paginate").trigger("custom");
}
$(".paginate").on("custom", function () {
$(".paginate").customPagination({
itemsForPage : ".product",
itemsPerPage : 2
});
$(".paginate ul:not(:first)").remove();
});
"You're gettin' the fuck...
I know you're seven !"
"But you'll be a seven year old
walkin' the dog no house motherfucker !"