comment.js
4.12 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
$(function() {
$(document).on('click', '.artbox_comment_container .removeable', function(e) {
e.preventDefault();
var container = $(this).parents('.artbox_comment_container');
$(container).remove();
});
$(document).on(
'click', '.artbox_comment_delete', function(e)
{
e.preventDefault();
var container = $(this).parents('.artbox_comment_container');
var comment_id = $(container).data('key');
var form_name = $(container).data('form');
if(confirm("Уверены, что хотите удалить комментарий?"))
{
$.post(
'/artbox-comment/delete', {
Comment : {
comment_id : comment_id
}
}, function(data, textStatus, jqXHR)
{
if(!data.error)
{
$(container).empty();
$(container).append('<p class="removeable">' + data.text + '</p>');
} else
{
$(container).prepend('<p class="removeable error_message">' + data.error + '</p>')
}
}
);
}
}
);
$(document).on(
'click', '.artbox_comment_reply', function(e)
{
e.preventDefault();
var container = $(this).parents('.artbox_comment_container').first();
var comment_id = $(container).data('key');
var form_name = $(container).data('form');
var author = $(container).find('.artbox_comment_author').first().text();
var comment_form = $(container).parents('.artbox_comment_widget').find('.artbox_comment_form').first();
var offset = $(comment_form).offset();
var reply_block = $(comment_form).find('.artbox_comment_reply_block').first();
$(reply_block).empty();
$(reply_block).append('<input type="hidden" name="' + form_name + '[comment_pid]" value="' + comment_id + '">');
$(reply_block).append('<p class="artbox_comment_reply_author">' + author + '</p>');
$('html, body').animate(
{
scrollTop : offset.top - 50,
}
);
}
);
$(document).on(
'click', '.artbox_comment_reply_author', function()
{
$(this).parents('.artbox_comment_reply_block').first().empty();
}
);
$(document).on(
'click', '.artbox_comment_update', function(e)
{
e.preventDefault();
var container = $(this).parents('.artbox_comment_container').first();
var comment_id = $(container).data('key');
var form_name = $(container).data('form');
var object = {};
object[form_name] = {comment_id : comment_id};
$.post(
'/artbox-comment/form', object, function(data, textStatus, jqXHR)
{
$(container).empty();
$(container).append(data.result.form);
}
);
}
);
// @TODO What is this
$(document).on(
'click', '.artbox_comment_update_reply', function()
{
$(this).remove();
}
);
$(document).on(
'click', '.artbox_comment_update_submit', function(e)
{
e.preventDefault();
var container = $(this).parents('.artbox_comment_container').first();
$.post(
'/artbox-comment/update', $(container).find('form').serialize(), function(data)
{
$(container).empty();
if(!data.error)
{
$(container).append('<p>'+data.result.text+'</p>');
$(container).append(data.result.html);
} else {
$(container).append(data.form);
}
}
)
}
);
});