Skip to content

Commit 5d0d821

Browse files
authored
[BUGFIX] Dynamically add a spacer to the top of the page (#729)
This spacer is needed if there's not enough space between the top of the page and the first editable element to allow the inline actions toolbar of this first editable CE to be visible. Without the spacer, in this use case, the inline actions toolbar is hidden under the module doc header. The code must be placed in .on('load') of inline_editing.css so the inline actions toolbar has its style applied and its height and position can be retrieved correctly. Resolves: #728
1 parent e4740b6 commit 5d0d821

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

Resources/Public/JavaScript/Editor.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,27 @@ define([
9393
href: resourcePath + 'Css/inline_editing.css',
9494
type: 'text/css'
9595
}
96-
)
96+
).on('load', function () {
97+
// Dinamically add a spacer if the inline actions toolbar is hidden under the module doc header
98+
// this could happen if there's not enough space between the top of the page and the first editable element
99+
const feIframe = document.getElementById('tx_frontendediting_iframe');
100+
const iframeDocument = feIframe.contentDocument;
101+
const firstInlineActionsToolbar = iframeDocument.querySelector('.t3-frontend-editing__inline-actions');
102+
if (firstInlineActionsToolbar) {
103+
firstInlineActionsToolbar.style.display = 'block'; // Tmp set display block or else the toolbar has height=0
104+
const toolbarTopYPosition = window.pageYOffset + firstInlineActionsToolbar.getBoundingClientRect().top;
105+
const toolbarHeight = firstInlineActionsToolbar.offsetHeight;
106+
firstInlineActionsToolbar.style.display = 'none'; // Reset toolbar display to none
107+
if (toolbarTopYPosition < toolbarHeight) {
108+
// Create a spacer element
109+
const spacer = iframeDocument.createElement('div');
110+
spacer.classList.add('t3-frontend-editing__spacer');
111+
spacer.style.height = -toolbarTopYPosition + 'px';
112+
// Insert the spacer as the first element inside the body of the iframe
113+
iframeDocument.body.insertBefore(spacer, iframeDocument.body.firstChild);
114+
}
115+
}
116+
})
97117
);
98118

99119
// Links in editable CE are not navigable directly on click.

0 commit comments

Comments
 (0)