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");
 
  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   $(document).on("hide.bs.tab", ".richtext_container button[data-bs-target$='_edit']", 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   $(document).on("show.bs.tab", ".richtext_container button[data-bs-target$='_preview']", 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   $(window).on("resize", updateHelp);
 
  48   $(document).on("turbo:load", function () {
 
  49     $(".richtext_container textarea").on("invalid", invalidTextareaListener);
 
  53   function invalidTextareaListener() {
 
  54     var container = $(this).closest(".richtext_container");
 
  56     container.find("button[data-bs-target$='_edit']").tab("show");
 
  59   function updateHelp() {
 
  60     $(".richtext_container .richtext_help_sidebar:not(:visible):not(:empty)").each(function () {
 
  61       var container = $(this).closest(".richtext_container");
 
  62       $(this).children().appendTo(container.find(".tab-pane[id$='_help']"));
 
  64     $(".richtext_container .richtext_help_sidebar:visible:empty").each(function () {
 
  65       var container = $(this).closest(".richtext_container");
 
  66       container.find(".tab-pane[id$='_help']").children().appendTo($(this));
 
  67       if (container.find("button[data-bs-target$='_help'].active").length) {
 
  68         container.find("button[data-bs-target$='_edit']").tab("show");