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 () {
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);
36 * Install a click handler to switch to preview mode when the
37 * preview button is pressed.
39 $(".richtext_dopreview").click(function () {
40 var editor = $(this).parents(".richtext_container").find("textarea");
41 var preview = $(this).parents(".richtext_container").find(".richtext_preview");
42 var minHeight = editor.outerHeight() - preview.outerHeight() + preview.height();
44 if (preview.contents().length === 0) {
45 preview.oneTime(500, "loading", function () {
46 preview.addClass("loading");
49 preview.load(editor.data("previewUrl"), { text: editor.val() }, function () {
50 preview.stopTime("loading");
51 preview.removeClass("loading");
56 preview.css("min-height", minHeight + "px");
59 $(this).siblings(".richtext_doedit").prop("disabled", false);
60 $(this).prop("disabled", true);