]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/richtext.js
Add richtext help tab
[rails.git] / app / assets / javascripts / richtext.js
1 $(document).ready(function () {
2   /*
3    * When the text in an edit pane is changed, clear the contents of
4    * the associated preview pne so that it will be regenerated when
5    * the user next switches to it.
6    */
7   $(".richtext_container textarea").change(function () {
8     var container = $(this).closest(".richtext_container");
9
10     container.find(".tab-pane[id$='_preview']").empty();
11   });
12
13   /*
14    * Install a handler to switch to preview mode
15    */
16   $(".richtext_container button[data-bs-target$='_preview']").on("show.bs.tab", function () {
17     var container = $(this).closest(".richtext_container");
18     var editor = container.find("textarea");
19     var preview = container.find(".tab-pane[id$='_preview']");
20     var minHeight = editor.outerHeight() - preview.outerHeight() + preview.height();
21
22     if (preview.contents().length === 0) {
23       preview.oneTime(500, "loading", function () {
24         preview.addClass("loading");
25       });
26
27       preview.load(editor.data("previewUrl"), { text: editor.val() }, function () {
28         preview.stopTime("loading");
29         preview.removeClass("loading");
30       });
31     }
32
33     preview.css("min-height", minHeight + "px");
34   });
35 });