Elgg  Version 3.0
comments.js
Go to the documentation of this file.
1 define(['jquery', 'elgg'], function ($, elgg) {
2 
3  /* Autofocuses first text input in a comment form when toggled */
4  $(document).on('elgg_ui_toggle', function (e, data) {
5  var $toggle = $(e.target);
6  var $elements = data.$toggled_elements;
7 
8  if ($elements.is('.elgg-river-responses > .elgg-form-comment-save')) {
9  if ($toggle.hasClass('elgg-state-active')) {
10  $elements.find('.elgg-input-text').focus();
11  } else {
12  $toggle.blur();
13  }
14  }
15  });
16 
17  $(document).on('submit', '.elgg-form-comment-save', function (event) {
18  var $form = $(this);
19 
20  require(['elgg/Ajax'], function(Ajax) {
21  var ajax = new Ajax();
22 
23  ajax.action($form.attr('action'), {
24  data: ajax.objectify($form),
25  success: function(result) {
26  var $container = $form.closest('.elgg-comments');
27  var view_name = 'page/elements/comments';
28  var comment_guid = result.guid;
29  var data = {
30  guid: $form.find('input[name="entity_guid"]').val(),
31  id: $form.attr('id'),
32  show_guid: comment_guid,
33  inline: $form.find('.elgg-input-text').length
34  };
35 
36  if (!$container.length) {
37  $container = $form.closest('.elgg-river-responses');
38  view_name = 'river/elements/responses';
39  data.river_id = $container.closest('.elgg-river-item').parent().attr('id').replace('item-river-', '');
40  }
41 
42  if (!$container.length) {
43  return;
44  }
45 
46  // the pagination returned will have a non-functional link that points to the current URL,
47  // but we want the the link to reload the page.
48  function fix_pagination($container) {
49  function normalize(url) {
50  return url.replace(/#.*/, '');
51  }
52 
53  var base_url = normalize(location.href);
54 
55  $container.find('.elgg-pagination a').each(function () {
56  if (normalize(this.href) === base_url) {
57  $(this).on('click', function () {
58  location.reload(true);
59  });
60  }
61  });
62  }
63 
64  ajax.view(view_name, {
65  data: data,
66  success: function(result) {
67  if (view_name === 'river/elements/responses') {
68  $container.html(result);
69  } else {
70  $container.html($(result).filter('.elgg-comments').html());
71  }
72 
73  $container.find('#elgg-object-' + comment_guid).addClass('elgg-state-highlight');
74  fix_pagination($container);
75  }
76  });
77  }
78  });
79  });
80 
81  event.preventDefault();
82  event.stopPropagation();
83  });
84 
85 
86  $(document).on('click', '.elgg-menu-item-edit > a', function () {
87  var $trigger = $(this).closest('.elgg-menu-hover').data('trigger');
88  if ((typeof $trigger === 'undefined') || !$trigger.is('.elgg-item-object-comment a')) {
89  return;
90  }
91 
92  // store object as data in the edit link
93  var dc = $(this).data('Comment');
94  if (!dc) {
95  var guid = this.href.split('/').pop();
96  dc = new Comment(guid, $trigger.closest('.elgg-item-object-comment'));
97  $(this).data('Comment', dc);
98  }
99  dc.toggleEdit();
100 
101  // trick the popup menu to close itself
102  $(document).trigger('scroll');
103 
104  return false;
105  });
106 
107  function Comment(guid, item) {
108  this.guid = guid;
109  this.$item = item;
110  }
111 
112  Comment.prototype = {
118  getForm: function () {
119  return this.$item.find('.elgg-form-comment-save');
120  },
121 
122  hideForm: function () {
123  this.getForm().toggleClass('hidden');
124  this.getForm().prev().toggleClass('hidden');
125  },
126 
127  showForm: function () {
128  this.getForm().toggleClass('hidden');
129  this.getForm().prev().toggleClass('hidden');
130  },
131 
132  loadForm: function () {
133  var that = this;
134 
135  require(['elgg/Ajax'], function(Ajax) {
136  var ajax = new Ajax();
137 
138  // Get the form using ajax
139  ajax.view('core/ajax/edit_comment?guid=' + that.guid, {
140  success: function(html) {
141  // Add the form to DOM
142  that.$item.find('.elgg-body').first().append(html);
143 
144  that.showForm();
145 
146  var $form = that.getForm();
147 
148  $form.find('.elgg-button-cancel').on('click', function () {
149  that.hideForm();
150  return false;
151  });
152 
153  // save
154  $form.on('submit', function () {
155  that.submitForm();
156  return false;
157  });
158  }
159  });
160  });
161  },
162 
163  submitForm: function () {
164  var $form = this.getForm();
165 
166  require(['elgg/Ajax'], function(Ajax) {
167  var ajax = new Ajax();
168 
169  ajax.action($form.attr('action'), {
170  data: ajax.objectify($form),
171  success: function(result) {
172  if (result.output) {
173  // Update list item content
174  $form.closest('.elgg-item-object-comment').html(result.output);
175  }
176  }
177  });
178  });
179 
180  return false;
181  },
182 
183  toggleEdit: function () {
184  var $form = this.getForm();
185  if ($form.length) {
186  if ($form.hasClass('hidden')) {
187  this.showForm();
188  } else {
189  this.hideForm();
190  }
191  } else {
192  this.loadForm();
193  }
194  return false;
195  }
196  };
197 });
define(['jquery', 'elgg'], function($, elgg){$(document).on('elgg_ui_toggle', function(e, data){var $toggle=$(e.target);var $elements=data.$toggled_elements;if($elements.is('.elgg-river-responses >.elgg-form-comment-save')){if($toggle.hasClass('elgg-state-active')){$elements.find('.elgg-input-text').focus();}else{$toggle.blur();}}});$(document).on('submit', '.elgg-form-comment-save', function(event){var $form=$(this);require(['elgg/Ajax'], function(Ajax){var ajax=new Ajax();ajax.action($form.attr('action'),{data:ajax.objectify($form), success:function(result){var $container=$form.closest('.elgg-comments');var view_name= 'page/elements/comments';var comment_guid=result.guid;var data={guid:$form.find('input[name="entity_guid"]').val(), id:$form.attr('id'), show_guid:comment_guid, inline:$form.find('.elgg-input-text').length};if(!$container.length){$container=$form.closest('.elgg-river-responses');view_name= 'river/elements/responses';data.river_id=$container.closest('.elgg-river-item').parent().attr('id').replace('item-river-', '');}if(!$container.length){return;}function fix_pagination($container){function normalize(url){return url.replace(/#.*/, '');}var base_url=normalize(location.href);$container.find('.elgg-pagination a').each(function(){if(normalize(this.href)===base_url){$(this).on('click', function(){location.reload(true);});}});}ajax.view(view_name,{data:data, success:function(result){if(view_name=== 'river/elements/responses'){$container.html(result);}else{$container.html($(result).filter('.elgg-comments').html());}$container.find('#elgg-object-'+comment_guid).addClass('elgg-state-highlight');fix_pagination($container);}});}});});event.preventDefault();event.stopPropagation();});$(document).on('click', '.elgg-menu-item-edit > a', function(){var $trigger=$(this).closest('.elgg-menu-hover').data('trigger');if((typeof $trigger=== 'undefined')||!$trigger.is('.elgg-item-object-comment a')){return;}var dc=$(this).data('Comment');if(!dc){var guid=this.href.split('/').pop();dc=new Comment(guid, $trigger.closest('.elgg-item-object-comment'));$(this).data('Comment', dc);}dc.toggleEdit();$(document).trigger('scroll');return false;});function Comment(guid, item){this.guid=guid;this.$item=item;}Comment.prototype={getForm:function(){return this.$item.find('.elgg-form-comment-save');}, hideForm:function(){this.getForm().toggleClass('hidden');this.getForm().prev().toggleClass('hidden');}, showForm:function(){this.getForm().toggleClass('hidden');this.getForm().prev().toggleClass('hidden');}, loadForm:function(){var that=this;require(['elgg/Ajax'], function(Ajax){var ajax=new Ajax();ajax.view('core/ajax/edit_comment?guid='+that.guid,{success:function(html){that.$item.find('.elgg-body').first().append(html);that.showForm();var $form=that.getForm();$form.find('.elgg-button-cancel').on('click', function(){that.hideForm();return false;});$form.on('submit', function(){that.submitForm();return false;});}});});}, submitForm:function(){var $form=this.getForm();require(['elgg/Ajax'], function(Ajax){var ajax=new Ajax();ajax.action($form.attr('action'),{data:ajax.objectify($form), success:function(result){if(result.output){$form.closest('.elgg-item-object-comment').html(result.output);}}});});return false;}, toggleEdit:function(){var $form=this.getForm();if($form.length){if($form.hasClass('hidden')){this.showForm();}else{this.hideForm();}}else{this.loadForm();}return false;}};})
if(!$items) $item
Definition: delete.php:13
elgg ajax
Wrapper function for jQuery.ajax which ensures that the url being called is relative to the elgg site...
Definition: ajax.js:19
$container
Definition: delete.php:23
elgg require
Throw an error if the required package isn't present.
Definition: elgglib.js:164
function filter(array, term)
$CONFIG url
The full URL where Elgg is installed.
Definition: config.php:38
$form
List all unvalidated users in the admin area.
Definition: unvalidated.php:9
Bundled plugins(the contents of the"/mod"directory) are available only under the GPLv2 license.The remainder of the project is available under either MIT or GPLv2.Both licenses can be found below.More info 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:96
var elgg
Definition: elgglib.js:4