parent
717a3386b2
commit
66fabf6849
9 changed files with 637 additions and 714 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,60 @@ |
||||
import $ from 'jquery'; |
||||
|
||||
$(document).ready(function () { |
||||
// Обработчик отправки комментария. Нам не важно, комментарий к курсу или к уроку - URL берется из action формы
|
||||
$('form.questions__form').on('submit', function (e) { |
||||
e.preventDefault(); |
||||
|
||||
const submitButton = $(this).find('button.questions__action'); |
||||
const replyToInput = $(this).find('input[name=reply_id]'); |
||||
const replyToValue = replyToInput.val() ? parseInt(replyToInput.val()) : 0; |
||||
const commentTextarea = $(this).find('textarea.questions__textarea'); |
||||
commentTextarea.attr('disabled', 'disabled'); |
||||
submitButton.attr('disabled', 'disabled'); |
||||
|
||||
$.ajax($(this).attr('action'), { |
||||
method: 'post', |
||||
data: { |
||||
reply_id: replyToValue, |
||||
comment: commentTextarea.val(), |
||||
} |
||||
}) |
||||
.done(function (data) { |
||||
console.log(data); |
||||
if (data.success === true) { |
||||
if (replyToValue > 0) { |
||||
$(`#question__${replyToValue}`).after(data.comment); |
||||
} else { |
||||
$('.questions__list').append(data.comment); |
||||
} |
||||
|
||||
commentTextarea.val(''); |
||||
} |
||||
}) |
||||
.fail(function (xhr) { |
||||
|
||||
}) |
||||
.always(function () { |
||||
commentTextarea.removeAttr('disabled'); |
||||
submitButton.removeAttr('disabled'); |
||||
}); |
||||
}); |
||||
|
||||
// Обработчик кнопки "Ответить"
|
||||
$('.questions__list').on('click', 'button.question__reply-button', function () { |
||||
const replyId = $(this).attr('data-reply-id'); |
||||
const form = $('form.questions__form'); |
||||
form.find('input[name=reply_id]').val(replyId); |
||||
form.find('.questions__reply-anchor').attr('href', `#question__${replyId}`); |
||||
form.find('.questions__reply-info').show(); |
||||
}); |
||||
|
||||
// Обработчик отмены комментирования в ответ на комментарий
|
||||
$('.questions__reply-cancel').on('click', function (e) { |
||||
e.preventDefault(); |
||||
|
||||
const form = $('form.questions__form'); |
||||
form.find('input[name=reply_id]').val(0); |
||||
form.find('.questions__reply-info').hide(); |
||||
}); |
||||
}); |
||||
@ -1,5 +1,5 @@ |
||||
// done by arturmoroz.com |
||||
@import helpers/all |
||||
@import generated/sprite-svg |
||||
@import lib/owl.carousel |
||||
// @import lib/owl.carousel |
||||
@import common |
||||
|
||||
Loading…
Reference in new issue