-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpagination.js
More file actions
95 lines (79 loc) · 2.96 KB
/
pagination.js
File metadata and controls
95 lines (79 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
******* www.devandclick.fr *******
modeles :
1 : suivant,precedent
2 : pagination
3 : pagination + suivant,precedent
@nbParPage : nombre d'elements par page
@divSelect : elements a paginer
@divPager : nom du div ou s'insere la pagination
@model : Modeles de pagination voir ci-dessus
*/
function pagination(nbParPage,divSelect,divPager,model)
{
//Initialisation
var nbElem = $(divSelect).length;
var nbPage = Math.ceil(nbElem / nbParPage);
var pageLoad = 1;
$(divSelect).each(function(index) {
if (index < nbParPage)
$(divSelect).eq(index).show();
else
$(divSelect).eq(index).hide();
});
//Reset & verification
function reset() {
if (nbPage < 2) $(divPager).hide();
if (pageLoad == nbPage) $(divPager + ' span.suivant').hide(); else $(divPager + ' span.suivant').show();
if (pageLoad == 1) $(divPager + ' span.precedent').hide(); else $(divPager + ' span.precedent').show();
$(divPager + ' ul li').removeClass('selected');
$(divPager + ' ul li').eq(pageLoad -1).addClass('selected');
}
//Pagination generation
if (model != 1) {
$(divPager).html('<ul></ul>');
for(i = 1; i <= nbPage; i++) $(divPager + ' ul').append('<li>' + i + '</li>');
//Changement click page
$(divPager + ' ul li').click(function() {
if ($(this).index() + 1 != pageLoad) {
pageLoad = $(this).index() + 1;
$(divSelect).hide();
$(divSelect).each(function(i) {
if (i >= ((pageLoad * nbParPage) - nbParPage) && i < (pageLoad * nbParPage)) $(this).show();
});
reset();
}
});
}
//Suivant Precedent
if (model == 1) {
$(divPager).prepend('<span class="precedent">Precedent</span>');
$(divPager).append('<span class="suivant">Suivant></span>');
} else if (model == 3) {
$(divPager + ' ul').before('<span class="precedent">Precedent</span>');
$(divPager + ' ul').after('<span class="suivant">Suivant</span>');
}
//Evenement click sur suivant
$(divPager + ' span.suivant').click(function() {
if (pageLoad < nbPage) {
pageLoad += 1;
$(divSelect).hide();
$(divSelect).each(function(i) {
if (i >= ((pageLoad * nbParPage) - nbParPage) && i < (pageLoad * nbParPage)) $(this).show();
});
reset();
}
});
//Evenement click sur precedent
$(divPager + ' span.precedent').click(function() {
if (pageLoad -1 >= 1) {
pageLoad -= 1;
$(divSelect).hide();
$(divSelect).each(function(i) {
if (i >= ((pageLoad * nbParPage) - nbParPage) && i < (pageLoad * nbParPage)) $(this).show();
});
reset();
}
});
reset();
}