mirror of
https://github.com/glanceapp/glance.git
synced 2024-11-25 18:05:00 +01:00
Fix bug with collapsible grids inside of group widget
Also move utils to new file
This commit is contained in:
parent
d5fa6424c1
commit
b0c4d70628
@ -1,27 +1,5 @@
|
|||||||
import { setupPopovers } from './popover.js';
|
import { setupPopovers } from './popover.js';
|
||||||
|
import { throttledDebounce, isElementVisible } from './utils.js';
|
||||||
function throttledDebounce(callback, maxDebounceTimes, debounceDelay) {
|
|
||||||
let debounceTimeout;
|
|
||||||
let timesDebounced = 0;
|
|
||||||
|
|
||||||
return function () {
|
|
||||||
if (timesDebounced == maxDebounceTimes) {
|
|
||||||
clearTimeout(debounceTimeout);
|
|
||||||
timesDebounced = 0;
|
|
||||||
callback();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
clearTimeout(debounceTimeout);
|
|
||||||
timesDebounced++;
|
|
||||||
|
|
||||||
debounceTimeout = setTimeout(() => {
|
|
||||||
timesDebounced = 0;
|
|
||||||
callback();
|
|
||||||
}, debounceDelay);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
async function fetchPageContent(pageData) {
|
async function fetchPageContent(pageData) {
|
||||||
// TODO: handle non 200 status codes/time outs
|
// TODO: handle non 200 status codes/time outs
|
||||||
@ -427,7 +405,7 @@ function setupCollapsibleGrids() {
|
|||||||
|
|
||||||
const button = attachExpandToggleButton(gridElement);
|
const button = attachExpandToggleButton(gridElement);
|
||||||
|
|
||||||
let cardsPerRow = 2;
|
let cardsPerRow;
|
||||||
|
|
||||||
const resolveCollapsibleItems = () => {
|
const resolveCollapsibleItems = () => {
|
||||||
const hideItemsAfterIndex = cardsPerRow * collapseAfterRows;
|
const hideItemsAfterIndex = cardsPerRow * collapseAfterRows;
|
||||||
@ -457,12 +435,11 @@ function setupCollapsibleGrids() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
afterContentReady(() => {
|
const observer = new ResizeObserver(() => {
|
||||||
cardsPerRow = getCardsPerRow();
|
if (!isElementVisible(gridElement)) {
|
||||||
resolveCollapsibleItems();
|
return;
|
||||||
});
|
}
|
||||||
|
|
||||||
window.addEventListener("resize", () => {
|
|
||||||
const newCardsPerRow = getCardsPerRow();
|
const newCardsPerRow = getCardsPerRow();
|
||||||
|
|
||||||
if (cardsPerRow == newCardsPerRow) {
|
if (cardsPerRow == newCardsPerRow) {
|
||||||
@ -472,6 +449,8 @@ function setupCollapsibleGrids() {
|
|||||||
cardsPerRow = newCardsPerRow;
|
cardsPerRow = newCardsPerRow;
|
||||||
resolveCollapsibleItems();
|
resolveCollapsibleItems();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
afterContentReady(() => observer.observe(gridElement));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
25
internal/assets/static/js/utils.js
Normal file
25
internal/assets/static/js/utils.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
export function throttledDebounce(callback, maxDebounceTimes, debounceDelay) {
|
||||||
|
let debounceTimeout;
|
||||||
|
let timesDebounced = 0;
|
||||||
|
|
||||||
|
return function () {
|
||||||
|
if (timesDebounced == maxDebounceTimes) {
|
||||||
|
clearTimeout(debounceTimeout);
|
||||||
|
timesDebounced = 0;
|
||||||
|
callback();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearTimeout(debounceTimeout);
|
||||||
|
timesDebounced++;
|
||||||
|
|
||||||
|
debounceTimeout = setTimeout(() => {
|
||||||
|
timesDebounced = 0;
|
||||||
|
callback();
|
||||||
|
}, debounceDelay);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export function isElementVisible(element) {
|
||||||
|
return !!(element.offsetWidth || element.offsetHeight || element.getClientRects().length);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user