]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/richtext.js
Remove non-existent image from leaflet URL map
[rails.git] / app / assets / javascripts / richtext.js
1 $(document).ready(function () {
2   /* Hide the preview panes */
3   $(".richtext_preview").hide();
4
5   /* 
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.
9    */
10   $(".richtext_content textarea").change(function () { 
11     $(this).parents(".richtext_container").find(".richtext_preview").empty();
12   });
13
14   /* Disable all the edit buttons */
15   $(".richtext_doedit").prop("disabled", true);
16
17   /* Enable the preview buttons */
18   $(".richtext_dopreview").prop("disabled", false);
19
20   /*
21    * Install a click handler to switch to edit mode when the
22    * edit button is pressed.
23    */
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");
27
28     preview.hide();
29     editor.show();
30
31     $(this).siblings(".richtext_dopreview").prop("disabled", false);
32     $(this).prop("disabled", true);
33
34     event.preventDefault();
35   });
36
37   /*
38    * Install a click handler to switch to preview mode when the
39    * preview button is pressed.
40    */
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();
46
47     if (preview.contents().length == 0) {
48       preview.oneTime(500, "loading", function () {
49         preview.addClass("loading");
50       });
51
52       preview.load(editor.data("previewUrl"), { text: editor.val() }, function () {
53         preview.stopTime("loading");
54         preview.removeClass("loading");
55       });
56     }
57
58     editor.hide();
59     preview.width(width);
60     preview.css("min-height", minHeight + "px");
61     preview.show();
62
63     $(this).siblings(".richtext_doedit").prop("disabled", false);
64     $(this).prop("disabled", true);
65
66     event.preventDefault();
67   });
68 });