diff --git a/app/controllers/dtext_previews_controller.rb b/app/controllers/dtext_previews_controller.rb index 221502baf..f021fe6f6 100644 --- a/app/controllers/dtext_previews_controller.rb +++ b/app/controllers/dtext_previews_controller.rb @@ -3,7 +3,7 @@ class DtextPreviewsController < ApplicationController def create body = params[:body] || "" - dtext = helpers.format_text(body, allow_color: CurrentUser.user.is_privileged?) + dtext = helpers.format_text(body, allow_color: params[:allow_color].to_s.truthy?) render json: { html: dtext, posts: deferred_posts } end end diff --git a/app/inputs/dtext_input.rb b/app/inputs/dtext_input.rb index d68aa564b..16c39f214 100644 --- a/app/inputs/dtext_input.rb +++ b/app/inputs/dtext_input.rb @@ -9,7 +9,7 @@ class DtextInput < SimpleForm::Inputs::TextInput end merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) - @builder.template.render("dtext_input", textarea: super(merged_input_options), limit: @options[:limit]) + @builder.template.render("dtext_input", textarea: super(merged_input_options), limit: @options[:limit], allow_color: @options.key?(:allow_color) ? @options[:allow_color] : CurrentUser.user.is_privileged?) end def input_html_classes diff --git a/app/javascript/src/javascripts/dtext.js b/app/javascript/src/javascripts/dtext.js index ba644c608..c64ba6f65 100644 --- a/app/javascript/src/javascripts/dtext.js +++ b/app/javascript/src/javascripts/dtext.js @@ -6,6 +6,7 @@ DText.initialze_input = function ($element) { const $preview = $(".dtext-formatter-preview", $element); const $textarea = $(".dtext-formatter-input", $element); const $charcount = $(".dtext-formatter-charcount", $element); + const allowColor = $element.attr("data-allow-color") === "true"; // Tab switching $(".dtext-formatter-tabs a", $element).on("click", event => { @@ -13,7 +14,7 @@ DText.initialze_input = function ($element) { if ($element.attr("data-editing") == "true") { $preview.css("min-height", $textarea.outerHeight()); $element.attr("data-editing", "false"); - update_preview($textarea, $preview); + update_preview($textarea, $preview, allowColor); } else { $element.attr("data-editing", "true"); $preview.attr("loading", "false"); @@ -47,7 +48,7 @@ DText.initialize_formatting_buttons = function (element) { }; /** Refreshes the preview field to match the provided input */ -function update_preview (input, preview) { +function update_preview (input, preview, allowColor = false) { const currentText = input.val().trim(); // The input is empty, reset everything @@ -67,9 +68,9 @@ function update_preview (input, preview) { SendQueue.add(() => { $.ajax({ type: "post", - url: "/dtext_preview", + url: "/dtext_preview.json", dataType: "json", - data: { body: currentText }, + data: { body: currentText, allow_color: allowColor }, success: (response) => { // The loading was cancelled, since the user toggled back diff --git a/app/javascript/src/javascripts/notes.js b/app/javascript/src/javascripts/notes.js index 3fc88a1c4..fe1b5cc14 100644 --- a/app/javascript/src/javascripts/notes.js +++ b/app/javascript/src/javascripts/notes.js @@ -436,7 +436,7 @@ let Note = { var text = $textarea.val(); $note_body.data("original-body", text); Note.Body.set_text($note_body, $note_box, "Loading..."); - $.post("/dtext_preview.json", {body: text}).then(function (data) { + $.post("/dtext_preview.json", { body: text, allow_color: true }).then(function (data) { Note.Body.set_text($note_body, $note_box, data.html); Note.Box.resize_inner_border($note_box); $note_body.show(); @@ -470,7 +470,7 @@ let Note = { var $note_box = Note.Box.find(id); $note_box.find(".note-box-inner-border").addClass("unsaved"); Note.Body.set_text($note_body, $note_box, "Loading..."); - $.post("/dtext_preview.json", {body: text}).then(function (data) { + $.post("/dtext_preview.json", { body: text, allow_color: true }).then(function (data) { Note.Body.set_text($note_body, $note_box, data.html); $note_body.show(); $(window).trigger("e621:add_deferred_posts", data.posts); diff --git a/app/javascript/src/javascripts/uploader/uploader.vue.erb b/app/javascript/src/javascripts/uploader/uploader.vue.erb index 1fc705fb2..f29d32f1a 100644 --- a/app/javascript/src/javascripts/uploader/uploader.vue.erb +++ b/app/javascript/src/javascripts/uploader/uploader.vue.erb @@ -203,7 +203,7 @@
Artist is note locked. Notes cannot be edited.
<% end %> - <%= f.input :notes, as: :dtext, limit: Danbooru.config.wiki_page_max_size, disabled: @artist.is_note_locked? %> + <%= f.input :notes, as: :dtext, limit: Danbooru.config.wiki_page_max_size, disabled: @artist.is_note_locked?, allow_color: true %> <%= f.button :submit, "Submit" %> <% end %> diff --git a/app/views/artists/_show.html.erb b/app/views/artists/_show.html.erb index 857ef9b36..6ad252634 100644 --- a/app/views/artists/_show.html.erb +++ b/app/views/artists/_show.html.erb @@ -4,7 +4,7 @@ <% if @artist.notes.present? && @artist.visible? %><%= link_to "View wiki page", @artist.wiki_page %>
diff --git a/app/views/bans/_form.html.erb b/app/views/bans/_form.html.erb index afc988b9b..09bdf8f64 100644 --- a/app/views/bans/_form.html.erb +++ b/app/views/bans/_form.html.erb @@ -5,6 +5,6 @@ <% end %> <%= f.input :duration, :hint => "in days" %> <%= f.input :is_permaban, as: :boolean, hint: 'ignores days' %> - <%= f.input :reason, as: :dtext %> + <%= f.input :reason, as: :dtext, allow_color: false %> <%= f.button :submit, :value => "Ban" %> <% end %> diff --git a/app/views/dmails/_form.html.erb b/app/views/dmails/_form.html.erb index b46cd6e08..379e572fc 100644 --- a/app/views/dmails/_form.html.erb +++ b/app/views/dmails/_form.html.erb @@ -2,6 +2,6 @@ <%= custom_form_for(dmail) do |f| %> <%= f.input :to_name, label: "To", autocomplete: "user", input_html: { value: dmail.to.try(:name) } %> <%= f.input :title, as: :string, input_html: { size: 100 } %> - <%= f.input :body, as: :dtext, limit: Danbooru.config.dmail_max_size %> + <%= f.input :body, as: :dtext, limit: Danbooru.config.dmail_max_size, allow_color: false %> <%= f.button :submit, "Send", data: { disable_with: "Sending..." } %> <% end %> diff --git a/app/views/news_updates/_form.html.erb b/app/views/news_updates/_form.html.erb index 748932d0d..80ead755d 100644 --- a/app/views/news_updates/_form.html.erb +++ b/app/views/news_updates/_form.html.erb @@ -1,4 +1,4 @@ <%= custom_form_for(@news_update) do |f| %> - <%= f.input :message, as: :dtext %> + <%= f.input :message, as: :dtext, allow_color: false %> <%= f.button :submit, "Submit" %> <% end %> diff --git a/app/views/notes/_note.html.erb b/app/views/notes/_note.html.erb index 4a71447f8..aaa5b4a6f 100644 --- a/app/views/notes/_note.html.erb +++ b/app/views/notes/_note.html.erb @@ -1 +1 @@ -