Blame view

common/modules/comment/resources/comment.js 3.57 KB
3f2bc3d0   Administrator   first commit
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
  $(function() {

  

      $(document).on('click', '.artbox_comment_delete', function() {

          var container = $(this).parents('.artbox_comment_container');

          var comment_id = $(container).data('comment_id');

          var form_name = $(container).data('form_name');

          if(confirm("Уверены, что хотите удалить комментарий?")) {

              $.post(

                  '/artbox-comment/delete',

                  {

                      Comment: {

                          comment_id: comment_id

                      }

                  },

                  function(data, textStatus, jqXHR) {

                      if(!data.error) {

                          $(container).after('<p class="removeable">'+data.text+'</p>');

                          $(container).remove();

                      } else {

                          $(container).prepend('<p class="removeable error_message">'+data.error+'</p>')

                      }

                  }

              );

          }

      });

  

      $(document).on('click', '.artbox_comment_reply', function() {

          var container = $(this).parents('.artbox_comment_container').first();

          var comment_id = $(container).data('comment_id');

          var form_name = $(container).data('form_name');

          var author = $(container).find('.artbox_comment_author').first().text();

          var comment_form = $('.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() {

          $(this).removeClass('artbox_comment_update');

          $(this).text('Сохранить');

          $(this).addClass('artbox_comment_update_submit');

          var container = $(this).parents('.artbox_comment_container').first();

          var comment_id = $(container).data('comment_id');

          var form_name = $(container).data('form_name');

          var text = $(container).find('.artbox_comment_text');

          var object = {};

          object[form_name] = {comment_id: comment_id};

          $.post(

              '/artbox-comment/form',

              object,

              function(data, textStatus, jqXHR) {

                  $(text).hide();

                  $(text).after(

                      '<div class="artbox_comment_text_edit new-portf-answer">'

                      + data

                      + '</div>'

                  );

              }

          );

      });

  

      $(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();

          var edit = $(container).find('.artbox_comment_text_edit').first();

          $.post(

              '/artbox-comment/update',

              $(edit).find('form').serialize(),

              function(data) {

                  if(!data.error) {

                      location.reload(true);

                  }

              }

          )

      });

  });