Skip to content

Commit

Permalink
Fix tooltip init after review (go-gitea#20814)
Browse files Browse the repository at this point in the history
* Fix tooltip init after review

Previous code passed a jQuery collection which initTooltip couldn't
handle. Instead, iterate the individial matched elements and add a
dollar to the variable name to make it clear it's jQuery.

Fixes: go-gitea#20809
  • Loading branch information
silverwind authored and Sysoev, Vladimir committed Aug 28, 2022
1 parent a5697ca commit 9f26437
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions web_src/js/features/repo-diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,28 @@ export function initRepoDiffConversationForm() {
$(document).on('submit', '.conversation-holder form', async (e) => {
e.preventDefault();

const form = $(e.target);
const $textArea = form.find('textarea');
const $form = $(e.target);
const $textArea = $form.find('textarea');
if (!validateTextareaNonEmpty($textArea)) {
return;
}

const newConversationHolder = $(await $.post(form.attr('action'), form.serialize()));
const {path, side, idx} = newConversationHolder.data();
const formDataString = String(new URLSearchParams(new FormData($form[0])));
const $newConversationHolder = $(await $.post($form.attr('action'), formDataString));
const {path, side, idx} = $newConversationHolder.data();

initTooltip(newConversationHolder.find('.tooltip'));
form.closest('.conversation-holder').replaceWith(newConversationHolder);
if (form.closest('tr').data('line-type') === 'same') {
$newConversationHolder.find('.tooltip').each(function () {
initTooltip(this);
});

$form.closest('.conversation-holder').replaceWith($newConversationHolder);
if ($form.closest('tr').data('line-type') === 'same') {
$(`[data-path="${path}"] a.add-code-comment[data-idx="${idx}"]`).addClass('invisible');
} else {
$(`[data-path="${path}"] a.add-code-comment[data-side="${side}"][data-idx="${idx}"]`).addClass('invisible');
}
newConversationHolder.find('.dropdown').dropdown();
initCompReactionSelector(newConversationHolder);
$newConversationHolder.find('.dropdown').dropdown();
initCompReactionSelector($newConversationHolder);
});


Expand Down

0 comments on commit 9f26437

Please sign in to comment.