Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
51 changes: 30 additions & 21 deletions themes/bootstrap5/js/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,17 @@ VuFind.register("channels", function Channels() {
return false;
}

// Disable and relabel button
disableLoadMoreBtn(btn);

// Reveal hidden items
const targetChannel = btn.closest(".channel");
const pageSize = Number(targetChannel.dataset.pageSize);
const hiddenItems = targetChannel.querySelectorAll(".hidden-batch-item");

// If we're waiting for more records
if (hiddenItems.length === 0) {
disableLoadMoreBtn(btn);
return;
}

// Reveal hidden items (limit to pageSize)
hiddenItems.forEach((item, index) => {
if (index < pageSize) {
Expand All @@ -190,20 +193,22 @@ VuFind.register("channels", function Channels() {
}
});

// Out of records
if (hiddenItems.length > 0 && hiddenItems.length < Number(targetChannel.dataset.rowSize)) {
const remainingHiddenItems = hiddenItems.length - pageSize;

// out of records?
if (remainingHiddenItems <= 0) {
hideLoadMoreBtn(btn);
return;
}

// How many more records do we need?
const neededCount = pageSize - hiddenItems.length;
if (neededCount <= 0) {
// skip loading more records?
if (remainingHiddenItems > pageSize) {
enableLoadMoreBtn(btn);
return; // skip loading more records
return;
}

// AJAX load more records
// should fire when we have only have one page of items left
const url = new URL(decodeURIComponent(btn.dataset.href), location.origin);
fetch(url.toString() + "&layout=lightbox")
.then((res) => res.text())
Expand All @@ -216,26 +221,29 @@ VuFind.register("channels", function Channels() {
? firstChannel.querySelectorAll(".channel-item")
: [];

if (records.length === 0) {
hideLoadMoreBtn(btn);
return;
}

const targetList = targetChannel.querySelector(".channel-list");
let index = Number(targetChannel.dataset.loaded);
targetChannel.dataset.loaded = index + records.length;
for (let i = 0; i < records.length; i++) {
const record = records[i];
record.dataset.index = index++;

record.classList.remove("hidden");
if (i >= neededCount) {
record.classList.add("hidden-batch-item");
}
record.classList.add("hidden-batch-item");
targetList.append(record);

clampLines(record.querySelector(".channel-item-title"));
}

// Hide button
if (records.length < Number(targetChannel.dataset.batchSize)) {
hideLoadMoreBtn(btn);
} else {
enableLoadMoreBtn(btn);
}
enableLoadMoreBtn(btn);
});

// Set button to next, next page
// Set button to next page
url.searchParams.set("page", Number(url.searchParams.get("page")) + 1);
btn.setAttribute("data-href", url.toString());
}
Expand Down Expand Up @@ -280,7 +288,7 @@ VuFind.register("channels", function Channels() {
.setAttribute("href", `${VuFind.path}/Channels/Record?${expandParams}`);

const prevBtn = content.querySelector(".ql-prev-item-btn");
if (record.previousElementSibling) {
if (Number(record.dataset.index) > 0) {
prevBtn.classList.remove("disabled");
prevBtn.removeAttribute("disabled");
} else {
Expand Down Expand Up @@ -345,6 +353,7 @@ VuFind.register("channels", function Channels() {
for (const channelEl of document.querySelectorAll(".channel")) {
// Disable the load more button is there are less items than the batchSize
const allItems = channelEl.querySelectorAll(".channel-item");
channelEl.dataset.loaded = allItems.length;
if (allItems.length < Number(channelEl.dataset.rowSize)) {
hideLoadMoreBtn(channelEl.querySelector(".channel-load-more-btn"));
}
Expand Down Expand Up @@ -403,7 +412,7 @@ VuFind.register("channels", function Channels() {
group.dataset.recordSource,
group.dataset.recordId
);
if (record.previousElementSibling) {
if (Number(record.dataset.index) > 0) {
quickLook(record.previousElementSibling, group.dataset.channelId);
event.preventDefault();
return false;
Expand Down
14 changes: 8 additions & 6 deletions themes/bootstrap5/templates/channels/channelList.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@
$url = empty($item['routeDetails'])
? $this->recordLinker()->getUrl("{$item['source']}|{$item['id']}")
: $this->url($item['routeDetails']['route'], $item['routeDetails']['params']);
$channelItemAttrs = [
'class' => 'channel-item' . ($index < $channel['config']['pageSize'] ? '' : ' hidden-batch-item'),
'data-channel-id' => $channelID,
'data-index' => $index,
'data-record-id' => $item['id'],
'data-record-source' => $item['source'],
];
?>
<li
class="channel-item <?=$index < $channel['config']['pageSize'] ? '' : 'hidden-batch-item' ?>"
data-channel-id="<?=$this->escapeHtmlAttr($channelID)?>"
data-record-id="<?=$this->escapeHtmlAttr($item['id']) ?>"
data-record-source="<?=$this->escapeHtmlAttr($item['source']) ?>"
>
<li<?=$this->htmlAttributes($channelItemAttrs) ?>>
<div class="channel-item-thumb">
<img
class="channel-item-img"
Expand Down
Loading