/*
* Pager - jQuery plugin to format serch result pagers
*/
;(function($) {
function assertHasClass(element, c, errormsg) {
if(!$(element).hasClass(c)) {throw errormsg;}
}
$.extend($.fn, {
showPager: function(callback, size) {
var PAGER_SIZE = parseInt(size) || 14;
$(this).each(function() {
assertHasClass(this, 'pager', "element must be a pager");
var pages = jQuery('.page:not(.nextPage, .previousPage)', this);
if(pages.length <= PAGER_SIZE) {
pages.show();
} else {
var current = pages.index(pages.filter('.currentPage'));
if(current<=PAGER_SIZE-4) {
pages.each(function(i) {
var page = jQuery(this);
if(i === PAGER_SIZE - 2){
page.replaceWith('...');
}else if(i pages.length-(PAGER_SIZE-2)) {
pages.each(function(i) {
var page = jQuery(this);
if(i === 0){
page.show();
}else if(i === 1){
page.replaceWith('...');
}else if(i > pages.length - (PAGER_SIZE-1)) {
page.show();
}
});
} else {
pages.each(function(i) {
var page = jQuery(this);
if(i === 0){
page.show();
}else if(i === 1){
page.replaceWith('...');
}else if(i === pages.length -1) {
page.show();
}else if(i === pages.length - 2){
page.replaceWith('...');
}else if(i > (current - Math.floor(PAGER_SIZE/2)+2) && (i < (current + Math.floor(PAGER_SIZE/2) - 1))) {
page.show();
}
});
}
}
if(typeof callback == 'function') {
jQuery('a.page', this).click(function() {
callback(this.href.slice(this.href.lastIndexOf('#')+1, this.href.length));
});
}
return this;
});
}
});
})(jQuery);
<%@ attribute name="current" required="true" rtexprvalue="true" type="java.lang.Integer" %>
<%@ attribute name="pages" required="true" rtexprvalue="true" type="java.util.Collection" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>