PageSourceSearch

https://eclos.fr/wp-content/themes/kidba/assets/js/simple-pagination.js?ver=6.8.2

js eclos.fr collected 2026-10-03 02:47:28 UTC 6,260 bytes, 236 lines download raw bytes

1/**
2* simplePagination.js v1.6
3* A simple jQuery pagination plugin.
4* http://flaviusmatis.github.com/simplePagination.js/
5*
6* Copyright 2012, Flavius Matis
7* Released under the MIT license.
8* http://flaviusmatis.github.com/license.html
9*/
10
11(function($){
12
13	var methods = {
14		init: function(options) {
15			var o = $.extend({
16				items: 1,
17				itemsOnPage: 1,
18				pages: 0,
19				displayedPages: 5,
20				edges: 2,
21				currentPage: 1,
22				hrefTextPrefix: '#page-',
23				hrefTextSuffix: '',
24				prevText: 'Prev',
25				nextText: 'Next',
26				ellipseText: '…',
27				cssStyle: 'light-theme',
28				selectOnClick: true,
29				onPageClick: function(pageNumber, event) {
30					// Callback triggered when a page is clicked
31					// Page number is given as an optional parameter
32				},
33				onInit: function() {
34					// Callback triggered immediately after initialization
35				}
36			}, options || {});
37
38			var self = this;
39
40			o.pages = o.pages ? o.pages : Math.ceil(o.items / o.itemsOnPage) ? Math.ceil(o.items / o.itemsOnPage) : 1;
41			o.currentPage = o.currentPage - 1;
42			o.halfDisplayed = o.displayedPages / 2;
43
44			this.each(function() {
45				self.addClass(o.cssStyle + ' simple-pagination').data('pagination', o);
46				methods._draw.call(self);
47			});
48
49			o.onInit();
50
51			return this;
52		},
53
54		selectPage: function(page) {
55			methods._selectPage.call(this, page - 1);
56			return this;
57		},
58
59		prevPage: function() {
60			var o = this.data('pagination');
61			if (o.currentPage > 0) {
62				methods._selectPage.call(this, o.currentPage - 1);
63			}
64			return this;
65		},
66
67		nextPage: function() {
68			var o = this.data('pagination');
69			if (o.currentPage < o.pages - 1) {
70				methods._selectPage.call(this, o.currentPage + 1);
71			}
72			return this;
73		},
74
75		getPagesCount: function() {
76			return this.data('pagination').pages;
77		},
78
79		getCurrentPage: function () {
80			return this.data('pagination').currentPage + 1;
81		},
82
83		destroy: function(){
84			this.empty();
85			return this;
86		},
87
88		redraw: function(){
89			methods._draw.call(this);
90			return this;
91		},
92
93		disable: function(){
94			var o = this.data('pagination');
95			o.disabled = true;
96			this.data('pagination', o);
97			methods._draw.call(this);
98			return this;
99		},
100
101		enable: function(){
102			var o = this.data('pagination');
103			o.disabled = false;
104			this.data('pagination', o);
105			methods._draw.call(this);
106			return this;
107		},
108
109		updateItems: function (newItems) {
110			var o = this.data('pagination');
111			o.items = newItems;
112			o.pages = Math.ceil(o.items / o.itemsOnPage) ? Math.ceil(o.items / o.itemsOnPage) : 1;
113			this.data('pagination', o);
114			methods._draw.call(this);
115		},
116
117		_draw: function() {
118			var	o = this.data('pagination'),
119				interval = methods._getInterval(o),
120				i;
121
122			methods.destroy.call(this);
123
124			var $panel = this.prop("tagName") === "UL" ? this : $('<ul></ul>').appendTo(this);
125
126			// Generate Prev link
127			if (o.prevText) {
128				methods._appendItem.call(this, o.currentPage - 1, {text: o.prevText, classes: 'prev'});
129			}
130
131			// Generate start edges
132			if (interval.start > 0 && o.edges > 0) {
133				var end = Math.min(o.edges, interval.start);
134				for (i = 0; i < end; i++) {
135					methods._appendItem.call(this, i);
136				}
137				if (o.edges < interval.start && (interval.start - o.edges != 1)) {
138					$panel.append('<li class="disabled"><span class="ellipse">' + o.ellipseText + '</span></li>');
139				} else if (interval.start - o.edges == 1) {
140					methods._appendItem.call(this, o.edges);
141				}
142			}
143
144			// Generate interval links
145			for (i = interval.start; i < interval.end; i++) {
146				methods._appendItem.call(this, i);
147			}
148
149			// Generate end edges
150			if (interval.end < o.pages && o.edges > 0) {
151				if (o.pages - o.edges > interval.end && (o.pages - o.edges - interval.end != 1)) {
152					$panel.append('<li class="disabled"><span class="ellipse">' + o.ellipseText + '</span></li>');
153				} else if (o.pages - o.edges - interval.end == 1) {
154					methods._appendItem.call(this, interval.end++);
155				}
156				var begin = Math.max(o.pages - o.edges, interval.end);
157				for (i = begin; i < o.pages; i++) {
158					methods._appendItem.call(this, i);
159				}
160			}
161
162			// Generate Next link
163			if (o.nextText) {
164				methods._appendItem.call(this, o.currentPage + 1, {text: o.nextText, classes: 'next'});
165			}
166		},
167
168		_getInterval: function(o) {
169			return {
170				start: Math.ceil(o.currentPage > o.halfDisplayed ? Math.max(Math.min(o.currentPage - o.halfDisplayed, (o.pages - o.displayedPages)
vendor: 1,837 bytes, lines 170-236
170), 0) : 0),
171				end: Math.ceil(o.currentPage > o.halfDisplayed ? Math.min(o.currentPage + o.halfDisplayed, o.pages) : Math.min(o.displayedPages, o.pages))
172			};
173		},
174
175		_appendItem: function(pageIndex, opts) {
176			var self = this, options, $link, o = self.data('pagination'), $linkWrapper = $('<li></li>'), $ul = self.find('ul');
177
178			pageIndex = pageIndex < 0 ? 0 : (pageIndex < o.pages ? pageIndex : o.pages - 1);
179
180			options = $.extend({
181				text: pageIndex + 1,
182				classes: ''
183			}, opts || {});
184
185			if (pageIndex == o.currentPage || o.disabled) {
186				if (o.disabled) {
187					$linkWrapper.addClass('disabled');
188				} else {
189					$linkWrapper.addClass('active');
190				}
191				$link = $('<span class="current">' + (options.text) + '</span>');
192			} else {
193				$link = $('<a href="' + o.hrefTextPrefix + (pageIndex + 1) + o.hrefTextSuffix + '" class="page-link">' + (options.text) + '</a>');
194				$link.click(function(event){
195					return methods._selectPage.call(self, pageIndex, event);
196				});
197			}
198
199			if (options.classes) {
200				$link.addClass(options.classes);
201			}
202
203			$linkWrapper.append($link);
204
205			if ($ul.length) {
206				$ul.append($linkWrapper);
207			} else {
208				self.append($linkWrapper);
209			}
210		},
211
212		_selectPage: function(pageIndex, event) {
213			var o = this.data('pagination');
214			o.currentPage = pageIndex;
215			if (o.selectOnClick) {
216				methods._draw.call(this);
217			}
218			return o.onPageClick(pageIndex + 1, event);
219		}
220
221	};
222	
223	$.fn.pagination = function(method) {
224
225		// Method calling logic
226		if (methods[method] && method.charAt(0) != '_') {
227			return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
228		} else if (typeof method === 'object' || !method) {
229			return methods.init.apply(this, arguments);
230		} else {
231			$.error('Method ' +  method + ' does not exist on jQuery.pagination');
232		}
233
234	};
235
236})(jQuery);

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.