Skip to content

Instantly share code, notes, and snippets.

@jsakhil
Last active June 21, 2019 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jsakhil/fb0419ea5232bfc748977137e2d03f0d to your computer and use it in GitHub Desktop.
Save jsakhil/fb0419ea5232bfc748977137e2d03f0d to your computer and use it in GitHub Desktop.
Full Width Pagination - An Auto expanding pagination with screen width - PyroCMS - ©Vishnu Soman US
var li_length = jQuery('ul.pagination li').length;
if(li_length == 13){
var li_item = jQuery('ul.pagination li:nth-child(9) a').attr('href');
var to_num_8 = jQuery('ul.pagination li:nth-child(11)').text();
$('<li><a href="'+li_item.replace("8", "9")+'">9</a></li>').insertAfter("ul.pagination li:nth-child(9)");
$('<li class="tenth"><a href="'+li_item.replace("8", "10")+'">10</a></li>').insertAfter("ul.pagination li:nth-child(10)");
var space = $('ul.pagination').parent().width() - $('ul.pagination').width();
var ext_count = space/42-1;
console.log('ext_count: '+ext_count);
var miss_pages = to_num_8 - 11;
console.log('miss_pages: '+miss_pages);
var count_lp = 0;
if(miss_pages >= ext_count){
for (var i = 0; i < ext_count; i++) {
count_lp = 11 + i;
$('<li class="tenth"><a href="'+li_item.replace("8", count_lp)+'">'+count_lp+'</a></li>').insertAfter("ul.pagination li:nth-child("+count_lp+")");
}
}else{
$("ul.pagination span:contains('...')").parent().remove();
for (var i = 0; i < miss_pages; i++) {
count_lp = 11 + i;
$('<li class="tenth"><a href="'+li_item.replace("8", count_lp)+'">'+count_lp+'</a></li>').insertAfter("ul.pagination li:nth-child("+count_lp+")");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment