Skip to content

Commit

Permalink
EZP-28773: [v2] Issues with page scrolling during actions in rich tex…
Browse files Browse the repository at this point in the history
…t editor
  • Loading branch information
konradoboza committed Jan 16, 2019
1 parent 8aaa9c5 commit 5012691
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/bundle/Resources/public/js/alloyeditor/dist/ezBtnEmbed.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/bundle/Resources/public/js/alloyeditor/dist/ezBtnImage.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ export default class EzBtnEmbed extends EzEmbedDiscoverContentButton {
addEmbed(items) {
const contentInfo = items[0].ContentInfo.Content._id;

this.execCommand();
if (navigator.userAgent.indexOf('Chrome') > -1) {
const scrollY = window.pageYOffset;
this.execCommand();
window.scroll(window.pageXOffset, scrollY);
} else {
this.execCommand();
}
this.setContentInfo(contentInfo);

const widget = this.getWidget();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@ export default class EzBtnImage extends EzEmbedImageButton {
addImage(items) {
const content = items[0].ContentInfo.Content;

this.execCommand();
if (navigator.userAgent.indexOf('Chrome') > -1) {
const scrollY = window.pageYOffset;
this.execCommand();
window.scroll(window.pageXOffset, scrollY);
} else {
this.execCommand();
}

this.setContentInfo(content._id);

const widget = this.getWidget()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export default class EzBtnLinkEdit extends Component {
this.state.element.setAttribute(
'href', 'ezlocation://' + items[0].id
);
this.focusEditedLink();
this.invokeWithFixedScrollbar(() => {
this.focusEditedLink();
});

ReactDOM.unmountComponentAtNode(udwContainer);
};
Expand Down Expand Up @@ -299,7 +301,10 @@ export default class EzBtnLinkEdit extends Component {
} else if (event.keyCode === 27) {
const editor = this.props.editor.get('nativeEditor');
new CKEDITOR.Link(editor).advanceSelection();
editor.fire('actionPerformed', this);

this.invokeWithFixedScrollbar(() => {
editor.fire('actionPerformed', this);
});
}
}

Expand Down Expand Up @@ -351,7 +356,9 @@ export default class EzBtnLinkEdit extends Component {

this.props.cancelExclusive();

editor.fire('actionPerformed', this);
this.invokeWithFixedScrollbar(() => {
editor.fire('actionPerformed', this);
});
}

/**
Expand Down Expand Up @@ -386,14 +393,33 @@ export default class EzBtnLinkEdit extends Component {
linkAttrs.href = this.state.linkHref;
linkUtils.update(linkAttrs, this.state.element, modifySelection);

editor.fire('actionPerformed', this);
this.invokeWithFixedScrollbar(() => {
editor.fire('actionPerformed', this);
});
}

// We need to cancelExclusive with the bound parameters in case the
// button is used inside another component in exclusive mode (such
// is the case of the link button)
this.props.cancelExclusive();
}

/**
* Saves current scrollbar position, invokes callback function and scrolls
* to the saved position afterward.
*
* @method invokeWithFixedScrollbar
* @param {Function} callback invoked after saving current scrollbar position
*/
invokeWithFixedScrollbar(callback) {
if (navigator.userAgent.indexOf('Chrome') > -1) {
const scrollY = window.pageYOffset;
callback();
window.scroll(window.pageXOffset, scrollY);
} else {
callback();
}
}
}

AlloyEditor.Buttons[EzBtnLinkEdit.key] = AlloyEditor.ButtonLinkEdit = EzBtnLinkEdit;

0 comments on commit 5012691

Please sign in to comment.