Skip to content

Commit

Permalink
Restore loading spinner in richtext previews
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonKhorev committed Nov 8, 2024
1 parent 3a1b4cb commit a05692a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
14 changes: 8 additions & 6 deletions app/assets/javascripts/richtext.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
*/
$(document).on("change", ".richtext_container textarea", function () {
var container = $(this).closest(".richtext_container");
var preview = container.find(".tab-pane[id$='_preview']");

container.find(".tab-pane[id$='_preview']").empty();
preview.children(".richtext_placeholder").attr("hidden", true);
preview.children(".richtext").empty();
});

/*
Expand All @@ -31,14 +33,14 @@
var editor = container.find("textarea");
var preview = container.find(".tab-pane[id$='_preview']");

if (preview.contents().length === 0) {
preview.oneTime(500, "loading", function () {
preview.addClass("loading");
if (preview.children(".richtext").contents().length === 0) {
preview.oneTime(200, "loading", function () {
preview.children(".richtext_placeholder").removeAttr("hidden");
});

preview.load(editor.data("previewUrl"), { text: editor.val() }, function () {
preview.children(".richtext").load(editor.data("previewUrl"), { text: editor.val() }, function () {
preview.stopTime("loading");
preview.removeClass("loading");
preview.children(".richtext_placeholder").attr("hidden", true);
});
}
});
Expand Down
9 changes: 8 additions & 1 deletion app/views/shared/_richtext_field.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@
<div id="<%= id %>_edit" class="tab-pane show active">
<%= builder.text_area(attribute, options.merge(:wrapper => false, "data-preview-url" => preview_url(:type => type))) %>
</div>
<div id="<%= id %>_preview" class="tab-pane richtext text-break"></div>
<div id="<%= id %>_preview" class="tab-pane">
<div class="richtext_placeholder text-center py-5" hidden>
<div class="spinner-border" role="status">
<span class="visually-hidden"><%= t("browse.start_rjs.loading") %></span>
</div>
</div>
<div class="richtext text-break"></div>
</div>
<div id="<%= id %>_help" class="tab-pane">
<div class="card bg-body-tertiary h-100">
<div class="card-body">
Expand Down

0 comments on commit a05692a

Please sign in to comment.