Correctifs
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage_django / media / js / pagination.js
CommitLineData
a008c7e5
CR
1function urlencode(str) {
2 return escape(str).replace(/\+/g,'%2B').replace(
3 /%20/g, '+').replace(/\*/g, '%2A').replace(
4 /\//g, '%2F').replace(/@/g, '%40');
5}
6function getUrlVars()
7{
8 var vars = {};
9 var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
10 for(var i = 0; i < hashes.length; i++)
11 {
12 var hash = hashes[i].split('=');
13 vars[hash[0]] = hash[1];
14 }
15 return vars;
16}
17function makeLink (page) {
18 var params = getUrlVars ();
19 params.page = page;
20 var rc = "?";
21 for (k in params) {
22 rc += k + "=" + urlencode(params[k]) + "&";
23 }
24 rc = rc.substr (0, rc.length - 1);
25 return rc;
26}
27function makePageLinks (currentPage, lastPage, more) {
28 var span = $("#pageLinks");
29 // Premiere page
30 if (currentPage == 0)
31 span.append ('<span class="lien-texte">&lt;&lt;</span>&nbsp;&nbsp;');
32 else
33 span.append ('<a href="' + makeLink(0) +
34 '"><span class="lien-texte">&lt;&lt;</span></a>&nbsp;&nbsp;');
35
36 // Boucle
37 var f = currentPage - 4;
38 var t = 0;
39 if (f < 0) { t = -f; f = 0; }
40 t += currentPage + 4;
41 if (t > lastPage) t = lastPage;
42
43 for (var i = f; i <= t; i++) {
44 var display = i + 1;
45 if (i == currentPage)
46 span.append ("<span>" + display + "</span>&nbsp;&nbsp;");
47 else
48 span.append ('<a href="' + makeLink(i) + '"><span>' +
49 display + '</span></a>&nbsp;&nbsp;');
50 }
51
52 // Derniere page
53 if (currentPage == lastPage)
54 span.append ('<span class="lien-texte">&gt;&gt;</span>');
55 else
56 span.append ('<a href="' + makeLink(lastPage) +
57 '"><span class="lien-texte">&gt;&gt;</span></a>');
58
59 if (more.length > 0)
60 span.append ('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' +
61 '<a href="'+more+'"><span class="lien-texte">Plus de résultats</span></a>');
62}