Skip to content

Commit 635134e

Browse files
committed
Merge pull request #15 from mischah/dev
Disable the pagination if there its only one page (by default)
2 parents 46079b9 + c27ebe6 commit 635134e

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

src/demo/demo_singlePage.htm

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5+
<title>Pagination Demo I - Simple pagination</title>
6+
<link rel="stylesheet" href="../pagination.css" />
7+
<link rel="stylesheet" href="demo.css" />
8+
<script type="text/javascript" src="lib/jquery.min.js"></script>
9+
<script type="text/javascript" src="../jquery.pagination.js"></script>
10+
11+
<script type="text/javascript">
12+
13+
// This is a very simple demo that showing the options for handling a single page.
14+
// Default of the option show_if_single_page is false.
15+
// So you only have to call the plugin with this option if you feel the need
16+
// to show the pagination even if there is only one single page.
17+
// Otherwise just leave it out.
18+
19+
/**
20+
* Callback function that displays the content.
21+
*
22+
* Gets called every time the user clicks on a pagination link.
23+
*
24+
* @param {int} page_index New Page index
25+
* @param {jQuery} jq the container with the pagination links as a jQuery object
26+
*/
27+
function pageselectCallback(page_index, jq){
28+
var new_content = jQuery('#hiddenresult div.result:eq('+page_index+')').clone();
29+
$('#Searchresult').empty().append(new_content);
30+
return false;
31+
}
32+
33+
/**
34+
* Initialisation function for pagination
35+
*/
36+
function initPagination() {
37+
// count entries inside the hidden content
38+
var num_entries = jQuery('#hiddenresult div.result').length;
39+
// Create content inside pagination element
40+
$("#Pagination").pagination(num_entries, {
41+
callback: pageselectCallback,
42+
items_per_page:1, // Show only one item per page
43+
//show_if_single_page:true // Show if there is only one single page
44+
});
45+
}
46+
47+
// When document is ready, initialize pagination
48+
$(document).ready(function(){
49+
initPagination();
50+
});
51+
52+
53+
54+
</script>
55+
</head>
56+
<body>
57+
<h1>jQuery Pagination Plugin Demo</h1>
58+
59+
<h2>Show Pagination if there is only one single page</h2>
60+
<div id="Pagination"></div>
61+
<div id="Searchresult" style="clear:both;">
62+
<p>Page 1</p>
63+
</div>
64+
65+
<!-- Container element for all the Elements that are to be paginated -->
66+
<div id="hiddenresult" style="display:none;">
67+
<div class="result">
68+
<p>Page 1</p>
69+
</div>
70+
<!--
71+
<div class="result">
72+
<p>Page 2</p>
73+
</div>
74+
-->
75+
</div>
76+
77+
<div id="footer">
78+
Copyright &copy; 2010 by <a href="http://www.d-scribe.de/">describe europe Ltd.</a>.
79+
</div>
80+
</body>
81+
</html>

src/jquery.pagination.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
prev_show_always:true,
143143
next_show_always:true,
144144
renderer:"defaultRenderer",
145+
show_if_single_page:false,
145146
load_first_page:false,
146147
callback:function(){return false;}
147148
},opts||{});
@@ -221,7 +222,9 @@
221222
// When all initialisation is done, draw the links
222223
links = renderer.getLinks(current_page, paginationClickHandler);
223224
containers.empty();
224-
links.appendTo(containers);
225+
if(np > 1 || opts.show_if_single_page) {
226+
links.appendTo(containers);
227+
}
225228
// call callback function
226229
if(opts.load_first_page) {
227230
opts.callback(current_page, containers);

0 commit comments

Comments
 (0)