Lighten the "More" button handler when checks are not necessary
This commit is contained in:
parent
8d255fc331
commit
dbabdd83dc
@ -254,8 +254,6 @@ $(function() {
|
|||||||
if (!keepSidebarOpen && $(window).outerWidth() < utils.mobileViewportPixels) {
|
if (!keepSidebarOpen && $(window).outerWidth() < utils.mobileViewportPixels) {
|
||||||
slideoutMenu.toggle(false);
|
slideoutMenu.toggle(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.togglePreviewMoreButtonsIfNeeded();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const lastActive = $("#windows > .active");
|
const lastActive = $("#windows > .active");
|
||||||
@ -281,6 +279,8 @@ $(function() {
|
|||||||
.addClass("active")
|
.addClass("active")
|
||||||
.trigger("show");
|
.trigger("show");
|
||||||
|
|
||||||
|
utils.togglePreviewMoreButtonsIfNeeded();
|
||||||
|
|
||||||
let title = $(document.body).data("app-name");
|
let title = $(document.body).data("app-name");
|
||||||
const chanTitle = chan.attr("aria-label");
|
const chanTitle = chan.attr("aria-label");
|
||||||
|
|
||||||
|
@ -72,11 +72,11 @@ function appendPreview(preview, msg, template) {
|
|||||||
const moreBtn = previewContainer.find(".more");
|
const moreBtn = previewContainer.find(".more");
|
||||||
const previewContent = previewContainer.find(".toggle-content");
|
const previewContent = previewContainer.find(".toggle-content");
|
||||||
|
|
||||||
|
// Depending on the size of the preview and the text within it, show or hide a
|
||||||
|
// "More" button that allows users to expand without having to open the link.
|
||||||
|
// Warning: Make sure to call this only on active channel, link previews only,
|
||||||
|
// expanded only.
|
||||||
const showMoreIfNeeded = () => {
|
const showMoreIfNeeded = () => {
|
||||||
// Only applies on previews:
|
|
||||||
if (channel.hasClass("active") && // in the current channel
|
|
||||||
previewContent.hasClass("show") // that are expanded
|
|
||||||
) {
|
|
||||||
const isVisible = moreBtn.is(":visible");
|
const isVisible = moreBtn.is(":visible");
|
||||||
const shouldShow = previewContent[0].offsetWidth >= previewContainer[0].offsetWidth;
|
const shouldShow = previewContent[0].offsetWidth >= previewContainer[0].offsetWidth;
|
||||||
|
|
||||||
@ -86,18 +86,30 @@ function appendPreview(preview, msg, template) {
|
|||||||
togglePreviewMore(moreBtn, false);
|
togglePreviewMore(moreBtn, false);
|
||||||
moreBtn.hide();
|
moreBtn.hide();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// "More" button only applies on text previews
|
||||||
if (preview.type === "link") {
|
if (preview.type === "link") {
|
||||||
$(window).on("resize", debounce(showMoreIfNeeded, 150));
|
// On resize, only touch previews in the current channel that are expanded
|
||||||
window.requestAnimationFrame(showMoreIfNeeded);
|
$(window).on("resize", debounce(() => {
|
||||||
|
if (channel.hasClass("active") && previewContent.hasClass("show")) {
|
||||||
|
showMoreIfNeeded();
|
||||||
|
}
|
||||||
|
}, 150));
|
||||||
|
|
||||||
|
// This event is triggered when a side menu is opened/closed, or when the
|
||||||
|
// preview gets expanded/collapsed.
|
||||||
previewContent.on("showMoreIfNeeded",
|
previewContent.on("showMoreIfNeeded",
|
||||||
() => window.requestAnimationFrame(showMoreIfNeeded)
|
() => window.requestAnimationFrame(showMoreIfNeeded)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activeChannelId === channelId) {
|
if (activeChannelId === channelId) {
|
||||||
|
// If this preview is in active channel, hide "More" button if necessary
|
||||||
|
if (preview.type === "link") {
|
||||||
|
window.requestAnimationFrame(showMoreIfNeeded);
|
||||||
|
}
|
||||||
|
|
||||||
container.trigger("keepToBottom");
|
container.trigger("keepToBottom");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user