From 77868bee699aaf3f4f43a7a0000996501dad772f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Geuken?= Date: Wed, 30 Jan 2019 08:24:31 +0100 Subject: [PATCH] Move js event handler for comments to another partial 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 c2ec9cc2898df3ad329e93caa3241c9895eb96ad. --- src/api/app/views/webui2/webui/comment/_content.html.haml | 5 ----- src/api/app/views/webui2/webui/comment/_show.html.haml | 8 ++++++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/api/app/views/webui2/webui/comment/_content.html.haml b/src/api/app/views/webui2/webui/comment/_content.html.haml index 5342759a079..627cb814cc6 100644 --- a/src/api/app/views/webui2/webui/comment/_content.html.haml +++ b/src/api/app/views/webui2/webui/comment/_content.html.haml @@ -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(''); - $(this).remove(); - }); diff --git a/src/api/app/views/webui2/webui/comment/_show.html.haml b/src/api/app/views/webui2/webui/comment/_show.html.haml index 1a8e06b1cad..f8926afd13b 100644 --- a/src/api/app/views/webui2/webui/comment/_show.html.haml +++ b/src/api/app/views/webui2/webui/comment/_show.html.haml @@ -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(''); + $(this).remove(); + }); + });