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

IBX-8837: Distraction free mode: Text obstruction by toolbar's fixed position #1361

Open
wants to merge 1 commit into
base: 4.6
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
(function (global, doc) {
let activeFieldEdit = null;
let clearedPositionNodesData = [];
const DISTRACTION_FREE_MODE_ENABLE_EVENT_NAME = 'ibexa-distraction-free:enable';
const DISTRACTION_FREE_DISABLE_EVENT_NAME = 'ibexa-distraction-free:disable';
const distractionFreeModeEnableBtns = doc.querySelectorAll('.ibexa-field-edit__distraction-free-mode-control-btn--enable');
Expand All @@ -16,6 +17,43 @@
activeFieldEdit.classList.toggle('ibexa-field-edit--distraction-free-mode-active', active);
editorInstance.set('distractionFreeModeActive', active);

if (active) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we safeguard the possibility of calling changeDistractionFreeModeState two times in a row with the same active parameter value by e.g. checking whether clearedPositionNodesData is not empty?

let parentElement = activeFieldEdit.parentNode;

while (parentElement && parentElement !== doc.body) {
Copy link
Contributor

@tischsoic tischsoic Oct 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this new fragment may be more readable if split into two functions e.g. resetAncestorsPositions(), restoreAncestorsPositions()

const { overflow, position } = getComputedStyle(parentElement);

if (overflow !== 'visible' || position === 'absolute') {
clearedPositionNodesData.push({
node: parentElement,
originalInlineOverflow: parentElement.style.overflow,
originalInlinePosition: parentElement.style.position,
});

parentElement.style.overflow = 'visible';
parentElement.style.position = 'static';
}

parentElement = parentElement.parentNode;
}
} else {
clearedPositionNodesData.forEach(({ node, originalInlineOverflow, originalInlinePosition }) => {
if (originalInlineOverflow) {
node.style.overflow = originalInlineOverflow;
} else {
node.style.removeProperty('overflow');
}

if (originalInlinePosition) {
node.style.position = originalInlinePosition;
} else {
node.style.removeProperty('position');
}
});

clearedPositionNodesData = [];
}

doc.body.dispatchEvent(
new CustomEvent(dispatchEventName, {
detail: {
Expand Down
Loading