[openstreetmap/openstreetmap-website] Adapt richtext javascript to Turbo (PR #5116)

Anton Khorev notifications at github.com
Fri Sep 6 07:49:09 UTC 2024


@AntonKhorev commented on this pull request.



>    });
 
-  /*
-   * Install a handler to switch to preview mode
-   */
-  $(".richtext_container button[data-bs-target$='_preview']").on("show.bs.tab", function () {
-    var container = $(this).closest(".richtext_container");
-    var editor = container.find("textarea");
-    var preview = container.find(".tab-pane[id$='_preview']");
+  $(document).on("turbo:load", function () {
+    /*
+    * When the text in an edit pane is changed, clear the contents of
+    * the associated preview pne so that it will be regenerated when
+    * the user next switches to it.
+    */
+    $(".richtext_container textarea").change(function () {

Because `invalid` event doesn't bubble and jQuery, if [this](https://stackoverflow.com/a/24585928) is still true, can't install capture phase listeners. The event will happen at `textarea`, won't go up to `document` and jQuery's delegation won't work.

Installed the listener with `document.addEventListener(..., true)`.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/5116#discussion_r1746660823
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/5116/review/2285259750 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20240906/6630bb1f/attachment.htm>


More information about the rails-dev mailing list