Skip to content

Commit

Permalink
Merge pull request gbirke#15 from mischah/dev
Browse files Browse the repository at this point in the history
Disable the pagination if there its only one page (by default)
  • Loading branch information
gbirke committed Sep 7, 2011
2 parents 46079b9 + c27ebe6 commit 635134e
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
81 changes: 81 additions & 0 deletions src/demo/demo_singlePage.htm
@@ -0,0 +1,81 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Pagination Demo I - Simple pagination</title>
<link rel="stylesheet" href="../pagination.css" />
<link rel="stylesheet" href="demo.css" />
<script type="text/javascript" src="lib/jquery.min.js"></script>
<script type="text/javascript" src="../jquery.pagination.js"></script>

<script type="text/javascript">

// This is a very simple demo that showing the options for handling a single page.
// Default of the option show_if_single_page is false.
// So you only have to call the plugin with this option if you feel the need
// to show the pagination even if there is only one single page.
// Otherwise just leave it out.

/**
* Callback function that displays the content.
*
* Gets called every time the user clicks on a pagination link.
*
* @param {int} page_index New Page index
* @param {jQuery} jq the container with the pagination links as a jQuery object
*/
function pageselectCallback(page_index, jq){
var new_content = jQuery('#hiddenresult div.result:eq('+page_index+')').clone();
$('#Searchresult').empty().append(new_content);
return false;
}

/**
* Initialisation function for pagination
*/
function initPagination() {
// count entries inside the hidden content
var num_entries = jQuery('#hiddenresult div.result').length;
// Create content inside pagination element
$("#Pagination").pagination(num_entries, {
callback: pageselectCallback,
items_per_page:1, // Show only one item per page
//show_if_single_page:true // Show if there is only one single page
});
}

// When document is ready, initialize pagination
$(document).ready(function(){
initPagination();
});



</script>
</head>
<body>
<h1>jQuery Pagination Plugin Demo</h1>

<h2>Show Pagination if there is only one single page</h2>
<div id="Pagination"></div>
<div id="Searchresult" style="clear:both;">
<p>Page 1</p>
</div>

<!-- Container element for all the Elements that are to be paginated -->
<div id="hiddenresult" style="display:none;">
<div class="result">
<p>Page 1</p>
</div>
<!--
<div class="result">
<p>Page 2</p>
</div>
-->
</div>

<div id="footer">
Copyright &copy; 2010 by <a href="http://www.d-scribe.de/">describe europe Ltd.</a>.
</div>
</body>
</html>
5 changes: 4 additions & 1 deletion src/jquery.pagination.js
Expand Up @@ -142,6 +142,7 @@
prev_show_always:true,
next_show_always:true,
renderer:"defaultRenderer",
show_if_single_page:false,
load_first_page:false,
callback:function(){return false;}
},opts||{});
Expand Down Expand Up @@ -221,7 +222,9 @@
// When all initialisation is done, draw the links
links = renderer.getLinks(current_page, paginationClickHandler);
containers.empty();
links.appendTo(containers);
if(np > 1 || opts.show_if_single_page) {
links.appendTo(containers);
}
// call callback function
if(opts.load_first_page) {
opts.callback(current_page, containers);
Expand Down

0 comments on commit 635134e

Please sign in to comment.