Created
May 17, 2011 11:57
-
-
Save ChrisMcKee/976343 to your computer and use it in GitHub Desktop.
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 PagnationStr(totalPgs, currentPg) | |
| { | |
| var pageSet = 10, | |
| indexUrl = "//mydomain.com/page/", | |
| tmp = "<div class=\"pagination\"><ul>", | |
| maxpage = currentPg + 9, | |
| crtarget = currentPg, | |
| i = 0; | |
| if (currentPg < 2 && currentPg > 0) | |
| { | |
| indexUrl = indexUrl + "/"; | |
| } | |
| // Previous Link | |
| if (currentPg > 1) | |
| { | |
| tmp += ("<li class='previous'><a href='" + indexUrl + (currentPg - 1) + | |
| "' title=\"Move One Page Back\">« Previous</a></li>"); | |
| } | |
| else | |
| { | |
| tmp += ("<li class='previous-off'>« Previous</li>"); | |
| } | |
| // Pagination Loop | |
| if (maxpage > totalPgs && maxpage > 10){ crtarget = crtarget - 9;} | |
| for (i = crtarget; i < maxpage; i++) | |
| { | |
| var cssclass = (currentPg === i) ? " class=\"currentpage\" " : "", | |
| pno = i > 1 ? i.toString() : ""; | |
| if (i < 1){ i = 1; } | |
| if (i > totalPgs){ break; } | |
| tmp += ("<li><a href='" + indexUrl + pno + "'" + cssclass + ">" + i + "</a></li>"); | |
| if (pageSet < 1){ break; } | |
| pageSet--; | |
| } | |
| // NEXT LINK | |
| tmp += ((totalPgs > 1) && (currentPg + 1 < totalPgs)) ? | |
| ("<li class='next'><a href='" + indexUrl + (currentPg + 1) + | |
| "' title=\"Move One Page Forward\">Next »</a></li>") : | |
| ("<li class='next-off'>Next »</li>"); | |
| return tmp += ("</ul></div>"); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple Javascript pagination function, returns html string