PageSourceSearch

https://www.csgyb.com.cn/static/default/static/js/jquery.pagination.js

js csgyb.com.cn collected 2026-10-03 17:34:56 UTC 5,180 bytes, 168 lines download raw bytes

1/**
2 * This jQuery plugin displays pagination links inside the selected elements.
3 *
4 * @author Gabriel Birke (birke *at* d-scribe *dot* de)
5 * @version 1.2
6 * @param {int} maxentries Number of entries to paginate
7 * @param {Object} opts Several options (see README for documentation)
8 * @return {Object} jQuery Object
9 */
10jQuery.fn.pagination = function(maxentries, opts){
11	opts = jQuery.extend({
12		items_per_page:10,
13		num_display_entries:10,
14		current_page:0,
15		num_edge_entries:0,
16		link_to:"#",
17		prev_text:"Prev",
18		next_text:"Next",
19		ellipse_text:"...",
20		prev_show_always:true,
21		next_show_always:true,
22		isAjax:false,
23		callback_afterinit:false,
24		callback:function(){return false;}
25	},opts||{});
26	
27	return this.each(function() {
28		/**
29		 * 计算最大分页显示数目
30		 */
31		function numPages() {
32			return Math.ceil(maxentries/opts.items_per_page);
33		}	
34		/**
35		 * 极端分页的起始和结束点,这取决于current_page 和 num_display_entries.
36		 * @返回 {数组(Array)}
37		 */
38		function getInterval()  {
39			var ne_half = Math.ceil(opts.num_display_entries/2);
40			var np = numPages();
41			var upper_limit = np-opts.num_display_entries;
42			var start = current_page>ne_half?Math.max(Math.min(current_page-ne_half, upper_limit), 0):0;
43			var end = current_page>ne_half?Math.min(current_page+ne_half, np):Math.min(opts.num_display_entries, np);
44			return [start,end];
45		}
46		
47		/**
48		 * 分页链接事件处理函数
49		 * @参数 {int} page_id 为新页码
50		 */
51		function pageSelected(page_id, evt){
52			if(opts.isAjax){
53			  current_page = page_id;
54			  drawLinks();
55			}			
56			var continuePropagation = opts.callback(page_id, panel);
57			if (!continuePropagation) {
58				if (evt.stopPropagation) {
59					evt.stopPropagation();
60				}
61				else {
62					evt.cancelBubble = true;
63				}
64			}
65			return continuePropagation;
66		}
67		
68		/**
69		 * 此函数将分页链接插入到容器元素中
70		 */
71		function drawLinks() {
72			panel.empty();
73			var interval = getInterval();
74			var np = numPages();
75			// 这个辅助函数返回一个处理函数调用有着正确page_id的pageSelected。
76			var getClickHandler = function(page_id) {
77				return function(evt){ return pageSelected(page_id,evt); }
78			}
79			//辅助函数用来产生一个单链接(如果不是当前页则产生span标签)
80			var appendItem = function(page_id, appendopts){
81				page_id = page_id<0?0:(page_id<np?page_id:np-1); // 规范page id值
82				appendopts = jQuery.extend({text:page_id+1, classes:""}, appendopts||{});
83				if(page_id == current_page){
84					var lnk = jQuery("<span class='current'>"+(appendopts.text)+"</span>");
85				}else{
86					var lnk = jQuery("<a>"+(appendopts.text)+"</a>")
87						.bind("click", getClickHandler(page_id))
88						.attr('href', opts.link_to.replace(/__id__/,page_id));		
89				}
90				if(appendopts.classes){lnk.addClass(appendopts.classes);}
91				panel.append(lnk);
92			}
93			// 产生"Previous"-链接
94			if(opts.prev_text && (current_page > 0 || opts.prev_show_always)){
95				appendItem(current_page-1,{text:opts.prev_text, classes:"prev"});
96			}
97			// 产生起始点
98			if (interval[0] > 0 && opts.num_edge_entries > 0)
99			{
100				var end = Math.min(opts.num_edge_entries, interval[0]);
101				for(var i=0; i<end; i++) {
102					appendItem(i);
103				}
104				if(opts.num_edge_entries < interval[0] && opts.ellipse_text)
105				{
106					jQuery("<span>"+opts.ellipse_text+"</span>").appendTo(panel);
107				}
108			}
109			// 产生内部的些链接
110			for(var i=interval[0]; i<interval[1]; i++) {
111				appendItem(i);
112			}
113			// 产生结束点
114			if (interval[1] < np && opts.num_edge_entries > 0)
115			{
116				if(np-opts.num_edge_entries > interval[1]&& opts.ellipse_text)
117				{
118					jQuery("<span>"+opts.ellipse_text+"</span>").appendTo(panel);
119				}
120				var begin = Math.max(np-opts.num_edge_entries, interval[1]);
121				for(var i=begin; i<np; i++) {
122					appendItem(i);
123				}
124				
125			}
126			// 产生 "Next"-链接
127			if(opts.next_text && (current_page < np-1 || opts.next_show_always)){
128				appendItem(current_page+1,{text:opts.next_text, classes:"next"});
129			}
130		}
131		
132		//从选项中提取current_page
133		var current_page = opts.current_page;
134		//创建一个显示条数和每页显示条数值
135		maxentries = (!maxentries || maxentries < 0)?1:maxentries;
136		opts.items_per_page = (!opts.items_per_page || opts.items_per_page < 0)?1:opts.items_per_page;
137		//存储DOM元素,以方便从所有的内部结构中获取
138		var panel = jQuery(this);
139		// 获得附加功能的元素
140		this.selectPage = function(page_id){ pageSelected(page_id);}
141		this.prevPage = function(){ 
142			if (current_page > 0) {
143				pageSelected(current_page - 1);
144				return true;
145			}
146			else {
147				return false;
148			}
149		}
150		this.nextPage = function(){ 
151			if(current_page < numPages()-1) {
152				pageSelected(current_page+1);
153				return true;
154			}
155			else {
156				return false;
157			}
158		}
159		// 所有初始化完成,绘制链接
160		drawLinks();
161        // 回调函数
162		if(opts.callback_afterinit){        
163		  opts.callback(current_page, this);
164		}
165	});
166}
167
168

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.