diff --git a/class/comment.php b/class/comment.php
index 021b31e..a81e53e 100644
--- a/class/comment.php
+++ b/class/comment.php
@@ -319,6 +319,7 @@ function commentListShow($tpl_dir)
$row['can_edit'] = 1;
}
}
+ $row['is_my_own'] = $is_author;
// ------------------------------------------
$row['comment_published_raw'] = $row['comment_published'];
diff --git a/js/comment.js b/js/comment.js
index e0b7aa4..7c81dcc 100644
--- a/js/comment.js
+++ b/js/comment.js
@@ -36,7 +36,7 @@
});
}
- /* Limit Plugin (Исправленный с возвратом контекста) */
+ /* Limit Plugin */
$.fn.extend({
limit: function(limit, element) {
return this.each(function() {
@@ -76,30 +76,33 @@
return true;
}
- /* --- ДЕЙСТВИЯ (DELETE, ANSWER, LOCK) --- */
+ /* --- ДЕЙСТВИЯ (DELETE, LOCK, OPEN/CLOSE) --- */
function cAction(obj, action) {
var $btn = $(obj);
var cid = $btn.data('id');
- if (!cid) return;
-
- if (action === 'answer') {
- $('#parent_id').val(cid);
- $('#mod_comment_new').insertBefore('#end' + cid).show();
- $('html, body').animate({ scrollTop: $('#mod_comment_new').offset().top - 150 }, 500);
- return;
- }
+ if (!cid && action !== 'open' && action !== 'close') return;
+
$.get(aveabspath + 'index.php', {
module: 'comment',
action: action,
docid: typeof DOC_ID !== 'undefined' ? DOC_ID : '',
- Id: cid
+ Id: cid ? cid : ''
}, function() {
+ if (action === 'close') {
+ $btn.attr('id', 'mod_comment_open')
+ .removeClass('btn-outline-danger').addClass('btn-outline-success')
+ .html(' ' + COMMENT_SITE_OPEN);
+ $('#mod_comment_new').fadeOut(300);
+ }
+ else if (action === 'open') {
+ $btn.attr('id', 'mod_comment_close')
+ .removeClass('btn-outline-success').addClass('btn-outline-danger')
+ .html(' ' + COMMENT_SITE_CLOSE);
+ $('#mod_comment_new').fadeIn(300);
+ }
if (action === 'delete') {
var $commentBlock = $btn.closest('.mod_comment_comment');
- if ($commentBlock.find('#mod_comment_new').length > 0) {
- $('#mod_comment_new').insertAfter($('.mod_comment_comment').last());
- }
$commentBlock.fadeOut(300, function() { $(this).remove(); });
}
if (action === 'unlock' || action === 'lock') {
@@ -116,16 +119,38 @@
initCommentTimers();
var $doc = $(document);
- // Делегирование с защитой от двойного клика через .off()
- $doc.off('click', '.mod_comment_answer').on('click', '.mod_comment_answer', function(e) {
- e.preventDefault(); cAction(this, 'answer');
+ // Глобальные кнопки управления
+ $doc.on('click', '#mod_comment_close', function(e) {
+ e.preventDefault(); cAction(this, 'close');
+ });
+ $doc.on('click', '#mod_comment_open', function(e) {
+ e.preventDefault(); cAction(this, 'open');
});
+ // КНОПКА ОТВЕТА (ИСПРАВЛЕНО: перемещает форму, а не шлет AJAX)
+ $doc.off('click', '.mod_comment_answer').on('click', '.mod_comment_answer', function(e) {
+ e.preventDefault();
+ var cid = $(this).data('id');
+ var $form = $('#mod_comment_new');
+
+ // Переносим форму и ставим parent_id
+ $form.insertAfter('#comment_' + cid).show();
+ $('#parent_id').val(cid);
+
+ // Скролл к форме
+ $('html, body').animate({
+ scrollTop: $form.offset().top - 150
+ }, 500);
+ $('#in_message').focus();
+ });
+
+ // Удаление
$doc.off('click', '.mod_comment_delete').on('click', '.mod_comment_delete', function(e) {
e.preventDefault();
if (confirm('Удалить этот комментарий?')) cAction(this, 'delete');
});
+ // Блокировка
$doc.off('click', '.mod_comment_lock, .mod_comment_unlock').on('click', '.mod_comment_lock, .mod_comment_unlock', function(e) {
e.preventDefault();
cAction(this, $(this).hasClass('mod_comment_lock') ? 'lock' : 'unlock');
@@ -135,11 +160,16 @@
$doc.off('click', '.mod_comment_edit').on('click', '.mod_comment_edit', function(e) {
e.preventDefault();
var cid = $(this).data('id');
- var $textBlock = $('#comment_wrapper_' + cid).find('.mod_comment_text');
- $('.edit-form-container').remove(); $('.mod_comment_text').show();
+ var $wrapper = $('#comment_wrapper_' + cid);
+ var $textBlock = $wrapper.find('.mod_comment_text').first();
+
+ if ($wrapper.find('.edit-form-container').length > 0) return;
+
+ $('.edit-form-container').remove();
+ $('.mod_comment_text').show();
var cleanText = $textBlock.html().replace(/
/mg, "\n").trim();
- var currentImg = $('#comment_wrapper_' + cid).find('.mod_comment_attached_image img').attr('src');
+ var currentImg = $wrapper.find('.mod_comment_attached_image img').first().attr('src');
var editHtml = `