Skip to content

Instantly share code, notes, and snippets.

@jmcd
Created July 1, 2013 13:04
Show Gist options
  • Save jmcd/5900561 to your computer and use it in GitHub Desktop.
Save jmcd/5900561 to your computer and use it in GitHub Desktop.
Reduce the number of links in bootstrap pagination
$(function () {
var radius = 4;
var replacementForHiddenContent = "<li><a>...</a></li>";
var $pages = $(".js-page");
var $activePage = $pages.filter(".active");
var indexOfActive = $pages.index($activePage);
var indexOfFirst = Math.max(indexOfActive - radius, 0);
var indexOfLast = indexOfFirst + 2 * radius + 1;
$pages.each(function(i, value) {
if (i < indexOfFirst || i > indexOfLast) {
$(value).hide();
}
});
if (indexOfFirst > 0) {
$pages.first().before(replacementForHiddenContent);
}
if (indexOfLast < $pages.length - 1) {
$pages.last().after(replacementForHiddenContent);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment