From cfa957e53883667990392d71a31f5427a9fa4169 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Dec 14 2015 16:08:54 +0000 Subject: Use jquery's $.closest() instead of piling up the $.parent() --- diff --git a/pagure/templates/issue.html b/pagure/templates/issue.html index 3238906..89a9306 100644 --- a/pagure/templates/issue.html +++ b/pagure/templates/issue.html @@ -350,8 +350,8 @@ $(function() { function cancel_edit_btn() { $( ".cancel" ).click( function() { - $(this).parent().parent().parent().parent().parent().find('.comment_body').show(); - $(this).parent().parent().parent().parent().remove(); + $(this).closest('#comments').find('.comment_body').show(); + $(this).closest('.edit_comment').remove(); return false; } ); diff --git a/pagure/templates/pull_request.html b/pagure/templates/pull_request.html index e7b5c92..979e67f 100644 --- a/pagure/templates/pull_request.html +++ b/pagure/templates/pull_request.html @@ -581,15 +581,12 @@ function cancel_edit_btn() { $( ".cancel" ).click( function() { - var item = $(this).parent().parent().parent().parent().parent().find('.comment_body'); - if (item.length) { - $(this).parent().parent().parent().parent().remove(); - item.show(); - } else { - item = $(this).parent().parent().parent().parent().parent().parent().parent().children()[1]; - $(this).parent().parent().parent().parent().parent().parent().remove(); - $(item).show(); + var item = $(this).closest('tr'); + if (!item.length) { + item = $(this).closest('section'); } + $(item.parent().children()[1]).show(); + item.remove(); return false; } );