- $(".richtext_dopreview").click(function () {
- var editor = $(this).parents(".richtext_container").find("textarea");
- var preview = $(this).parents(".richtext_container").find(".richtext_preview");
- var minHeight = editor.outerHeight() - preview.outerHeight() + preview.height();
-
- if (preview.contents().length === 0) {
- preview.oneTime(500, "loading", function () {
- preview.addClass("loading");
- });
-
- preview.load(editor.data("previewUrl"), { text: editor.val() }, function () {
- preview.stopTime("loading");
- preview.removeClass("loading");
- });
+ $(document).on("show.bs.tab", ".richtext_container button[data-bs-target$='_preview']", function () {
+ const container = $(this).closest(".richtext_container");
+ const editor = container.find("textarea");
+ const preview = container.find(".tab-pane[id$='_preview']");
+
+ if (preview.children(".richtext").contents().length === 0) {
+ preview.children(".richtext_placeholder").removeAttr("hidden").addClass("delayed-fade-in");
+
+ fetch(editor.data("previewUrl"), {
+ method: "POST",
+ body: new URLSearchParams({ text: editor.val(), ...OSM.csrf })
+ })
+ .then(r => r.text())
+ .then(html => {
+ preview.children(".richtext").html(html);
+ preview.children(".richtext_placeholder").attr("hidden", true).removeClass("delayed-fade-in");
+ });