Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-30269: [Content Tree] Collapse all button jumps a little bit when scrolling #888

Merged
Changes from all 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
15 changes: 6 additions & 9 deletions src/bundle/Resources/public/js/scripts/admin.content.tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
const KEY_CONTENT_TREE_EXPANDED = 'ez-content-tree-expanded';
const CLASS_CONTENT_TREE_EXPANDED = 'ez-content-tree-container--expanded';
const CLASS_BTN_CONTENT_TREE_EXPANDED = 'ez-btn--content-tree-expanded';
const VIEWPORT_CHANGE_TIMEOUT = 50;
const token = doc.querySelector('meta[name="CSRF-Token"]').content;
const siteaccess = doc.querySelector('meta[name="SiteAccess"]').content;
const contentTreeContainer = doc.querySelector('.ez-content-tree-container');
const contentTreeWrapper = doc.querySelector('.ez-content-tree-container__wrapper');
const btn = doc.querySelector('.ez-btn--toggle-content-tree');
const { currentLocationPath, userId, treeRootLocationId } = contentTreeContainer.dataset;
let onViewportChangeTimeout = null;
let frame = null;
const toggleContentTreePanel = () => {
contentTreeContainer.classList.toggle(CLASS_CONTENT_TREE_EXPANDED);
btn.classList.toggle(CLASS_BTN_CONTENT_TREE_EXPANDED);
Expand All @@ -23,15 +22,13 @@
const height = Math.min(window.innerHeight - contentTreeContainer.getBoundingClientRect().top, window.innerHeight);

contentTreeWrapper.style.height = `${height}px`;
onViewportChangeTimeout = null;
};
const handleViewportChange = () => {
if (onViewportChangeTimeout) {
return;
if (frame) {
cancelAnimationFrame(frame);
}

window.clearTimeout(onViewportChangeTimeout);
onViewportChangeTimeout = window.setTimeout(updateContentTreeWrapperHeight, VIEWPORT_CHANGE_TIMEOUT);
frame = requestAnimationFrame(updateContentTreeWrapperHeight);
};
const saveContentTreeExpandedState = (userId, isExpanded) => {
let expandedState = JSON.parse(localStorage.getItem(KEY_CONTENT_TREE_EXPANDED));
Expand Down Expand Up @@ -69,6 +66,6 @@

updateContentTreeWrapperHeight();

doc.addEventListener('scroll', handleViewportChange, false);
window.addEventListener('resize', handleViewportChange, false);
doc.addEventListener('scroll', handleViewportChange, { capture: false, passive: true });
window.addEventListener('resize', handleViewportChange, { capture: false, passive: true });
})(window.document, window.React, window.ReactDOM, window.eZ, window.localStorage);