Skip to content

Commit

Permalink
Move js event handler for comments to another partial
Browse files Browse the repository at this point in the history
The 'comment/_content' partial is rendered multiple times. Therefore
the handler would be registered again and again.
By moving it to the comment show view and wrapping it into a document
ready statement we ensure that it's called only once, and for any
comment img element in the DOM.

Follow up of c2ec9cc.
  • Loading branch information
bgeuken committed Jan 30, 2019
1 parent c2ec9cc commit 77868be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 0 additions & 5 deletions src/api/app/views/webui2/webui/comment/_content.html.haml
Expand Up @@ -18,8 +18,3 @@
- comment.children.each do |children|
= render partial: 'webui2/webui/comment/content', locals: { comment: children, commentable: commentable, level: level + 1 }

:javascript
$('#comments img').one('error', function(){
$(this).after('<i class="fas fa-user-circle fa-2x ' + $(this).attr('class') + '"></i>');
$(this).remove();
});
8 changes: 8 additions & 0 deletions src/api/app/views/webui2/webui/comment/_show.html.haml
Expand Up @@ -4,3 +4,11 @@

.comment_new
= render partial: 'webui2/webui/comment/new', locals: { commentable: commentable }

:javascript
$(document).ready(function() {
$('#comments img').one('error', function() {
$(this).after('<i class="fas fa-user-circle fa-2x ' + $(this).attr('class') + '"></i>');
$(this).remove();
});
});

0 comments on commit 77868be

Please sign in to comment.