1 $(document).ready(function () {
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 $(".richtext_container textarea").change(function () {
8 var container = $(this).closest(".richtext_container");
10 container.find(".tab-pane[id$='_preview']").empty();
14 * Install a handler to set the minimum preview pane height
15 * when switching away from an edit pane
17 $(".richtext_container button[data-bs-target$='_edit']").on("hide.bs.tab", function () {
18 var container = $(this).closest(".richtext_container");
19 var editor = container.find("textarea");
20 var preview = container.find(".tab-pane[id$='_preview']");
21 var minHeight = editor.outerHeight() - preview.outerHeight() + preview.height();
23 preview.css("min-height", minHeight + "px");
27 * Install a handler to switch to preview mode
29 $(".richtext_container button[data-bs-target$='_preview']").on("show.bs.tab", function () {
30 var container = $(this).closest(".richtext_container");
31 var editor = container.find("textarea");
32 var preview = container.find(".tab-pane[id$='_preview']");
34 if (preview.contents().length === 0) {
35 preview.oneTime(500, "loading", function () {
36 preview.addClass("loading");
39 preview.load(editor.data("previewUrl"), { text: editor.val() }, function () {
40 preview.stopTime("loading");
41 preview.removeClass("loading");
46 var updateHelp = function () {
47 $(".richtext_container .richtext_help_sidebar:not(:visible):not(:empty)").each(function () {
48 var container = $(this).closest(".richtext_container");
49 $(this).children().appendTo(container.find(".tab-pane[id$='_help']"));
51 $(".richtext_container .richtext_help_sidebar:visible:empty").each(function () {
52 var container = $(this).closest(".richtext_container");
53 container.find(".tab-pane[id$='_help']").children().appendTo($(this));
54 if (container.find("button[data-bs-target$='_help'].active").length) {
55 container.find("button[data-bs-target$='_edit']").tab("show");
61 $(window).on("resize", updateHelp);