Created
December 5, 2012 07:53
-
-
Save kev009/4213593 to your computer and use it in GitHub Desktop.
This file contains 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
@(page:Int, pageLength:Int, collectionLength:Int, route:Int => Call, bound:Int = 5) | |
@lowbound() = @{ | |
((page.toDouble / bound).floor * bound) toInt | |
} | |
@highbound() = @{ | |
if ((lowbound() + bound) * pageLength >= collectionLength) | |
collectionLength / pageLength + 1 | |
else | |
lowbound() + bound | |
} | |
<div class="pb_centered"> | |
<div class="pagination"> | |
<ul> | |
@if(page == 1){ | |
<li class="disabled"><a href="#">Previous</a></li> | |
} else { | |
<li><a href="@route(page-1)">Previous</a></li> | |
} | |
@if(page < bound) { | |
<li class="disabled"><a href="#">«</a></li> | |
} else { | |
@if(lowbound()-bound <= 0) { | |
<li><a href="@route(1)">«</a></li> | |
} else { | |
<li><a href="@route(lowbound()-bound)">«</a></li> | |
} | |
} | |
@for(i <- lowbound().max(1) until page) { | |
<li><a href="@route(i)">@i</a></li> | |
} | |
<li class="active"><a href="#">@page</a></li> | |
@for(i <- page+1 to highbound()) { | |
<li><a href="@route(i)">@i</a></li> | |
} | |
@if(highbound() * pageLength <= collectionLength && highbound() > page && page * pageLength != collectionLength) { | |
<li><a href="@route(highbound())">»</a></li> | |
} else { | |
<li class="disabled"><a href="#">»</a></li> | |
} | |
@if(page < highbound()) { | |
<li><a href="@route(page+1)">Next</a></li> | |
} else { | |
<li class="disabled"><a href="#">Next</a></li> | |
} | |
</ul> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instead of repeating
highboung()
andlowbound()
calls, why not use defining to only perform the call once?