Flickr style navigation rework
Finally found some time to add another post. After much debugging, my Web 2.0 - Flickr style navigation still didn't work correctly. So I decided to rework it completely.
Calculating the last page
I discovered that it already went wrong from the start: when calculating the last page. The formula here needs a math function 'Ceil()': Returns the smallest integer greater than or equal to the specified double-precision floating-point number. So I made this in LotusScript:
Function Ceil(num) As Integer
If Fraction(num)>0 Then
Ceil=Fix(num)+1
Else
Ceil=Fix(num)
End If
End Function
Getting one navigation entry
I moved the check if the entry rendered is the same as the current page to a separate function. This makes the code a lot shorter.
Function getPageNavLink(Byval strPath As String, pNum As Integer, pThis As Integer) As String
If pNum=pThis Then
getPageNavLink=|<span class="here">| & pNum & |</span>|
Else
getPageNavLink=|<a href="| & strPath & pNum & |">| & pNum & |</a>|
End If
End Function
Function getPageNav
I also separated the navigation in a separate function. All QueryString values are added back to the link. Values 'page' and 'count' are processed.
Function getPageNav(Byval strPath As String, Byval total As Long, Byval pCount As Integer) As String
On Error Goto catch
Dim tmp As New stringbuffer(100)
Dim v As Variant,vv As Variant, i As Integer
Dim vLast As Integer
Dim vPath As String, vPage As Integer, vCount As Integer, vAdjacents As Integer
' initial values
vPath=strPath & QUERYMARK & "open"
vPage=1
vCount=pCount
vAdjacents=3
' process the QueryString values
v=Split(Replace(doc.Query_String_Decoded(0), "&", "&"), "&")
For i=0 To Ubound(v)
vv=Split(v(i), "=")
If Ubound(vv)=1 Then
Select Case vv(0)
Case "page"
vPage=Cint(vv(1))
Case "count"
vCount=Cint(vv(1))
vPath=vPath & "&" & vv(0) & "=" & vv(1)
Case Else
vPath=vPath & "&" & vv(0) & "=" & vv(1)
End Select
End If
Next
vPath=vPath & "&page="
vLast=Ceil(total/vCount)
tmp.add |<div class="pages">|
If vLast>1 Then 'we need to show the navigation
'previous button
If vPage=1 Then
tmp.add |<span class="prev">« Prev</span>|
Else
tmp.add |<a href="| & vPath & vPage-1 & |" class="prev">« Prev</a>|
End If
'page numbers
If vLast<7+(vAdjacents*2) Then 'not enough pages to bother breaking it up
For i=1 To vLast
tmp.add getPageNavLink(vPath, i, vPage)
Next
Elseif vPage<1+(vAdjacents*2) Then 'close to beginning: hide later pages
For i=1 To 4+(vAdjacents*2)-1
tmp.add getPageNavLink(vPath, i, vPage)
Next
tmp.add |<span class="break">...</span>|
tmp.add getPageNavLink(vPath, vLast-1, 0)
tmp.add getPageNavLink(vPath, vLast, 0)
Elseif vLast-(vAdjacents*2)>vPage And vPage>(vAdjacents*2) Then ' smack in the middle
tmp.add getPageNavLink(vPath, 1, 0)
tmp.add getPageNavLink(vPath, 2, 0)
tmp.add |<span class="break">...</span>|
For i=vPage-vAdjacents To vPage+vAdjacents
tmp.add getPageNavLink(vPath, i, vPage)
Next
tmp.add |<span class="break">...</span>|
tmp.add getPageNavLink(vPath, vLast-1, 0)
tmp.add getPageNavLink(vPath, vLast, 0)
Else 'close to the end: hide pages in the beginning
tmp.add getPageNavLink(vPath, 1, 0)
tmp.add getPageNavLink(vPath, 2, 0)
tmp.add |<span class="break">...</span>|
For i=vLast-(2+(vAdjacents*2)) To vLast
tmp.add getPageNavLink(vPath, i, vPage)
Next
End If
' next button
If vPage=vLast Then
tmp.add |<span class="next">Next »</span>|
Else
tmp.add |<a href="| & vPath & (vPage+1) & |" class="next">Next »</a>|
End If
End If
tmp.add |<div class="count">(| & total & | pages)</div>|
tmp.add |</div>|
getPageNav=tmp.collapse(NEWLINE)
Goto finally
catch:
Error Err, Error & " in " & Getthreadinfo(1) & ", line " & Erl
Resume finally
finally:
End Function
Comments
11/15/2007 05:50:16 AM, Dr Domino
I've been reading your posts on Domino view pagination (View navigation in Web 2.0 style, A one fits all navigator in LotusScript and this one), but I'm not following how everything ties together.
Will a demo database be posted any time soon? This is a perfect solution for an application I'm currently working on.
I'm not sure where the functions shown above are placed and how they are triggered.
2007-11-20 11:27:59, Patrick Kwinten
http://www.smashingmagazine.com/2007/11/16/pagination-gallery-examples-and-good-practices/ here a link to some other examples of pagination...
20/11/2007 19:18:47, Michel Van der Meiren
Hello Patrick. Yes this is an excellent article. It even contains a link to a place where you can get custom styles for the pagination.
To add a comment, log in or register as new user. It's free and safe.