Created
July 1, 2013 13:04
-
-
Save jmcd/5900561 to your computer and use it in GitHub Desktop.
Reduce the number of links in bootstrap pagination
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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