I have a block of code, no complicated stuff is going on in it, and it is based on three different numbers ( viewport widths in my case ) :
if(viewport_width > 1224) {
$(".shop-items-navigation").initiate_shop({ containerID: "shop-items-wrapper", perPage: 8 }, function(pages){
current_page = pages.current;
total_pages = pages.count;
});
}
if(viewport_width < 1224 && viewport_width > 954) {
$(".shop-items-navigation").initiate_shop({ containerID: "shop-items-wrapper", perPage: 6 }, function(pages){
current_page = pages.current;
total_pages = pages.count;
});
}
if(viewport_width < 954 && viewport_width > 624) {
$(".shop-items-navigation").initiate_shop({ containerID: "shop-items-wrapper", perPage: 4 }, function(pages){
current_page = pages.current;
total_pages = pages.count;
});
}
if(viewport_width < 624) {
$(".shop-items-navigation").initiate_shop({ containerID: "shop-items-wrapper", perPage: 2 }, function(pages){
current_page = pages.current;
total_pages = pages.count;
});
}
So I though ( one method ) to place those three numbers in an array like this :
var widths = [1224, 954, 624];
And after apply an foreach function on it :
for(var i in widths ) {
...
}
But I cannot really figure how to wrap that up around those three numbers. The only thing that changes depending on the number in the array is another number :
{ ... perPage: 6 ... }
Which can vary from 8 down to 2. I would like a little help with this if possible, or maybe another way of writing it would be just fine.
You could make a list of objects:
Then: