From 7c8e2f990dea8aa4628e8cf5afdad77a34f2a9a8 Mon Sep 17 00:00:00 2001 From: fredtempez Date: Mon, 11 Mar 2019 16:56:56 +0100 Subject: [PATCH] [9.0.05.dev.a] Tinymce toolbar sticked under admin bar --- core/vendor/tinymce/init.js | 80 ++++++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/core/vendor/tinymce/init.js b/core/vendor/tinymce/init.js index 9ce60017..996c4f93 100755 --- a/core/vendor/tinymce/init.js +++ b/core/vendor/tinymce/init.js @@ -140,4 +140,82 @@ tinymce.init({ description: "Grille adaptative sur 12 colonnes, sur mobile elles passent les unes en dessous des autres." } ] -}); \ No newline at end of file +}); + + +tinymce.PluginManager.add('stickytoolbar', function(editor, url) { + editor.on('init', function() { + setSticky(); + }); + + $(window).on('scroll', function() { + setSticky(); + }); + + function setSticky() { + var container = editor.editorContainer; + var toolbars = $(container).find('.mce-toolbar-grp'); + var statusbar = $(container).find('.mce-statusbar'); + + if (isSticky()) { + $(container).css({ + paddingTop: toolbars.outerHeight() + }); + + if (isAtBottom()) { + toolbars.css({ + top: 'auto', + bottom: statusbar.outerHeight(), + position: 'absolute', + width: '100%', + borderBottom: 'none' + }); + } else { + toolbars.css({ + top: 45, + bottom: 'auto', + position: 'fixed', + width: $(container).width(), + borderBottom: '1px solid rgba(0,0,0,0.2)' + }); + } + } else { + $(container).css({ + paddingTop: 0 + }); + + toolbars.css({ + position: 'relative', + width: 'auto', + borderBottom: 'none' + }); + } + } + + function isSticky() { + var container = editor.editorContainer, + editorTop = container.getBoundingClientRect().top; + + if (editorTop < 0) { + return true; + } + + return false; + } + + function isAtBottom() { + var container = editor.editorContainer, + editorTop = container.getBoundingClientRect().top; + + var toolbarHeight = $(container).find('.mce-toolbar-grp').outerHeight(); + var footerHeight = $(container).find('.mce-statusbar').outerHeight(); + + var hiddenHeight = -($(container).outerHeight() - toolbarHeight - footerHeight); + + if (editorTop < hiddenHeight) { + return true; + } + + return false; + } + }); \ No newline at end of file