Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong positioning of new comment popup on smaller screen sizes #1

Merged
merged 1 commit into from
Sep 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions static/js/newComment.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,32 @@ const insertNewCommentPopupIfDontExist = (comment, callback) => {
return $newComment;
};

// The variable position is an array consisting of x and y coordinates
const showNewCommentPopup = (position) => {
// position below comment icon
position = position || [];
let left = position[0];
if ($('.toolbar .addComment').length) {
left = $('.toolbar .addComment').offset().left;
}
const top = position[1];

const xPosition = position[0] || 0;
const yPosition = position[1] || 0;

// This code snippet prioritizes the position passed to the method.
// It ensures that it cannot go out of the right border of the padInnerElement.
const padInnerElement = $('iframe[name="ace_outer"]').contents().find('iframe[name="ace_inner"]');
const popupLeftPositionFromRightBorderOfPadInnerElement = padInnerElement.width() - $('#newComment').width();
const left = Math.max(
Math.min(
xPosition,
popupLeftPositionFromRightBorderOfPadInnerElement,
),
xPosition
);
$newComment.css('left', left);

const top = yPosition;
if (left === position[0]) {
$newComment.css('top', top);
}

// Reset form to make sure it is all clear
$newComment.find('.suggestion-checkbox').prop('checked', false).trigger('change');
$newComment.find('textarea').val('');
Expand Down