/** * this jquery plugin displays pagination links inside the selected elements. * * @author gabriel birke (birke *at* d-scribe *dot* de) * @version 1.2 * @param {int} maxentries number of entries to paginate * @param {object} opts several options (see readme for documentation) * @return {object} jquery object */ jquery.fn.pagination1 = function(maxentries, opts){ opts = jquery.extend({ items_per_page:10, num_display_entries:10, current_page:0, num_edge_entries:0, link_to:"#", prev_text:"prev", next_text:"next", ellipse_text:"...", prev_show_always:true, next_show_always:true, callback:function(){return false;} },opts||{}); return this.each(function() { /** * 鐠侊紕鐣婚張鈧径褍鍨庢い鍨▔缁€鐑樻殶閻╋拷 */ function numpages() { return math.ceil(maxentries/opts.items_per_page); } /** * 閺嬩胶顏崚鍡涖€夐惃鍕崳婵鎷扮紒鎾存将閻愮櫢绱濇潻娆忓絿閸愬厖绨琧urrent_page 閸滐拷 num_display_entries. * @鏉╂柨娲� {閺佹壆绮�(array)} */ function getinterval() { var ne_half = math.ceil(opts.num_display_entries/2); var np = numpages(); var upper_limit = np-opts.num_display_entries; var start = current_page>ne_half?math.max(math.min(current_page-ne_half, upper_limit), 0):0; var end = current_page>ne_half?math.min(current_page+ne_half, np):math.min(opts.num_display_entries, np); return [start,end]; } /** * 閸掑棝銆夐柧鐐复娴滃娆㈡径鍕倞閸戣姤鏆� * @閸欏倹鏆� {int} page_id 娑撶儤鏌婃い鐢电垳 */ function pageselected(page_id, evt){ current_page = page_id; drawlinks(); var continuepropagation = opts.callback(page_id, panel); if (!continuepropagation) { if (evt.stoppropagation) { evt.stoppropagation(); } else { evt.cancelbubble = true; } } return continuepropagation; } /** * 濮濄倕鍤遍弫鏉跨殺閸掑棝銆夐柧鐐复閹绘帒鍙嗛崚鏉款啇閸c劌鍘撶槐鐘辫厬 */ function drawlinks() { panel.empty(); var interval = getinterval(); var np = numpages(); // 鏉╂瑤閲滄潏鍛и閸戣姤鏆熸潻鏂挎礀娑撯偓娑擃亜顦╅悶鍡楀毐閺佹媽鐨熼悽銊︽箒閻偓濮濓絿鈥榩age_id閻ㄥ埦ageselected閵嗭拷 var getclickhandler = function(page_id) { return function(evt){ return pageselected(page_id,evt); } } //鏉堝懎濮崙鑺ユ殶閻劍娼垫禍褏鏁撴稉鈧稉顏勫礋闁剧偓甯�(婵″倹鐏夋稉宥嗘ц瑜版挸澧犳い闈涘灟娴溠呮晸span閺嶅洨顒�) var appenditem = function(page_id, appendopts){ page_id = page_id<0?0:(page_id"+(appendopts.text)+""); }else{ var lnk = jquery(""+(appendopts.text)+"") .bind("click", getclickhandler(page_id)) .attr('href', opts.link_to.replace(/__id__/,page_id)); } if(appendopts.classes){lnk.addclass(appendopts.classes);} panel.append(lnk); } // 娴溠呮晸"previous"-闁剧偓甯� if(opts.prev_text && (current_page > 0 || opts.prev_show_always)){ appenditem(current_page-1,{text:opts.prev_text, classes:"prev"}); } // 娴溠呮晸鐠у嘲顫愰悙锟� if (interval[0] > 0 && opts.num_edge_entries > 0) { var end = math.min(opts.num_edge_entries, interval[0]); for(var i=0; i"+opts.ellipse_text+"").appendto(panel); } } // 娴溠呮晸閸愬懘鍎撮惃鍕昂闁剧偓甯� for(var i=interval[0]; i 0) { if(np-opts.num_edge_entries > interval[1]&& opts.ellipse_text) { jquery(""+opts.ellipse_text+"").appendto(panel); } var begin = math.max(np-opts.num_edge_entries, interval[1]); for(var i=begin; i 0) { pageselected(current_page - 1); return true; } else { return false; } } this.nextpage = function(){ if(current_page < numpages()-1) { pageselected(current_page+1); return true; } else { return false; } } // 閹碘偓閺堝鍨垫慨瀣鐎瑰本鍨氶敍宀€绮崚鍫曟懠閹猴拷 drawlinks(); // 閸ョ偠鐨熼崙鑺ユ殶 opts.callback(current_page, this); }); }