Elgg  Version 1.11
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  // https://github.com/kvz/phpjs/blob/master/LICENSE.txt
71  function nl2br(content) {
72  if (/<(?:p|br)\b/.test(content)) {
73  // probably formatted already
74  return content;
75  }
76  return content.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1<br>$2');
77  }
78 
79  if (json.status === 0) {
80  // Update list item content
81  if (json.output) {
82  that.$item.find('[data-role="comment-text"]').replaceWith(json.output);
83  } else {
84  // action has been overridden and doesn't return comment content
85  that.$item.find('[data-role="comment-text"]').html(nl2br(value));
86  }
87  }
88  that.hideForm(function () {
89  that.getForm().remove();
90  });
91  }
92  });
93 
94  return false;
95  },
96 
97  toggleEdit: function () {
98  var $form = this.getForm();
99  if ($form.length) {
100  if ($form.data('hidden')) {
101  this.showForm();
102  } else {
103  this.hideForm();
104  }
105  } else {
106  this.loadForm();
107  }
108  return false;
109  }
110 };
111 
117 elgg.comments.init = function() {
118  $(document).on('click', '.elgg-item-object-comment .elgg-menu-item-edit > a', function () {
119  // store object as data in the edit link
120  var dc = $(this).data('Comment'),
121  guid;
122  if (!dc) {
123  guid = this.href.split('/').pop();
124  dc = new elgg.comments.Comment(guid);
125  $(this).data('Comment', dc);
126  }
127  dc.toggleEdit();
128  return false;
129  });
130 };
131 
132 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:252
elgg
Definition: install.js:23
p
Definition: admin.php:118
friends picker navigation friends picker navigation r
Definition: admin.php:800
$form
Definition: settings.php:18
b
Definition: admin.php:56
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
elgg widget content
Definition: admin.php:1245