[openstreetmap/openstreetmap-website] Adapt richtext javascript to Turbo (PR #5116)
Tom Hughes
notifications at github.com
Sun Aug 25 16:38:32 UTC 2024
@tomhughes commented on this pull request.
> @@ -1,53 +1,61 @@
-$(document).ready(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 () {
- var container = $(this).closest(".richtext_container");
+(function () {
+ $(document).ready(function () {
+ /*
Do we actually need this? The only things happening inside it are installing handlers on document and window which should be safe without waiting for the page to be ready?
> });
- /*
- * 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 () {
Is it safe to do these on `turbo:load` or might we get handlers installed twice on the same object if a partial load occurs? Is there any reason not to register these on document with event delegation?
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/5116#pullrequestreview-2259337639
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/openstreetmap-website/pull/5116/review/2259337639 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20240825/0ced0413/attachment-0001.htm>
More information about the rails-dev
mailing list