Skip to content

Commit a2f3ad7

Browse files
albozekpawlakadrian
authored andcommitted
After review
1 parent 1a107a0 commit a2f3ad7

File tree

3 files changed

+51
-57
lines changed

3 files changed

+51
-57
lines changed

src/bundle/Resources/public/js/scripts/admin.back.to.top.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(function (global, doc) {
1+
(function (global, doc, ibexa) {
22
const backToTopBtn = doc.querySelector('.ibexa-back-to-top__btn');
33
const backToTop = doc.querySelector('.ibexa-back-to-top');
44
const backToTopAnchor = doc.querySelector('.ibexa-back-to-top-anchor');
@@ -15,7 +15,6 @@
1515

1616
return backToTopBtn.classList.contains('ibexa-back-to-top__btn--visible');
1717
};
18-
1918
const backToTopBtnTitle = backToTopBtn.querySelector('.ibexa-back-to-top__title');
2019
let currentBackToTopAnchorHeight = backToTopAnchor.offsetHeight;
2120
const setBackToTopBtnTextVisibility = (container) => {
@@ -28,7 +27,7 @@
2827

2928
if (!backToTopBtn.classList.contains('ibexa-back-to-top__btn--visible') && shouldBeVisible) {
3029
backToTopBtn.classList.add('ibexa-back-to-top__btn--visible');
31-
global.ibexa.adminUiConfig.quickActionManager.recalculateButtonsLayout();
30+
ibexa.quickAction.recalculateButtonsLayout();
3231
}
3332

3433
backToTopBtn.classList.toggle('ibexa-btn--no-text', !isTitleVisible);
@@ -56,13 +55,13 @@
5655
setBackToTopBtnTextVisibility(backToTopScrollContainer);
5756
});
5857
const config = {
59-
name: 'back-to-top',
58+
id: 'back-to-top',
6059
zIndex: 10,
61-
selector: backToTop,
60+
container: backToTop,
6261
priority: 100,
6362
checkVisibility: checkIsVisible,
6463
};
6564

66-
global.ibexa.adminUiConfig.quickActionManager.registerButton(config);
65+
ibexa.quickAction.registerButton(config);
6766
resizeObserver.observe(backToTopAnchor);
68-
})(window, window.document);
67+
})(window, window.document, window.ibexa);
Lines changed: 44 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,49 @@
11
(function (global) {
2-
let registeredActionButtons = [];
2+
let actionButtonConfigs = [];
3+
4+
const registerButton = (config) => {
5+
if (!config || !config.container || actionButtonConfigs.some((btn) => btn.id === config.id)) {
6+
return;
7+
}
8+
9+
actionButtonConfigs = [...actionButtonConfigs, config].sort((a, b) => a.priority - b.priority);
10+
recalculateButtonsLayout();
11+
};
12+
const unregisterButton = (id) => {
13+
actionButtonConfigs = actionButtonConfigs.filter((btn) => btn.id !== id);
14+
recalculateButtonsLayout();
15+
};
16+
const recalculateButtonsLayout = () => {
17+
const buttonsToRender = actionButtonConfigs.filter((btn) => {
18+
if (typeof btn.checkVisibility === 'function') {
19+
const isVisible = btn.checkVisibility();
20+
21+
return isVisible;
22+
}
23+
24+
return false;
25+
});
26+
27+
buttonsToRender.forEach((buttonConfig, index) => {
28+
const { container } = buttonConfig;
329

4-
const QuickActionManager = (() => {
5-
const registerButton = (config) => {
6-
if (!config || !config.selector || registeredActionButtons.some((btn) => btn.name === config.name)) {
7-
return;
30+
if (!container.style.transition) {
31+
container.style.transition = 'all 0.3s ease-in-out';
832
}
933

10-
registeredActionButtons = [...registeredActionButtons, config];
11-
recalculateButtonsLayout();
12-
};
13-
const unregisterButton = (name) => {
14-
registeredActionButtons = registeredActionButtons.filter((btn) => btn.name !== name);
15-
recalculateButtonsLayout();
16-
};
17-
const recalculateButtonsLayout = () => {
18-
const sortedButtons = registeredActionButtons.sort((a, b) => a.priority - b.priority);
19-
const buttonsToRender = sortedButtons.filter((el) => {
20-
if (el.checkVisibility && typeof el.checkVisibility === 'function') {
21-
const isVisible = el.checkVisibility();
22-
23-
return isVisible;
24-
}
25-
26-
return false;
27-
});
28-
29-
buttonsToRender.forEach((buttonConfig, index) => {
30-
const { selector } = buttonConfig;
31-
32-
if (!selector.style.transition) {
33-
selector.style.transition = 'all 0.3s ease-in-out';
34-
}
35-
36-
selector.style.position = 'fixed';
37-
selector.style.right = '2rem';
38-
selector.style.zIndex = buttonConfig.zIndex || 1040;
39-
40-
const bottomPosition = `${index === 0 ? 2 : (index + 1) * 3.2}rem`;
41-
42-
selector.style.bottom = bottomPosition;
43-
});
44-
};
45-
46-
return {
47-
registerButton,
48-
unregisterButton,
49-
recalculateButtonsLayout,
50-
};
51-
})();
52-
53-
global.ibexa.adminUiConfig.quickActionManager = QuickActionManager;
34+
container.style.position = 'fixed';
35+
container.style.right = '2rem';
36+
container.style.zIndex = buttonConfig.zIndex || 1040;
37+
38+
const bottomPosition = `${index === 0 ? 2 : index * 3.8 + 2 + index * 0.5}rem`;
39+
40+
container.style.bottom = bottomPosition;
41+
});
42+
};
43+
44+
global.ibexa.quickAction = {
45+
registerButton,
46+
unregisterButton,
47+
recalculateButtonsLayout,
48+
};
5449
})(window);

src/bundle/Resources/views/themes/admin/ui/layout.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@
220220
<div class="ibexa-quick-action-menu">
221221
{% if not is_back_to_top_disabled|default(false) %}
222222
{% block back_to_top %}
223-
<div class="ibexa-back-to-top{{ is_back_to_top_disabled|default(false) ? ' ibexa-back-to-top--hidden' : '' }}">
223+
<div class="ibexa-back-to-top">
224224
<button type="button" class="btn ibexa-btn ibexa-btn--tertiary ibexa-btn--no-text ibexa-back-to-top__btn">
225225
<span class="ibexa-back-to-top__title">
226226
{{ 'back.to.top'|trans|desc('Go to top') }}

0 commit comments

Comments
 (0)