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 width = editor.outerWidth() - preview.outerWidth() + preview.width();
45 var minHeight = editor.outerHeight() - preview.outerHeight() + preview.height();
47 if (preview.contents().length === 0) {
48 preview.oneTime(500, "loading", function () {
49 preview.addClass("loading");
52 preview.load(editor.data("previewUrl"), { text: editor.val() }, function () {
53 preview.stopTime("loading");
54 preview.removeClass("loading");
60 preview.css("min-height", minHeight + "px");
63 $(this).siblings(".richtext_doedit").prop("disabled", false);
64 $(this).prop("disabled", true);
66 event.preventDefault();