Elgg  Version 1.9
comments.js
Go to the documentation of this file.
1 
2 elgg.provide('elgg.comments');
3 
8 elgg.comments.Comment = function (guid) {
9  this.guid = guid;
10  this.$item = $('#elgg-object-' + guid);
11 };
12 
13 elgg.comments.Comment.prototype = {
19  getForm: function () {
20  return this.$item.find('.elgg-form-comment-save');
21  },
22 
26  hideForm: function (complete) {
27  complete = complete || function () {};
28  this.getForm().slideUp('fast', complete).data('hidden', 1);
29  },
30 
31  showForm: function () {
32  this.getForm().slideDown('medium').data('hidden', 0);
33  },
34 
35  loadForm: function () {
36  var that = this;
37 
38  // Get the form using ajax
39  elgg.ajax('ajax/view/core/ajax/edit_comment?guid=' + this.guid, {
40  success: function(html) {
41  // Add the form to DOM
42  that.$item.find('.elgg-body').first().append(html);
43 
44  that.showForm();
45 
46  var $form = that.getForm();
47 
48  $form.find('.elgg-button-cancel').on('click', function () {
49  that.hideForm();
50  return false;
51  });
52 
53  // save
54  $form.on('submit', function () {
55  that.submitForm();
56  return false;
57  });
58  }
59  });
60  },
61 
62  submitForm: function () {
63  var that = this,
64  $form = this.getForm(),
65  value = $form.find('textarea[name=generic_comment]').val();
66 
67  elgg.action('comment/save', {
68  data: $form.serialize(),
69  success: function(json) {
70  if (json.status === 0) {
71  // Update list item content
72  that.$item.find('[data-role="comment-text"]').html(value);
73  }
74  that.hideForm(function () {
75  that.getForm().remove();
76  });
77  }
78  });
79 
80  return false;
81  },
82 
83  toggleEdit: function () {
84  var $form = this.getForm();
85  if ($form.length) {
86  if ($form.data('hidden')) {
87  this.showForm();
88  } else {
89  this.hideForm();
90  }
91  } else {
92  this.loadForm();
93  }
94  return false;
95  }
96 };
97 
103 elgg.comments.init = function() {
104  $(document).on('click', '.elgg-item-object-comment .elgg-menu-item-edit > a', function () {
105  // store object as data in the edit link
106  var dc = $(this).data('Comment'),
107  guid;
108  if (!dc) {
109  guid = this.href.split('/').pop();
110  dc = new elgg.comments.Comment(guid);
111  $(this).data('Comment', dc);
112  }
113  dc.toggleEdit();
114  return false;
115  });
116 };
117 
118 elgg.register_hook_handler('init', 'system', elgg.comments.init);
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed on
Definition: LICENSE.txt:43
elgg message elgg state success
Definition: admin.php:243
elgg
Definition: install.js:23
$form
Definition: settings.php:18
GNU GENERAL PUBLIC LICENSE June Free Software Franklin Fifth MA USA Everyone is permitted to copy and distribute verbatim copies of this license document
Definition: LICENSE.txt:4
html
Definition: admin.php:36
$item
Definition: item.php:12