Skip to content

Commit 36a2348

Browse files
update
1 parent fac8923 commit 36a2348

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/Schema/Pagination/Yidas/views/cursor.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<?php if($isFirst):?>
1919
<span <?=$linkAttributes?>><?=$this->prevPageLabel?></span>
2020
<?php else: ?>
21-
<a <?=$linkAttributes?> data-target="[data-pagination-content]" href="<?=$prevUrl?>"><?=$this->prevPageLabel?></a>
21+
<a <?=$linkAttributes?> data-target="[data-pagination-content]" data-history="none" href="<?=$prevUrl?>"><?=$this->prevPageLabel?></a>
2222
<?php endif ?>
2323

2424
<?php foreach ($this->_buttonStack as $key => $btnPage): ?>
@@ -28,7 +28,7 @@
2828
<?php if($isLast):?>
2929
<span <?=$linkAttributes?>><?=$this->nextPageLabel?></span>
3030
<?php else: ?>
31-
<a <?=$linkAttributes?> data-target="[data-pagination-content]" href="<?=$nextUrl?>"><?=$this->nextPageLabel?></a>
31+
<a <?=$linkAttributes?> data-target="[data-pagination-content]" data-history="none" href="<?=$nextUrl?>"><?=$this->nextPageLabel?></a>
3232
<?php endif ?>
3333
</div>
3434

@@ -56,6 +56,8 @@ function closestAnchor(el){
5656
// Prevent default only for our ajax link
5757
e.preventDefault();
5858

59+
// Decide the history behavior from data-attributes
60+
var historyMode = a.getAttribute('data-history') || 'push'; // 'push' | 'replace' | 'none'
5961
var targetSelector = a.getAttribute('data-target') || '[data-pagination-content]';
6062
var scope = a.closest('[data-pagination-scope]');
6163
var container = document.querySelector(targetSelector);
@@ -83,7 +85,11 @@ function closestAnchor(el){
8385
curShowing.innerHTML = newShowing.innerHTML;
8486
}
8587

86-
try { window.history.pushState({}, '', href); } catch(_e) {}
88+
// Manage history
89+
try {
90+
if(historyMode === 'push') window.history.pushState({}, '', a.getAttribute('href'));
91+
else if(historyMode === 'replace') window.history.replaceState({}, '', a.getAttribute('href'));
92+
} catch(_e) {}
8793
})
8894
.catch(function(){ window.location.href = href; })
8995
.finally(function(){ a.removeAttribute('aria-busy'); });

src/Schema/Pagination/Yidas/views/loading.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
$lastUrl = $this->pagination->createUrl($totalPages);
1414
?>
1515
<?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;">
1717
Load More
1818
</a>
1919
<?php else: ?>
@@ -54,7 +54,11 @@ function closestAnchor(el){
5454

5555
a.setAttribute('aria-busy', 'true');
5656

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)
5862
.then(function(res){ return res.text(); })
5963
.then(function(html){
6064
var parser = new DOMParser();
@@ -85,9 +89,13 @@ function closestAnchor(el){
8589
curShowing.innerHTML = newShowing.innerHTML;
8690
}
8791

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) {}
8997
})
90-
.catch(function(){ window.location.href = href; })
98+
.catch(function(){ window.location.href = a.getAttribute('href'); })
9199
.finally(function(){ a.removeAttribute('aria-busy'); });
92100
});
93101
})();

0 commit comments

Comments
 (0)