Skip to content

Commit

Permalink
EZP-28953: RichText editor's toolbox obscures the preceding paragraph…
Browse files Browse the repository at this point in the history
…'s content (ezsystems#962)

* EZP-28953: RichText editor's toolbox obscures the preceding paragraph's content

* fixup! EZP-28953: RichText editor's toolbox obscures the preceding paragraph's content

* fixup! EZP-28953: RichText editor's toolbox obscures the preceding paragraph's content

* fixup! EZP-28953: RichText editor's toolbox obscures the preceding paragraph's content

* fixup! EZP-28953: RichText editor's toolbox obscures the preceding paragraph's content

* fixup! EZP-28953: RichText editor's toolbox obscures the preceding paragraph's content

* fixup! EZP-28953: RichText editor's toolbox obscures the preceding paragraph's content

* fixup! EZP-28953: RichText editor's toolbox obscures the preceding paragraph's content

* fixup! EZP-28953: RichText editor's toolbox obscures the preceding paragraph's content

* fixup! EZP-28953: RichText editor's toolbox obscures the preceding paragraph's content
  • Loading branch information
adamwojs authored and andrerom committed Apr 16, 2018
1 parent ea19286 commit f12a75b
Show file tree
Hide file tree
Showing 13 changed files with 198 additions and 30 deletions.
11 changes: 9 additions & 2 deletions Resources/config/yui.yml
Expand Up @@ -30,11 +30,14 @@ system:
ez-alloyeditor-toolbar-config-block-base:
requires: ['ez-alloyeditor']
path: "%ez_platformui.public_dir%/js/alloyeditor/toolbars/config/block-base.js"
ez-alloyeditor-toolbar-config-block-floating-base:
requires: ['ez-alloyeditor']
path: "%ez_platformui.public_dir%/js/alloyeditor/toolbars/config/block-floating-base.js"
ez-alloyeditor-toolbar-config-heading:
requires: ['ez-alloyeditor', 'ez-alloyeditor-toolbar-config-block-base', 'ez-translator']
requires: ['ez-alloyeditor', 'ez-alloyeditor-toolbar-config-block-floating-base', 'ez-translator']
path: "%ez_platformui.public_dir%/js/alloyeditor/toolbars/config/heading.js"
ez-alloyeditor-toolbar-config-paragraph:
requires: ['ez-alloyeditor', 'ez-alloyeditor-toolbar-config-block-base', 'ez-translator']
requires: ['ez-alloyeditor', 'ez-alloyeditor-toolbar-config-block-floating-base', 'ez-translator']
path: "%ez_platformui.public_dir%/js/alloyeditor/toolbars/config/paragraph.js"
ez-alloyeditor-toolbar-config-embed:
requires: ['ez-alloyeditor', 'ez-alloyeditor-toolbar-config-block-base']
Expand Down Expand Up @@ -63,6 +66,9 @@ system:
ez-alloyeditor-plugin-focusblock:
requires: ['ez-alloyeditor']
path: "%ez_platformui.public_dir%/js/alloyeditor/plugins/focusblock.js"
ez-alloyeditor-plugin-floatingtoolbar:
requires: ['ez-alloyeditor']
path: "%ez_platformui.public_dir%/js/alloyeditor/plugins/floatingtoolbar.js"
ez-alloyeditor-plugin-paste:
requires: ['ez-alloyeditor']
path: "%ez_platformui.public_dir%/js/alloyeditor/plugins/paste.js"
Expand Down Expand Up @@ -932,6 +938,7 @@ system:
- 'ez-alloyeditor-plugin-removeblock'
- 'ez-alloyeditor-plugin-moveelement'
- 'ez-alloyeditor-plugin-focusblock'
- 'ez-alloyeditor-plugin-floatingtoolbar'
- 'ez-alloyeditor-plugin-paste'
- 'ez-alloyeditor-plugin-yui3'
- 'ez-alloyeditor-toolbar-ezadd'
Expand Down
22 changes: 20 additions & 2 deletions Resources/public/css/alloyeditor/general.css
Expand Up @@ -3,12 +3,30 @@
* For full copyright and license information view LICENSE file distributed with this source code.
*/

.ez-view-richtexteditview .ez-richtext-editor {
padding: 0 .5em;
}

.ae-toolbar-add,
.ae-toolbar,
.ae-toolbar-styles {
z-index: 1200;
}

.ae-ui .ae-arrow-box.ae-arrow-box-bottom.ez-ae-arrow-box-left:after {
left: -75%;
.ae-ui .ae-arrow-box:after {
display: none;
}

.ae-ui .ae-toolbar, .ae-ui [class^="ae-toolbar-"] {
margin-top: .3em;
padding: 0;
}

.ae-ui .ae-toolbar-styles {
margin-top: -.3em;
}

.ae-ui .ae-toolbar-floating-fixed {
position: fixed;
margin: .5em 0 0 .5em;
}
6 changes: 5 additions & 1 deletion Resources/public/css/theme/alloyeditor/general.css
Expand Up @@ -4,9 +4,13 @@
*/

[class*="ae-icon-"], [class*=" ae-icon-"] {
font-size: 18px;
font-size: 1.2em;
}

.ae-ui [class^=ae-toolbar] {
border: 1px solid #333;
}

.ae-ui .ae-toolbar-add .ae-button-add .ae-icon-add {
font-size: 1.2em;
}
65 changes: 65 additions & 0 deletions Resources/public/js/alloyeditor/plugins/floatingtoolbar.js
@@ -0,0 +1,65 @@
/*
* Copyright (C) eZ Systems AS. All rights reserved.
* For full copyright and license information view LICENSE file distributed with this source code.
*/
/* global CKEDITOR */
YUI.add('ez-alloyeditor-plugin-floatingtoolbar', function (Y) {
'use strict';

if (CKEDITOR.plugins.get('ezfloatingtoolbar')) {
return;
}

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

function findScrollParent(editor) {
var container = editor.closest('.ez-main-content');

if (window.getComputedStyle(container).getPropertyValue('overflow') === 'auto') {
return container;
}

return window;
}

function findFocusedEditor() {
for (var name in CKEDITOR.instances) {
if (CKEDITOR.instances[name].focusManager.hasFocus) {
return CKEDITOR.instances[name];
}
}

return null;
}

function scrollHandler () {
var toolbar = document.querySelector(FLOATING_TOOLBAR_SELECTOR),
editor = findFocusedEditor(),
editorRect,
top;

if (!toolbar || !editor) {
return;
}

editorRect = editor.element.getClientRect();
top = editorRect.top < 0 ? 0 : editorRect.top + editor.element.getWindow().getScrollPosition().y - toolbar.getBoundingClientRect().height;
toolbar.style.top = top + 'px';
toolbar.classList.toggle(FLOATING_TOOLBAR_FIXED_CLASS, editorRect.top < 0);
}

/**
* CKEditor plugin to handle pin/unpin the floating toolbars on scrolling in viewport.
*
* @class ezfloatingtoolbar
* @namespace CKEDITOR.plugins
* @constructor
*/
CKEDITOR.plugins.add('ezfloatingtoolbar', {
init: function (editor) {
findScrollParent(editor.element.$).addEventListener('scroll', scrollHandler);
},
});
});

@@ -0,0 +1,69 @@
/*
* Copyright (C) eZ Systems AS. All rights reserved.
* For full copyright and license information view LICENSE file distributed with this source code.
*/
/* global CKEDITOR */
YUI.add('ez-alloyeditor-toolbar-config-block-floating-base', function (Y) {
'use strict';
/**
* Provides base methods to toolbar dedicated to block element (heading,
* paragraph, ...).
*
* @module ez-alloyeditor-toolbar-config-block-floating-base
*/
Y.namespace('eZ.AlloyEditorToolbarConfig');

var ReactDOM = window.ReactDOM,
FLOATING_TOOLBAR_FIXED_CLASS = 'ae-toolbar-floating-fixed';

function setPositionFor (toolbar, block, editor) {
var editorRect = editor.element.getClientRect(),
top = editorRect.top < 0 ? 0 : editorRect.top + editor.element.getWindow().getScrollPosition().y - toolbar.getClientRect().height;

toolbar.setStyle('left', editorRect.left + 'px');
toolbar.setStyle('top', top + 'px');
toolbar[editorRect.top < 0 ? 'addClass' : 'removeClass'](FLOATING_TOOLBAR_FIXED_CLASS);

return true;
}

Y.eZ.AlloyEditorToolbarConfig.BlockFloatingBase = {
/**
* Returns the arrow box classes for the toolbar. The toolbar is
* always positioned above its related block and has a special class to
* move its tail on the left.
*
* @method getArrowBoxClasses
* @return {String}
*/
getArrowBoxClasses: function () {
return 'ae-toolbar-floating ae-arrow-box ae-arrow-box-bottom ez-ae-arrow-box-left';
},

/**
* Sets the position of the toolbar. It overrides the default styles
* toolbar positioning to position the toolbar just above its related
* block element. The related block element is the block indicated in
* CKEditor's path or the target of the editorEvent event.
*
* @method setPosition
* @param {Object} payload
* @param {AlloyEditor.Core} payload.editor
* @param {Object} payload.selectionData
* @param {Object} payload.editorEvent
* @return {Boolean} true if the method was able to position the
* toolbar
*/
setPosition: function (payload) {
var editor = payload.editor.get('nativeEditor'),
block = editor.elementPath().block,
toolbar = new CKEDITOR.dom.element(ReactDOM.findDOMNode(this));

if (!block) {
block = new CKEDITOR.dom.element(payload.editorEvent.data.nativeEvent.target);
}

return setPositionFor(toolbar, block, editor);
},
};
});
14 changes: 7 additions & 7 deletions Resources/public/js/alloyeditor/toolbars/config/heading.js
Expand Up @@ -11,7 +11,7 @@ YUI.add('ez-alloyeditor-toolbar-config-heading', function (Y) {
*/
Y.namespace('eZ.AlloyEditorToolbarConfig');

var BlockBase = Y.eZ.AlloyEditorToolbarConfig.BlockBase,
var BlockFloatingBase = Y.eZ.AlloyEditorToolbarConfig.BlockFloatingBase,
HeadingConfig,
name = 'heading',
getStyles = function () {
Expand Down Expand Up @@ -68,9 +68,9 @@ YUI.add('ez-alloyeditor-toolbar-config-heading', function (Y) {
);
};

this.getArrowBoxClasses = BlockBase.getArrowBoxClasses;
this.getArrowBoxClasses = BlockFloatingBase.getArrowBoxClasses;

this.setPosition = BlockBase.setPosition;
this.setPosition = BlockFloatingBase.setPosition;
};

/**
Expand All @@ -81,7 +81,7 @@ YUI.add('ez-alloyeditor-toolbar-config-heading', function (Y) {
* @namespace eZ.AlloyEditorToolbarConfig
* @class HeadingConfig
* @constructor
* @extends BlockBase
* @extends BlockFloatingBase
*/
Y.eZ.AlloyEditorToolbarConfig.HeadingConfig = HeadingConfig;

Expand All @@ -95,7 +95,7 @@ YUI.add('ez-alloyeditor-toolbar-config-heading', function (Y) {
* @namespace eZ.AlloyEditorToolbarConfig
* @class Heading
* @deprecated
* @extends BlockBase
* @extends BlockFloatingBase
*/
Y.eZ.AlloyEditorToolbarConfig.Heading = {
name: name,
Expand Down Expand Up @@ -133,8 +133,8 @@ YUI.add('ez-alloyeditor-toolbar-config-heading', function (Y) {
);
},

getArrowBoxClasses: BlockBase.getArrowBoxClasses,
getArrowBoxClasses: BlockFloatingBase.getArrowBoxClasses,

setPosition: BlockBase.setPosition,
setPosition: BlockFloatingBase.setPosition,
};
});
12 changes: 6 additions & 6 deletions Resources/public/js/alloyeditor/toolbars/config/paragraph.js
Expand Up @@ -11,7 +11,7 @@ YUI.add('ez-alloyeditor-toolbar-config-paragraph', function (Y) {
*/
Y.namespace('eZ.AlloyEditorToolbarConfig');

var BlockBase = Y.eZ.AlloyEditorToolbarConfig.BlockBase,
var BlockFloatingBase = Y.eZ.AlloyEditorToolbarConfig.BlockFloatingBase,
ParagraphConfig,
name = 'paragraph',
getStyles = function () {
Expand Down Expand Up @@ -68,9 +68,9 @@ YUI.add('ez-alloyeditor-toolbar-config-paragraph', function (Y) {
);
};

this.getArrowBoxClasses = BlockBase.getArrowBoxClasses;
this.getArrowBoxClasses = BlockFloatingBase.getArrowBoxClasses;

this.setPosition = BlockBase.setPosition;
this.setPosition = BlockFloatingBase.setPosition;
};

/*
Expand All @@ -95,7 +95,7 @@ YUI.add('ez-alloyeditor-toolbar-config-paragraph', function (Y) {
* @namespace eZ.AlloyEditorToolbarConfig
* @deprecated
* @class Paragraph
* @extends BlockBase
* @extends BlockFloatingBase
*/
Y.eZ.AlloyEditorToolbarConfig.Paragraph = {
name: name,
Expand Down Expand Up @@ -134,8 +134,8 @@ YUI.add('ez-alloyeditor-toolbar-config-paragraph', function (Y) {
);
},

getArrowBoxClasses: BlockBase.getArrowBoxClasses,
getArrowBoxClasses: BlockFloatingBase.getArrowBoxClasses,

setPosition: BlockBase.setPosition,
setPosition: BlockFloatingBase.setPosition,
};
});
2 changes: 1 addition & 1 deletion Resources/public/js/views/fields/ez-richtext-editview.js
Expand Up @@ -157,7 +157,7 @@ YUI.add('ez-richtext-editview', function (Y) {
var editor, nativeEd, valid, setEditorFocused, unsetEditorFocused,
extraPlugins = [
'ezaddcontent', 'widget', 'ezembed', 'ezremoveblock',
'ezfocusblock', 'yui3', 'ezpaste', 'ezmoveelement',
'ezfocusblock', 'ezfloatingtoolbar', 'yui3', 'ezpaste', 'ezmoveelement',
];

if (this.get('isNotTranslatable')) {
Expand Down
Expand Up @@ -4,16 +4,16 @@
*/
YUI.add('ez-alloyeditor-toolbar-config-heading-tests', function (Y) {
var defineTest, testTest,
BlockBase = Y.eZ.AlloyEditorToolbarConfig.BlockBase,
BlockFloatingBase = Y.eZ.AlloyEditorToolbarConfig.BlockFloatingBase,
Assert = Y.Assert, Mock = Y.Mock;

defineTest = new Y.Test.Case(Y.merge(Y.eZ.Test.ToolbarConfigDefineTest, {
name: 'eZ AlloyEditor heading config toolbar define test',
toolbarConfig: new Y.eZ.AlloyEditorToolbarConfig.HeadingConfig(),
toolbarConfigName: "heading",
methods: {
getArrowBoxClasses: BlockBase.getArrowBoxClasses,
setPosition: BlockBase.setPosition,
getArrowBoxClasses: BlockFloatingBase.getArrowBoxClasses,
setPosition: BlockFloatingBase.setPosition,
},

_should: {
Expand Down
Expand Up @@ -4,16 +4,16 @@
*/
YUI.add('ez-alloyeditor-toolbar-config-paragraph-tests', function (Y) {
var defineTest, testTest,
BlockBase = Y.eZ.AlloyEditorToolbarConfig.BlockBase,
BlockFloatingBase = Y.eZ.AlloyEditorToolbarConfig.BlockFloatingBase,
Assert = Y.Assert, Mock = Y.Mock;

defineTest = new Y.Test.Case(Y.merge(Y.eZ.Test.ToolbarConfigDefineTest, {
name: 'eZ AlloyEditor paragraph config toolbar define test',
toolbarConfig: new Y.eZ.AlloyEditorToolbarConfig.ParagraphConfig(),
toolbarConfigName: "paragraph",
methods: {
getArrowBoxClasses: BlockBase.getArrowBoxClasses,
setPosition: BlockBase.setPosition,
getArrowBoxClasses: BlockFloatingBase.getArrowBoxClasses,
setPosition: BlockFloatingBase.setPosition,
},

_should: {
Expand Down
Expand Up @@ -34,11 +34,11 @@
modules: {
"ez-alloyeditor-toolbar-config-heading": {
fullpath: "../../../../../Resources/public/js/alloyeditor/toolbars/config/heading.js",
requires: ['ez-alloyeditor', 'ez-alloyeditor-toolbar-config-block-base', 'ez-translator'],
requires: ['ez-alloyeditor', 'ez-alloyeditor-toolbar-config-block-floating-base', 'ez-translator'],
},
"ez-alloyeditor-toolbar-config-block-base": {
"ez-alloyeditor-toolbar-config-block-floating-base": {
requires: ['ez-alloyeditor'],
fullpath: "../../../../../Resources/public/js/alloyeditor/toolbars/config/block-base.js"
fullpath: "../../../../../Resources/public/js/alloyeditor/toolbars/config/block-floating-base.js"
},
"ez-alloyeditor": {
fullpath: "../../../../../Resources/public/js/external/ez-alloyeditor.js",
Expand Down
Expand Up @@ -34,11 +34,11 @@
modules: {
"ez-alloyeditor-toolbar-config-paragraph": {
fullpath: "../../../../../Resources/public/js/alloyeditor/toolbars/config/paragraph.js",
requires: ['ez-alloyeditor', 'ez-alloyeditor-toolbar-config-block-base', 'ez-translator'],
requires: ['ez-alloyeditor', 'ez-alloyeditor-toolbar-config-block-floating-base', 'ez-translator'],
},
"ez-alloyeditor-toolbar-config-block-base": {
requires: ['ez-alloyeditor'],
fullpath: "../../../../../Resources/public/js/alloyeditor/toolbars/config/block-base.js"
fullpath: "../../../../../Resources/public/js/alloyeditor/toolbars/config/block-floating-base.js"
},
"ez-alloyeditor": {
fullpath: "../../../../../Resources/public/js/external/ez-alloyeditor.js",
Expand Down

0 comments on commit f12a75b

Please sign in to comment.