From: Anton Khorev Date: Thu, 8 Aug 2024 03:07:42 +0000 (+0300) Subject: Use closest() instead of parents() when looking for richtext container X-Git-Tag: live~332^2~4 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/5e3544849129552b3230a13ee265979fef7c7499 Use closest() instead of parents() when looking for richtext container --- diff --git a/app/assets/javascripts/richtext.js b/app/assets/javascripts/richtext.js index 7447a0ca2..cb0bd1f27 100644 --- a/app/assets/javascripts/richtext.js +++ b/app/assets/javascripts/richtext.js @@ -5,15 +5,18 @@ $(document).ready(function () { * the user next switches to it. */ $(".richtext_container textarea").change(function () { - $(this).parents(".richtext_container").find(".tab-pane[id$='_preview']").empty(); + var container = $(this).closest(".richtext_container"); + + container.find(".tab-pane[id$='_preview']").empty(); }); /* * Install a handler to switch to preview mode */ $(".richtext_container button[data-bs-target$='_preview']").on("show.bs.tab", function () { - var editor = $(this).parents(".richtext_container").find("textarea"); - var preview = $(this).parents(".richtext_container").find(".tab-pane[id$='_preview']"); + var container = $(this).closest(".richtext_container"); + var editor = container.find("textarea"); + var preview = container.find(".tab-pane[id$='_preview']"); var minHeight = editor.outerHeight() - preview.outerHeight() + preview.height(); if (preview.contents().length === 0) {