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).removeClass("delayed-fade-in");
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.children(".richtext_placeholder").removeAttr("hidden").addClass("delayed-fade-in");
39 preview.children(".richtext").load(editor.data("previewUrl"), { text: editor.val() }, function () {
40 preview.children(".richtext_placeholder").attr("hidden", true).removeClass("delayed-fade-in");
45 $(window).on("resize", updateHelp);
47 $(document).on("turbo:load", function () {
48 $(".richtext_container textarea").on("invalid", invalidTextareaListener);
52 function invalidTextareaListener() {
53 var container = $(this).closest(".richtext_container");
55 container.find("button[data-bs-target$='_edit']").tab("show");
58 function updateHelp() {
59 $(".richtext_container .richtext_help_sidebar:not(:visible):not(:empty)").each(function () {
60 var container = $(this).closest(".richtext_container");
61 $(this).children().appendTo(container.find(".tab-pane[id$='_help']"));
63 $(".richtext_container .richtext_help_sidebar:visible:empty").each(function () {
64 var container = $(this).closest(".richtext_container");
65 container.find(".tab-pane[id$='_help']").children().appendTo($(this));
66 if (container.find("button[data-bs-target$='_help'].active").length) {
67 container.find("button[data-bs-target$='_edit']").tab("show");