Created
January 30, 2014 23:02
-
-
Save CezaryDanielNowak/8721979 to your computer and use it in GitHub Desktop.
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
// I'ts ugly but works | |
$('.pagination').each(function(){ | |
var allLi = $(this).find('li'); | |
if(allLi.length > 20) { | |
var activeId = allLi.filter('.active').index(); | |
allLi.eq(0) | |
.add(allLi.eq(1)) | |
.add(allLi.eq(2)) | |
.add(allLi.eq(3)) | |
.add(allLi.eq(4)) | |
.add(allLi.eq(-1)) | |
.add(allLi.eq(-2)) | |
.add(allLi.eq(-3)) | |
.add(allLi.eq(-4)) | |
.add(allLi.eq(activeId)) | |
.add(allLi.eq(activeId-1)) | |
.add(allLi.eq(activeId-2)) | |
.add(allLi.eq(activeId-3)) | |
.add(allLi.eq(activeId+1)) | |
.add(allLi.eq(activeId+2)) | |
.add(allLi.eq(activeId+3)) | |
.addClass('allow'); | |
var replacedWithDots = false; | |
allLi.each(function() { | |
if( $(this).hasClass('allow') ) { | |
replacedWithDots = false; | |
} else if(!replacedWithDots) { | |
replacedWithDots = true; | |
$(this).html('<a>...</a>'); | |
} else { | |
$(this).remove(); | |
} | |
}) | |
} | |
}); |
Author
CezaryDanielNowak
commented
Jan 30, 2014
i'm a begiiner at javascript so it would be really helpful if u explained how does this hide the pages. and how does pagination call on those hidden pages?
I wrote this 6 years ago, and code isn't good :D
But in general:
- take 4 list element from the beginning
- take 4 list element from the end
- take 3 elements around active one
- replace all other elements with
...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment