I've got a fairly simple pagination algorithm here but it's not working the way I'd like it to.
Currently it's displaying like this
1 2 3 ... 33 34 35 [36] 37 38 ... 47 48 49 50
When it should be displaying like this
1 2 3 ... 33 34 35 [36] 37 38 39 ... 48 49 50
Here's my code, I wrote it very quickly. It also seems to continuously run (The loop doesn't stop) but I've no idea why.
$(function(){
var pages = 50; //Total number of pages
var current = 36; //The current page we are on
var before = 3; //Number of links to display before current
var after = 3; //Same as above but after
var start = (current - before); //The number of the first link
var end = (current + after); //Number of the end link
for(var i = 1; i <= pages; i++){
if(i == (before + 1)){
i = start;
document.write('...');
}
else if(i == (current + after)){
i = (pages - after);
document.write('...');
}
if(i == current){
document.write(' ['+i+'] ');
}
else{
document.write(' '+i+' ');
}
}
});