1 $.fn.alphaPager = function(fn,type) {
4 if ( fn == undefined ) {
5 fn = function(a){ return _clean( $.fn.text.apply( a.childNodes ) ); };
6 } else if ( fn.constructor == Number ) {
8 fn = function(a){ return _clean( $.fn.text.apply( [a.childNodes[ n ]] ) ); };
14 return a.substr(0,1).toUpperCase();
16 return /^([a-z0-9]+)/.exec(a)[1];
21 return this.pager( fn );
25 $.fn.pager = function(step) {
33 return this.each(function(){
34 var type = types[this.nodeName];
35 var pagedUI = type == "tr" ? $("tbody",this) : $(this);
36 var rows = $(type, pagedUI);
38 var names = [], num = [];
40 if ( !step || step.constructor != Function ) {
43 if (rows.length > step)
44 for ( var i = 0; i <= rows.length; i += step ) {
45 names.push( names.length + 1 );
46 num.push( [ i, step ] );
54 var pre = num.length ? num[ num.length - 1 ][0] + num[ num.length - 1 ][1] : 0;
56 num.push( [ pre, 0 ] );
60 num[ num.length - 1 ][1]++;
64 if ( names.length > 1 ) {
65 var pager = $(this).prev("ul.nav-page").empty();
68 pager = $("<ul class='nav-page'></ul>");
70 for ( var i = 0; i < names.length; i++ )
71 $("<a href=''></a>").attr({
72 rel: i, innerHTML: names[i]
74 return handleCrop( this.rel );
75 }).wrap("<li></li>").parent().appendTo(pager);
77 pager.insertBefore( this );
79 var prev = $("<a href=''>« Prev</a>").click(function(){
80 return handleCrop( --curPage );
81 }).wrap("<li class='prev'></li>").parent().prependTo(pager);
83 var next = $("<a href=''>Next »</a>").click(function(){
84 return handleCrop( ++curPage );
85 }).wrap("<li class='next'></li>").parent().appendTo(pager);
90 function handleCrop( page ) {
92 var s = num[ curPage ][0];
93 var e = num[ curPage ][1];
95 if ( !curPage ) prev.hide();
98 if ( curPage == names.length - 1 ) next.hide();
106 pagedUI.empty().append(
107 jQuery.makeArray( rows ).slice( s, s + e )