Skip to content

Commit

Permalink
EZP-28953: Added debounce for updating position of the floating toolb…
Browse files Browse the repository at this point in the history
…ar on the scroll event (ezsystems#963)
  • Loading branch information
adamwojs authored and andrerom committed Apr 16, 2018
1 parent f12a75b commit 6795eab
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Resources/public/js/alloyeditor/plugins/floatingtoolbar.js
Expand Up @@ -11,7 +11,9 @@ YUI.add('ez-alloyeditor-plugin-floatingtoolbar', function (Y) {
}

var FLOATING_TOOLBAR_SELECTOR = '.ae-toolbar-floating',
FLOATING_TOOLBAR_FIXED_CLASS = 'ae-toolbar-floating-fixed';
FLOATING_TOOLBAR_FIXED_CLASS = 'ae-toolbar-floating-fixed',
SCROLL_HANDLER_DEBOUNCE_TIMEOUT = 100,
scrollHandler;

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

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

scrollHandler = CKEDITOR.tools.debounce(updateToolbarPosition, SCROLL_HANDLER_DEBOUNCE_TIMEOUT);

/**
* CKEditor plugin to handle pin/unpin the floating toolbars on scrolling in viewport.
*
Expand Down

0 comments on commit 6795eab

Please sign in to comment.