mirror of
https://github.com/thelounge/thelounge
synced 2024-11-26 05:50:22 +00:00
Implement infinite scroll using IntersectionObserver
This commit is contained in:
parent
72a534f42b
commit
629592d641
1 changed files with 25 additions and 0 deletions
|
@ -12,6 +12,11 @@ const condensed = require("./condensed");
|
|||
const chat = $("#chat");
|
||||
const sidebar = $("#sidebar");
|
||||
|
||||
const historyObserver = window.IntersectionObserver ?
|
||||
new window.IntersectionObserver(loadMoreHistory, {
|
||||
root: chat.get(0)
|
||||
}) : null;
|
||||
|
||||
module.exports = {
|
||||
appendMessage,
|
||||
buildChannelMessages,
|
||||
|
@ -145,6 +150,10 @@ function renderChannel(data) {
|
|||
if (data.type === "channel") {
|
||||
renderChannelUsers(data);
|
||||
}
|
||||
|
||||
if (historyObserver) {
|
||||
historyObserver.observe(chat.find("#chan-" + data.id + " .show-more").get(0));
|
||||
}
|
||||
}
|
||||
|
||||
function renderChannelMessages(data) {
|
||||
|
@ -220,3 +229,19 @@ function renderNetworks(data) {
|
|||
utils.toggleNotificationMarkers(true);
|
||||
}
|
||||
}
|
||||
|
||||
function loadMoreHistory(entries) {
|
||||
entries.forEach((entry) => {
|
||||
if (!entry.isIntersecting) {
|
||||
return;
|
||||
}
|
||||
|
||||
var target = $(entry.target).find(".show-more-button");
|
||||
|
||||
if (target.attr("disabled")) {
|
||||
return;
|
||||
}
|
||||
|
||||
target.click();
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue