From 6d835b69a024c78e2a1f9b1ed39a3c580733c79a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20W=C3=B3js?= Date: Fri, 17 Nov 2017 11:49:01 +0100 Subject: [PATCH] EZP-28078: Embedding a Content Object in the RichText Editor makes page scroll up (#920) * Fix EZP-28078: Embedding a Content Object in the RichText Editor makes page scroll up * fixup! Fix EZP-28078: Embedding a Content Object in the RichText Editor makes page scroll up * fixup! Fix EZP-28078: Embedding a Content Object in the RichText Editor makes page scroll up * fixup! Fix EZP-28078: Embedding a Content Object in the RichText Editor makes page scroll up --- Resources/public/js/alloyeditor/buttons/embed.js | 13 +++++++++++-- Resources/public/js/alloyeditor/buttons/embed.jsx | 13 +++++++++++-- Resources/public/js/alloyeditor/buttons/image.js | 13 +++++++++++-- Resources/public/js/alloyeditor/buttons/image.jsx | 13 +++++++++++-- Resources/public/js/alloyeditor/buttons/linkedit.js | 13 +++++++++++-- .../public/js/alloyeditor/buttons/linkedit.jsx | 13 +++++++++++-- 6 files changed, 66 insertions(+), 12 deletions(-) diff --git a/Resources/public/js/alloyeditor/buttons/embed.js b/Resources/public/js/alloyeditor/buttons/embed.js index 5e71e3c41..2ce7b751f 100644 --- a/Resources/public/js/alloyeditor/buttons/embed.js +++ b/Resources/public/js/alloyeditor/buttons/embed.js @@ -75,9 +75,18 @@ YUI.add('ez-alloyeditor-button-embed', function (Y) { */ _addEmbed: function (e) { var contentInfo = e.selection.contentInfo, - widget; + widget, + scrollY; + + if (navigator.userAgent.indexOf('Chrome') > -1) { + // Workaround for https://jira.ez.no/browse/EZP-28078 + scrollY = window.pageYOffset; + this.execCommand(); + window.scroll(window.pageXOffset, scrollY); + } else { + this.execCommand(); + } - this.execCommand(); this._setContentInfo(contentInfo); widget = this._getWidget().setWidgetContent(''); this._fireUpdatedEmbed(e.selection); diff --git a/Resources/public/js/alloyeditor/buttons/embed.jsx b/Resources/public/js/alloyeditor/buttons/embed.jsx index ec1113322..e02445f21 100644 --- a/Resources/public/js/alloyeditor/buttons/embed.jsx +++ b/Resources/public/js/alloyeditor/buttons/embed.jsx @@ -70,9 +70,18 @@ YUI.add('ez-alloyeditor-button-embed', function (Y) { */ _addEmbed: function (e) { var contentInfo = e.selection.contentInfo, - widget; + widget, + scrollY; + + if (navigator.userAgent.indexOf('Chrome') > -1) { + // Workaround for https://jira.ez.no/browse/EZP-28078 + scrollY = window.pageYOffset; + this.execCommand(); + window.scroll(window.pageXOffset, scrollY); + } else { + this.execCommand(); + } - this.execCommand(); this._setContentInfo(contentInfo); widget = this._getWidget().setWidgetContent(''); this._fireUpdatedEmbed(e.selection); diff --git a/Resources/public/js/alloyeditor/buttons/image.js b/Resources/public/js/alloyeditor/buttons/image.js index 22650693b..897d20211 100644 --- a/Resources/public/js/alloyeditor/buttons/image.js +++ b/Resources/public/js/alloyeditor/buttons/image.js @@ -78,9 +78,18 @@ YUI.add('ez-alloyeditor-button-image', function (Y) { * @protected */ _addImage: function (e) { - var widget; + var widget, + scrollY; + + if (navigator.userAgent.indexOf('Chrome') > -1) { + // Workaround for https://jira.ez.no/browse/EZP-28078 + scrollY = window.pageYOffset; + this.execCommand(); + window.scroll(window.pageXOffset, scrollY); + } else { + this.execCommand(); + } - this.execCommand(); this._setContentInfo(e.selection.contentInfo); widget = this._getWidget() diff --git a/Resources/public/js/alloyeditor/buttons/image.jsx b/Resources/public/js/alloyeditor/buttons/image.jsx index dde9aff7c..c2b332ee5 100644 --- a/Resources/public/js/alloyeditor/buttons/image.jsx +++ b/Resources/public/js/alloyeditor/buttons/image.jsx @@ -73,9 +73,18 @@ YUI.add('ez-alloyeditor-button-image', function (Y) { * @protected */ _addImage: function (e) { - var widget; + var widget, + scrollY; + + if (navigator.userAgent.indexOf('Chrome') > -1) { + // Workaround for https://jira.ez.no/browse/EZP-28078 + scrollY = window.pageYOffset; + this.execCommand(); + window.scroll(window.pageXOffset, scrollY); + } else { + this.execCommand(); + } - this.execCommand(); this._setContentInfo(e.selection.contentInfo); widget = this._getWidget() diff --git a/Resources/public/js/alloyeditor/buttons/linkedit.js b/Resources/public/js/alloyeditor/buttons/linkedit.js index 11a7b0191..f3b789d01 100644 --- a/Resources/public/js/alloyeditor/buttons/linkedit.js +++ b/Resources/public/js/alloyeditor/buttons/linkedit.js @@ -126,9 +126,18 @@ YUI.add('ez-alloyeditor-button-linkedit', function (Y) { * @protected */ _focusEditedLink: function () { - var editor = this.props.editor.get('nativeEditor'); + var editor = this.props.editor.get('nativeEditor'), + scrollY; + + if (navigator.userAgent.indexOf('Chrome') > -1) { + // Workaround for https://jira.ez.no/browse/EZP-28078 + scrollY = window.pageYOffset; + editor.focus(); + window.scroll(window.pageXOffset, scrollY); + } else { + editor.focus(); + } - editor.focus(); editor.eZ.moveCaretToElement(editor, this.state.element); editor.fire('actionPerformed', this); }, diff --git a/Resources/public/js/alloyeditor/buttons/linkedit.jsx b/Resources/public/js/alloyeditor/buttons/linkedit.jsx index 748c839b9..769be76af 100644 --- a/Resources/public/js/alloyeditor/buttons/linkedit.jsx +++ b/Resources/public/js/alloyeditor/buttons/linkedit.jsx @@ -121,9 +121,18 @@ YUI.add('ez-alloyeditor-button-linkedit', function (Y) { * @protected */ _focusEditedLink: function () { - var editor = this.props.editor.get('nativeEditor'); + var editor = this.props.editor.get('nativeEditor'), + scrollY; + + if (navigator.userAgent.indexOf('Chrome') > -1) { + // Workaround for https://jira.ez.no/browse/EZP-28078 + scrollY = window.pageYOffset; + editor.focus(); + window.scroll(window.pageXOffset, scrollY); + } else { + editor.focus(); + } - editor.focus(); editor.eZ.moveCaretToElement(editor, this.state.element); editor.fire('actionPerformed', this); },