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.
7 $(document).on("change", ".richtext_container textarea", function () {
8 var container = $(this).closest(".richtext_container");
9 var preview = container.find(".tab-pane[id$='_preview']");
11 preview.children(".richtext_placeholder").attr("hidden", true);
12 preview.children(".richtext").empty();
16 * Install a handler to set the minimum preview pane height
17 * when switching away from an edit pane
19 $(document).on("hide.bs.tab", ".richtext_container button[data-bs-target$='_edit']", function () {
20 var container = $(this).closest(".richtext_container");
21 var editor = container.find("textarea");
22 var preview = container.find(".tab-pane[id$='_preview']");
23 var minHeight = editor.outerHeight() - preview.outerHeight() + preview.height();
25 preview.css("min-height", minHeight + "px");
29 * Install a handler to switch to preview mode
31 $(document).on("show.bs.tab", ".richtext_container button[data-bs-target$='_preview']", function () {
32 var container = $(this).closest(".richtext_container");
33 var editor = container.find("textarea");
34 var preview = container.find(".tab-pane[id$='_preview']");
36 if (preview.children(".richtext").contents().length === 0) {
37 preview.oneTime(200, "loading", function () {
38 preview.children(".richtext_placeholder").removeAttr("hidden");
41 preview.children(".richtext").load(editor.data("previewUrl"), { text: editor.val() }, function () {
42 preview.stopTime("loading");
43 preview.children(".richtext_placeholder").attr("hidden", true);
48 $(window).on("resize", updateHelp);
50 $(document).on("turbo:load", function () {
51 $(".richtext_container textarea").on("invalid", invalidTextareaListener);
55 function invalidTextareaListener() {
56 var container = $(this).closest(".richtext_container");
58 container.find("button[data-bs-target$='_edit']").tab("show");
61 function updateHelp() {
62 $(".richtext_container .richtext_help_sidebar:not(:visible):not(:empty)").each(function () {
63 var container = $(this).closest(".richtext_container");
64 $(this).children().appendTo(container.find(".tab-pane[id$='_help']"));
66 $(".richtext_container .richtext_help_sidebar:visible:empty").each(function () {
67 var container = $(this).closest(".richtext_container");
68 container.find(".tab-pane[id$='_help']").children().appendTo($(this));
69 if (container.find("button[data-bs-target$='_help'].active").length) {
70 container.find("button[data-bs-target$='_edit']").tab("show");