Elgg  Version 5.1
Functions
comments.js File Reference

Go to the source code of this file.

Functions

 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('click', '.elgg-toggle-comment', function(event){var $anchor=$(this);var comment_guid=$anchor.data().loadComment;require(['elgg/Ajax', 'elgg/toggle'], function(Ajax){var ajax=new Ajax();ajax.form('comment/save',{data:{guid:comment_guid}, success:function(result){$('div[data-comments-placeholder='+comment_guid+ ']').html(result).slideToggle('medium').find('textarea, [contenteditable]').filter(':visible').first().focus();$anchor.toggleClass('elgg-toggle elgg-toggle-comment');}});});});$(document).on('submit', '.elgg-form-comment-save', function(event){var $form=$(this);$form.find('.elgg-button-submit').prop('disabled', true);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){$form.find('.elgg-button-submit').prop('disabled', true);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();});}});}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());}var $comment=$container.find('#elgg-object-'+comment_guid);$comment.addClass('elgg-state-highlight');$comment[0].scrollIntoView({behavior: 'smooth'});fix_pagination($container);}, error:function(){$form.find('.elgg-button-submit').prop('disabled', false);}});}, error:function(){$form.find('.elgg-button-submit').prop('disabled', false);}});});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).data().commentGuid;dc=new Comment(guid, $trigger.closest('.elgg-item-object-comment'));$(this).data('Comment', dc);}dc.toggleEdit();require(['elgg/popup'], function(popup){popup.close();});return false;});function Comment(guid, item){this.guid=guid;this.$item=item;}Comment.prototype={getForm:function(){return this.$item.find('#edit-comment-'+this.guid);}, hideForm:function(){this.getForm().toggleClass('hidden');this.getForm().prev().toggleClass('hidden');}, showForm:function(){this.getForm().toggleClass('hidden');this.getForm().prev().toggleClass('hidden');this.getForm().find('textarea, [contenteditable]').filter(':visible').first().focus();}, 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();$form.find('.elgg-button-submit').prop('disabled', true);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);}}, error:function(){$form.find('.elgg-button-submit').prop('disabled', false);}});});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;}};})
 

Function Documentation

define ( 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('click', '.elgg-toggle-comment', function(event){var $anchor=$(this);var comment_guid=$anchor.data().loadComment;require(['elgg/Ajax', 'elgg/toggle'], function(Ajax){var ajax=new Ajax();ajax.form('comment/save',{data:{guid:comment_guid}, success:function(result){$('div[data-comments-placeholder='+comment_guid+ ']').html(result).slideToggle('medium').find('textarea, [contenteditable]').filter(':visible').first().focus();$anchor.toggleClass('elgg-toggle elgg-toggle-comment');}});});});$(document).on('submit', '.elgg-form-comment-save', function(event){var $form=$(this);$form.find('.elgg-button-submit').prop('disabled', true);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){$form.find('.elgg-button-submit').prop('disabled', true);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();});}});}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());}var $comment=$container.find('#elgg-object-'+comment_guid);$comment.addClass('elgg-state-highlight');$comment[0].scrollIntoView({behavior: 'smooth'});fix_pagination($container);}, error:function(){$form.find('.elgg-button-submit').prop('disabled', false);}});}, error:function(){$form.find('.elgg-button-submit').prop('disabled', false);}});});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).data().commentGuid;dc=new Comment(guid, $trigger.closest('.elgg-item-object-comment'));$(this).data('Comment', dc);}dc.toggleEdit();require(['elgg/popup'], function(popup){popup.close();});return false;});function Comment(guid, item){this.guid=guid;this.$item=item;}Comment.prototype={getForm:function(){return this.$item.find('#edit-comment-'+this.guid);}, hideForm:function(){this.getForm().toggleClass('hidden');this.getForm().prev().toggleClass('hidden');}, showForm:function(){this.getForm().toggleClass('hidden');this.getForm().prev().toggleClass('hidden');this.getForm().find('textarea, [contenteditable]').filter(':visible').first().focus();}, 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();$form.find('.elgg-button-submit').prop('disabled', true);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);}}, error:function(){$form.find('.elgg-button-submit').prop('disabled', false);}});});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;}};}  )
Parameters
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();}}});.on('click', '.elgg-toggle-comment', function(event){var $anchor=;var comment_guid=$anchor.data().loadComment;require(['elgg/Ajax', 'elgg/toggle'], function(Ajax){var ajax=new Ajax();ajax.form('comment/save',{data:{guid:comment_guid}, success:function(result){$('div[data-comments-placeholder='+comment_guid+ ']').html(result).slideToggle('medium').find('textarea, [contenteditable]').filter(':visible').first().focus();$anchor.toggleClass('elgg-toggle elgg-toggle-comment');}});});});.on('submit', '.elgg-form-comment-save', function(event){var $form=;$form.find('.elgg-button-submit').prop('disabled', true);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){$form.find('.elgg-button-submit').prop('disabled', true);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){.on('click', function(){location.reload();});}});}ajax.view(view_name,{data:data, success:function(result){if(view_name=== 'river/elements/responses'){$container.html(result);}else{$container.html(.filter('.elgg-comments').html());}var $comment=$container.find('elgg-object-'+comment_guid);$comment.addClass('elgg-state-highlight');$comment[0].scrollIntoView({behavior: 'smooth'});fix_pagination($container);}, error:function(){$form.find('.elgg-button-submit').prop('disabled', false);}});}, error:function(){$form.find('.elgg-button-submit').prop('disabled', false);}});});event.preventDefault();event.stopPropagation();});.on('click', '.elgg-menu-item-edit > a', function(){var $trigger=.closest('.elgg-menu-hover').data('trigger');if((typeof $trigger=== 'undefined')||!$trigger.is('.elgg-item-object-comment a')){return;}var dc=.data('Comment');if(!dc){var guid=.data().commentGuid;dc=new Comment(guid, $trigger.closest('.elgg-item-object-comment'));.data('Comment', dc);}dc.toggleEdit();require(['elgg/popup'], function(popup){popup.close();});return false;});function Comment(guid, item){this.guid=guid;this.$item=item;}Comment.prototype={getForm:function(){return this.$item.find('#edit-comment-'+this.guid);}, hideForm:function(){this.getForm().toggleClass('hidden');this.getForm().prev().toggleClass('hidden');}, showForm:function(){this.getForm().toggleClass('hidden');this.getForm().prev().toggleClass('hidden');this.getForm().find('textarea, [contenteditable]').filter(':visible').first().focus();}, 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();$form.find('.elgg-button-submit').prop('disabled', true);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);}}, error:function(){$form.find('.elgg-button-submit').prop('disabled', false);}});});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;}};} Get a jQuery-wrapped reference to the form
Returns
{jQuery} note: may be empty