Skip to content
This repository was archived by the owner on May 3, 2022. It is now read-only.

Commit 6795eab

Browse files
adamwojsandrerom
authored andcommitted
EZP-28953: Added debounce for updating position of the floating toolbar on the scroll event (#963)
1 parent f12a75b commit 6795eab

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Resources/public/js/alloyeditor/plugins/floatingtoolbar.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ YUI.add('ez-alloyeditor-plugin-floatingtoolbar', function (Y) {
1111
}
1212

1313
var FLOATING_TOOLBAR_SELECTOR = '.ae-toolbar-floating',
14-
FLOATING_TOOLBAR_FIXED_CLASS = 'ae-toolbar-floating-fixed';
14+
FLOATING_TOOLBAR_FIXED_CLASS = 'ae-toolbar-floating-fixed',
15+
SCROLL_HANDLER_DEBOUNCE_TIMEOUT = 100,
16+
scrollHandler;
1517

1618
function findScrollParent(editor) {
1719
var container = editor.closest('.ez-main-content');
@@ -33,7 +35,7 @@ YUI.add('ez-alloyeditor-plugin-floatingtoolbar', function (Y) {
3335
return null;
3436
}
3537

36-
function scrollHandler () {
38+
function updateToolbarPosition() {
3739
var toolbar = document.querySelector(FLOATING_TOOLBAR_SELECTOR),
3840
editor = findFocusedEditor(),
3941
editorRect,
@@ -49,6 +51,8 @@ YUI.add('ez-alloyeditor-plugin-floatingtoolbar', function (Y) {
4951
toolbar.classList.toggle(FLOATING_TOOLBAR_FIXED_CLASS, editorRect.top < 0);
5052
}
5153

54+
scrollHandler = CKEDITOR.tools.debounce(updateToolbarPosition, SCROLL_HANDLER_DEBOUNCE_TIMEOUT);
55+
5256
/**
5357
* CKEditor plugin to handle pin/unpin the floating toolbars on scrolling in viewport.
5458
*

0 commit comments

Comments
 (0)