Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,37 @@ <h3>Source</h3>
}).on('page', function(event, num){
// ... load content from the server and update DOM
$(".content3").html("Dynamic content for Page #" + num);
});</code></pre>
</div>
<h2 id="example-maxvisible1">maxVisible: 1 example</h2>
<ul>
<li>Only one page number visible at a time.</li>
<li>Use prev/next to navigate all 10 pages.</li>
</ul>
<div class="bs-docs-example">
<div class="border rounded p-3 text-center demo content5">
Dynamic content here.
</div>
<p class="demo demo5"></p>
</div>
<h3>Source</h3>
<div class="code-snippet">
<button
type="button"
class="btn-clipboard"
data-bs-toggle="tooltip"
data-bs-title="Copy to clipboard"
aria-label="Copy to clipboard"
>
<svg width="20" height="20" fill="currentColor">
<use href="#clipboard"></use>
</svg>
</button>
<pre><code class="language-javascript">$('.demo5').bootpag({
total: 10,
maxVisible: 1
}).on('page', function(event, num){
$(".content5").html("Dynamic content for Page #" + num);
});</code></pre>
</div>
<h2 id="example-full">Full example</h2>
Expand Down Expand Up @@ -386,6 +417,14 @@ <h3>Source</h3>
.on("page", function (event, num) {
$(".content3").html("Dynamic content for Page #" + num); // or load content from the server
});
$(".demo5")
.bootpag({
total: 10,
maxVisible: 1,
})
.on("page", function (event, num) {
$(".content5").html("Dynamic content for Page #" + num);
});
$(".demo4_top,.demo4_bottom")
.bootpag({
total: 50,
Expand Down
2 changes: 1 addition & 1 deletion src/jquery.bootpag.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
.find('a').attr('href', href(lp));
}

step = settings.maxVisible == 1 ? 0 : 1;
step = 1;

lp = page + 1 > settings.total ? settings.total :
settings.leaps && page + 1 <= settings.total - settings.maxVisible ?
Expand Down
9 changes: 9 additions & 0 deletions test/bootpag.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ describe('Leaps', () => {
expect(handler.mock.calls[0][1]).toBe(6);
});

test('with maxVisible: 1, next advances to the next page', () => {
var handler = jest.fn();
$('#pag').bootpag({ total: 5, maxVisible: 1, leaps: true }).on('page', handler);
$('#pag li.next').trigger('click');
expect(handler).toHaveBeenCalledTimes(1);
expect(handler.mock.calls[0][1]).toBe(2);
expect($('#pag li.active').attr('data-lp')).toBe('2');
});

test('with leaps: false, next advances by 1', () => {
var handler = jest.fn();
$('#pag').bootpag({ total: 20, maxVisible: 5, leaps: false }).on('page', handler);
Expand Down