(function ($) { $(document).on('submit', '.post_comment_form', function () { const $form = $(this); startAddComment($form); if (!Joyreactor.api_auth) { // disable old form as joyreactor.com migrated return false; } // submit via api let text = $form.find('textarea').val(); const pictureUrl = $form.find('input[name="comment_picture_url"]').val(); if (pictureUrl) { text += `` } const postId = parseInt($form.find('input[name="post_id"]').val()); const parentId = parseInt($form.find('input[name="parent_id"]').val()); const data = { query: "mutation CommentFormMutation($id: ID!, $text: String!, $files: [Upload!]) {" + " comment (id: $id, text: $text, files: $files ) {" + " comment {" + " id" + " }" + " }" + "}", variables: { text: text, id: btoa(parentId ? `Comment:${parentId}` : `Post:${postId}`) }, } const formData = new FormData(); formData.append( 'operations', JSON.stringify(data), ); const files = $form.find('input[name="comment_picture"]')[0].files; if (files.length) { formData.append('0', files[0]); formData.append('map', JSON.stringify({0: ['variables.files.0']})); } else { formData.append('map', JSON.stringify({})); } graphQLRequest( formData, function (data) { $form.show(); $form.parent().find('.comment_add_waiting').remove(); $form.find('input[type="submit"]').removeAttr("disabled"); if (data.data?.comment?.comment?.id) { // success const url = `/post/commentsPart/${postId}/${parentId}`; successAddComment(url, $form); return; } $form.find('.add_comment_flash').text(window.add_post_internal_error).show(); }, errorAddComment ); return false; }); // image from file/url buttons $(document).on('click', '.post_comment_form .more_file', function () { var parent = $(this).closest('.post_comment_form'); parent.find('.comment_picture').show(); parent.find('.comment_picture_url').hide(); parent.find('.more_url').show(); $(this).hide(); return false; }); $(document).on('click', '.post_comment_form .more_url', function () { var parent = $(this).closest('.post_comment_form'); parent.find('.comment_picture_url').show(); parent.find('.comment_picture').hide(); parent.find('.more_file').show(); $(this).hide(); return false; }); // ответ на коммент $(document).on('click', '.comment a.response', function () { var parent = $(this).closest('.comment'); // id=comment12345 var post = $(this).closest('.postContainer'); // id=postContainer180956 showAddComment(post.attr('id').substring(13), parent.attr('id').substring(7)); return false; }); $(document).on('click', '.add-comment-link a.response', function () { var parent = $(this).closest('.add-comment-link'); showAddComment(parent.attr('data-post-id'), 0); return false; }); function showAddComment(post_id, parent_id) { $("#comment_list_post_" + post_id + " .addcomment").hide("fast"); var div = $("#addcomment_post_" + post_id); div.find('.add_comment_flash').hide(); if (parent_id != 0) { var txtDiv = $("#comment" + parent_id); // for full version search inner div.txt var innerTxtDiv = txtDiv.find('div.txt'); if (innerTxtDiv.length > 0) { txtDiv = innerTxtDiv; } var commentDiv = txtDiv.find('div.addcomment'); if (commentDiv.length == 0) { txtDiv.append('
'); commentDiv = txtDiv.find('div.addcomment'); } if (!commentDiv.is(':has(form)')) { commentDiv.html(div.html()); commentDiv.find('input.parent_id').val(parent_id); commentDiv.find('input.token').val(window.token); commentDiv.find('textarea.comment_text, input.comment_picture_url, input.comment_picture').val(''); } div = commentDiv; } if (div.is(":visible")) { div.hide("fast"); txtDiv.removeClass('comFormOpened'); } else { div.show("fast") txtDiv.addClass('comFormOpened'); } } function startAddComment(jqForm) { jqForm.find('input[type="submit"]').attr("disabled", true); jqForm.hide(); jqForm.parent().append(window.loading_wait_code); } function errorAddComment() { var $div = $('.comment_add_waiting'); $div.parent().find('form').show(); $div.parent().find('form').find('input[type="submit"]').removeAttr("disabled"); $div.remove(); } function successAddComment(url, jqForm) { $('.addcomment').hide("fast"); $('.addcommentInline').hide("fast"); jqForm.find('textarea.comment_text, input.comment_picture_url, input.comment_picture').val(''); jqForm.find('.add_comment_flash').hide(); var post_id = jqForm.find('input.post_id').val(); var parent_id = jqForm.find('input.parent_id').val(); var $container = (parent_id != 0) ? $('#comment_list_comment_' + parent_id) : $('#comment_list_post_' + post_id); $container.load(url, function () { $(this).trigger('DOMUpdate'); }); } function showLoginDialog() { $('#SignInOrSignUpDialog').dialog({ draggable: false, modal: true, resizable: false }); } function escapeHtml(unsafe) { return unsafe .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); } })(jQuery);