|
13 | 13 | $lastUrl = $this->pagination->createUrl($totalPages); |
14 | 14 | ?> |
15 | 15 | <?php if (!$isLast): ?> |
16 | | - <a <?=$linkAttributes?> href="<?php echo $nextUrl; ?>" class="load-more-btn" data-page="<?php echo $nextPage; ?>" data-mode="append" data-target="[data-pagination-append]" style="padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer; text-decoration: none; display: inline-block;"> |
| 16 | + <a <?=$linkAttributes?> href="<?php echo $nextUrl; ?>" class="load-more-btn" data-page="<?php echo $nextPage; ?>" data-mode="append" data-target="[data-pagination-append]" data-history="none" style="padding: 10px 20px; background-color: #007bff; color: white; border: none; border-radius: 5px; cursor: pointer; text-decoration: none; display: inline-block;"> |
17 | 17 | Load More |
18 | 18 | </a> |
19 | 19 | <?php else: ?> |
@@ -54,7 +54,11 @@ function closestAnchor(el){ |
54 | 54 |
|
55 | 55 | a.setAttribute('aria-busy', 'true'); |
56 | 56 |
|
57 | | - fetch(href, { headers: { 'X-Requested-With': 'XMLHttpRequest' }}) |
| 57 | + // Decide the history behavior from data-attributes |
| 58 | + var historyMode = a.getAttribute('data-history') || 'push'; // 'push' | 'replace' | 'none' |
| 59 | + var fetchOptions = { headers: { 'X-Requested-With': 'XMLHttpRequest' } }; |
| 60 | + |
| 61 | + fetch(href, fetchOptions) |
58 | 62 | .then(function(res){ return res.text(); }) |
59 | 63 | .then(function(html){ |
60 | 64 | var parser = new DOMParser(); |
@@ -85,9 +89,13 @@ function closestAnchor(el){ |
85 | 89 | curShowing.innerHTML = newShowing.innerHTML; |
86 | 90 | } |
87 | 91 |
|
88 | | - try { window.history.pushState({}, '', href); } catch(_e) {} |
| 92 | + // Manage history |
| 93 | + try { |
| 94 | + if(historyMode === 'push') window.history.pushState({}, '', a.getAttribute('href')); |
| 95 | + else if(historyMode === 'replace') window.history.replaceState({}, '', a.getAttribute('href')); |
| 96 | + } catch(_e) {} |
89 | 97 | }) |
90 | | - .catch(function(){ window.location.href = href; }) |
| 98 | + .catch(function(){ window.location.href = a.getAttribute('href'); }) |
91 | 99 | .finally(function(){ a.removeAttribute('aria-busy'); }); |
92 | 100 | }); |
93 | 101 | })(); |
|
0 commit comments