I have previously asked a question about how can I write a code block in a shorter way, I got my answer and I started adapting it to my circumstances. But I ran into a small problem, here is the code I’m running :
var default_cluster_options = {
limits : [ { min: 1224, items: 8 }, { min: 954, items: 6 }, { min: 624, items: 4 }, { min: 0, items: 2 } ]
};
var default_plugin_options = {
containerID : "",
first : false,
previous : false,
next : false,
last : false,
startPage : 1,
perPage : 1,
midRange : 6,
startRange : 1,
endRange : 1,
keyBrowse : false,
scrollBrowse: false,
pause : 0,
clickStop : true,
delay : 50,
direction : "auto",
animation : "fadeIn",
links : "title",
fallback : 1000,
minHeight : true,
callback : function(pages, items) {}
};
var Cluster = function(cluster_options, plugin_options) {
this.options = $.extend({}, default_cluster_options, cluster_options);
this.plugin_options = $.extend({}, default_plugin_options, plugin_options);
this.limits = this.options.limits;
this.inititate_shop();
};
Cluster.prototype.initiate_plugin = function(plugin_navigation, plugin_options) {
var options = $.extend({}, this.plugin_options, plugin_options);
return $(plugin_navigation).jPages(options);
};
Cluster.prototype.inititate_shop = function() {
for (var i = 0; this.viewport_width <= this.limits[i].min; i++) {
log(this.limits[i].min);
log(this.viewport_width);
this.initiate_plugin('.shop-items-navigation', {
containerID : "shop-items-wrapper",
perPage : this.limits[i].items,
midRange : 8,
animation : "fadeIn",
links : "blank",
keyBrowse : true,
callback : function(pages) {
log(pages.current);
}
});
}
};
var cluster = new Cluster();
Some of the code in there might not make sense because there are other code blocks, but I think that’s all the code related to my problem that may cause issues.
And my problem would be the for() loop inside the Cluster.prototype.inititate_shop property. I see no error in the console but when I tried to see if another loop works on the this.limits variable ( which is an array of 4 objects ) it did.
So that’s why I don’t see why the function won’t work or the for() loop would break and I’m asking here if anyone spots something I don’t ( I have a history of missing things ).
From the comments above – the problem is that your highest min value in the limits list is 1224 but your viewport width is 1366 so:
never evaluates to true and the code in the for loop is never executed.
EDIT 2
What about if you break out the statement that does the check: