1 $(document).ready(function () {
 
   2   /* Hide the preview panes */
 
   3   $(".richtext_preview").hide();
 
   6    * When the text in an edit pane is changed, clear the contents of
 
   7    * the associated preview pne so that it will be regenerated when
 
   8    * the user next switches to it.
 
  10   $(".richtext_content textarea").change(function () {
 
  11     $(this).parents(".richtext_container").find(".richtext_preview").empty();
 
  14   /* Disable all the edit buttons */
 
  15   $(".richtext_doedit").prop("disabled", true);
 
  17   /* Enable the preview buttons */
 
  18   $(".richtext_dopreview").prop("disabled", false);
 
  21    * Install a click handler to switch to edit mode when the
 
  22    * edit button is pressed.
 
  24   $(".richtext_doedit").click(function (event) {
 
  25     var editor = $(this).parents(".richtext_container").find("textarea");
 
  26     var preview = $(this).parents(".richtext_container").find(".richtext_preview");
 
  31     $(this).siblings(".richtext_dopreview").prop("disabled", false);
 
  32     $(this).prop("disabled", true);
 
  34     event.preventDefault();
 
  38    * Install a click handler to switch to preview mode when the
 
  39    * preview button is pressed.
 
  41   $(".richtext_dopreview").click(function (event) {
 
  42     var editor = $(this).parents(".richtext_container").find("textarea");
 
  43     var preview = $(this).parents(".richtext_container").find(".richtext_preview");
 
  44     var minHeight = editor.outerHeight() - preview.outerHeight() + preview.height();
 
  46     if (preview.contents().length === 0) {
 
  47       preview.oneTime(500, "loading", function () {
 
  48         preview.addClass("loading");
 
  51       preview.load(editor.data("previewUrl"), { text: editor.val() }, function () {
 
  52         preview.stopTime("loading");
 
  53         preview.removeClass("loading");
 
  58     preview.css("min-height", minHeight + "px");
 
  61     $(this).siblings(".richtext_doedit").prop("disabled", false);
 
  62     $(this).prop("disabled", true);
 
  64     event.preventDefault();