blob: 216d848c847ae1081c26b005108c78d719a9bde1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// Static comments
// from: https://github.com/eduardoboucas/popcorn/blob/gh-pages/js/main.js
$(document).ready(function() {
var $comments = $('.js-comments');
$('.js-form').submit(function () {
var form = this;
$(form).addClass('form--loading');
$.ajax({
type: $(this).attr('method'),
url: $(this).attr('action'),
data: $(this).serialize(),
contentType: 'application/x-www-form-urlencoded',
success: function (data) {
// $('.js-form input[type="submit"]').val('{{ i18n comment_btn_submit }}');
// showAlert('{{ i18n comment_success_msg }}');
showAlert('success');
$(form).removeClass('form--loading');
clearForm();
},
error: function (err) {
console.log(err);
// $('.js-form input[type="submit"]').val('{{ i18n comment_btn_submit }}');
// showAlert('{{ i18n comment_error_msg }}');
showAlert('failed');
$(form).removeClass('form--loading');
}
});
return false;
});
function showAlert(msg) {
$('.js-form .js-notice').removeClass('hidden');
$('.js-form .js-notice-text').text(msg);
}
function clearForm() {
$('input[name="fields[replyThread]"]').val('');
$('input[name="fields[replyID]"]').val('');
$('input[name="fields[replyName]"]').val('');
$('.reply-notice-text').text('');
}
// record reply target when "reply to this comment" is pressed
$('article.static-comment').on('click', 'a.btn', function (evt){
var cmt = $(evt.delegateTarget);
$('input[name="fields[replyThread]"]').val(this.title);
$('input[name="fields[replyID]"]').val(cmt.attr("id"));
authorTag = cmt.find('.comment-author');
replyName = authorTag.text();
$('input[name="fields[replyName]"]').val(replyName);
$('.reply-notice-text').text('↷\xa0' + replyName);
});
// clear form when reset button is clicked
$('.js-form input[type="reset"]').click(function (){
clearForm();
});
});
|