[DText] Explicitly set when color is allowed in preview (#665)

This commit is contained in:
Donovan Daniels 2024-07-20 12:19:40 -05:00 committed by GitHub
parent b28bb5c99f
commit 4ff4c3718e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 28 additions and 27 deletions

View File

@ -3,7 +3,7 @@
class DtextPreviewsController < ApplicationController class DtextPreviewsController < ApplicationController
def create def create
body = params[:body] || "" 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 } render json: { html: dtext, posts: deferred_posts }
end end
end end

View File

@ -9,7 +9,7 @@ class DtextInput < SimpleForm::Inputs::TextInput
end end
merged_input_options = merge_wrapper_options(input_html_options, wrapper_options) 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 end
def input_html_classes def input_html_classes

View File

@ -6,6 +6,7 @@ DText.initialze_input = function ($element) {
const $preview = $(".dtext-formatter-preview", $element); const $preview = $(".dtext-formatter-preview", $element);
const $textarea = $(".dtext-formatter-input", $element); const $textarea = $(".dtext-formatter-input", $element);
const $charcount = $(".dtext-formatter-charcount", $element); const $charcount = $(".dtext-formatter-charcount", $element);
const allowColor = $element.attr("data-allow-color") === "true";
// Tab switching // Tab switching
$(".dtext-formatter-tabs a", $element).on("click", event => { $(".dtext-formatter-tabs a", $element).on("click", event => {
@ -13,7 +14,7 @@ DText.initialze_input = function ($element) {
if ($element.attr("data-editing") == "true") { if ($element.attr("data-editing") == "true") {
$preview.css("min-height", $textarea.outerHeight()); $preview.css("min-height", $textarea.outerHeight());
$element.attr("data-editing", "false"); $element.attr("data-editing", "false");
update_preview($textarea, $preview); update_preview($textarea, $preview, allowColor);
} else { } else {
$element.attr("data-editing", "true"); $element.attr("data-editing", "true");
$preview.attr("loading", "false"); $preview.attr("loading", "false");
@ -47,7 +48,7 @@ DText.initialize_formatting_buttons = function (element) {
}; };
/** Refreshes the preview field to match the provided input */ /** 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(); const currentText = input.val().trim();
// The input is empty, reset everything // The input is empty, reset everything
@ -67,9 +68,9 @@ function update_preview (input, preview) {
SendQueue.add(() => { SendQueue.add(() => {
$.ajax({ $.ajax({
type: "post", type: "post",
url: "/dtext_preview", url: "/dtext_preview.json",
dataType: "json", dataType: "json",
data: { body: currentText }, data: { body: currentText, allow_color: allowColor },
success: (response) => { success: (response) => {
// The loading was cancelled, since the user toggled back // The loading was cancelled, since the user toggled back

View File

@ -436,7 +436,7 @@ let Note = {
var text = $textarea.val(); var text = $textarea.val();
$note_body.data("original-body", text); $note_body.data("original-body", text);
Note.Body.set_text($note_body, $note_box, "Loading..."); 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.set_text($note_body, $note_box, data.html);
Note.Box.resize_inner_border($note_box); Note.Box.resize_inner_border($note_box);
$note_body.show(); $note_body.show();
@ -470,7 +470,7 @@ let Note = {
var $note_box = Note.Box.find(id); var $note_box = Note.Box.find(id);
$note_box.find(".note-box-inner-border").addClass("unsaved"); $note_box.find(".note-box-inner-border").addClass("unsaved");
Note.Body.set_text($note_body, $note_box, "Loading..."); 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.set_text($note_body, $note_box, data.html);
$note_body.show(); $note_body.show();
$(window).trigger("e621:add_deferred_posts", data.posts); $(window).trigger("e621:add_deferred_posts", data.posts);

View File

@ -203,7 +203,7 @@
<label class="section-label" for="post_description">Description</label> <label class="section-label" for="post_description">Description</label>
</div> </div>
<div class="col2"> <div class="col2">
<%= ApplicationController.new.render_to_string(partial: "dtext_input", locals: { limit: Danbooru.config.post_descr_max_size, textarea: '<textarea class="dtext-formatter-input tag-textarea dtext" id="post_description" rows="10" v-model="description"></textarea>'.html_safe }) %> <%= ApplicationController.new.render_to_string(partial: "dtext_input", locals: { limit: Danbooru.config.post_descr_max_size, textarea: '<textarea class="dtext-formatter-input tag-textarea dtext" id="post_description" rows="10" v-model="description"></textarea>'.html_safe, allow_color: true }) %>
</div> </div>
</div> </div>
<div v-if="allowUploadAsPending" class="flex-grid border-bottom"> <div v-if="allowUploadAsPending" class="flex-grid border-bottom">

View File

@ -1,6 +1,6 @@
<%= error_messages_for :staff_note %> <%= error_messages_for :staff_note %>
<%= custom_form_for(staff_note, url: user_staff_notes_path(user_id: user.id), method: :post) do |f| %> <%= custom_form_for(staff_note, url: user_staff_notes_path(user_id: user.id), method: :post) do |f| %>
<%= f.input :body, as: :dtext, label: false %> <%= f.input :body, as: :dtext, label: false, allow_color: true %>
<%= f.button :submit, "Submit" %> <%= f.button :submit, "Submit" %>
<% end %> <% end %>

View File

@ -18,8 +18,8 @@
<%= select_tag("user[enable_privacy_mode]", options_for_select([["Yes", true], ["No", false]], @user.enable_privacy_mode?)) %> <%= select_tag("user[enable_privacy_mode]", options_for_select([["Yes", true], ["No", false]], @user.enable_privacy_mode?)) %>
</div> </div>
<%= f.input :profile_about, as: :dtext, label: "About", limit: Danbooru.config.user_about_max_size %> <%= f.input :profile_about, as: :dtext, label: "About", limit: Danbooru.config.user_about_max_size, allow_color: true %>
<%= f.input :profile_artinfo, as: :dtext, label: "Commission Info", limit: Danbooru.config.user_about_max_size %> <%= f.input :profile_artinfo, as: :dtext, label: "Commission Info", limit: Danbooru.config.user_about_max_size, allow_color: true %>
<%= f.input :base_upload_limit %> <%= f.input :base_upload_limit %>
<% if CurrentUser.is_bd_staff? || !@user.is_bd_staff? %> <% if CurrentUser.is_bd_staff? || !@user.is_bd_staff? %>

View File

@ -1,4 +1,4 @@
<div class="dtext-formatter" data-editing="true" data-initialized="false"> <div class="dtext-formatter" data-editing="true" data-initialized="false" data-allow-color="<%= allow_color %>">
<div class="dtext-formatter-tabs"> <div class="dtext-formatter-tabs">
<a data-action="edit" role="tab">Write</a> <a data-action="edit" role="tab">Write</a>
<a data-action="show" role="tab">Preview</a> <a data-action="show" role="tab">Preview</a>

View File

@ -18,6 +18,6 @@
<% if @artist.is_note_locked? %> <% if @artist.is_note_locked? %>
<p>Artist is note locked. Notes cannot be edited.</p> <p>Artist is note locked. Notes cannot be edited.</p>
<% end %> <% 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" %> <%= f.button :submit, "Submit" %>
<% end %> <% end %>

View File

@ -4,7 +4,7 @@
<% if @artist.notes.present? && @artist.visible? %> <% if @artist.notes.present? && @artist.visible? %>
<div class="dtext-container"> <div class="dtext-container">
<%= format_text(@artist.notes) %> <%= format_text(@artist.notes, allow_color: true) %>
</div> </div>
<p><%= link_to "View wiki page", @artist.wiki_page %></p> <p><%= link_to "View wiki page", @artist.wiki_page %></p>

View File

@ -5,6 +5,6 @@
<% end %> <% end %>
<%= f.input :duration, :hint => "in days" %> <%= f.input :duration, :hint => "in days" %>
<%= f.input :is_permaban, as: :boolean, hint: 'ignores 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" %> <%= f.button :submit, :value => "Ban" %>
<% end %> <% end %>

View File

@ -2,6 +2,6 @@
<%= custom_form_for(dmail) do |f| %> <%= custom_form_for(dmail) do |f| %>
<%= f.input :to_name, label: "To", autocomplete: "user", input_html: { value: dmail.to.try(:name) } %> <%= 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 :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..." } %> <%= f.button :submit, "Send", data: { disable_with: "Sending..." } %>
<% end %> <% end %>

View File

@ -1,4 +1,4 @@
<%= custom_form_for(@news_update) do |f| %> <%= custom_form_for(@news_update) do |f| %>
<%= f.input :message, as: :dtext %> <%= f.input :message, as: :dtext, allow_color: false %>
<%= f.button :submit, "Submit" %> <%= f.button :submit, "Submit" %>
<% end %> <% end %>

View File

@ -1 +1 @@
<article data-width="<%= note.width %>" data-height="<%= note.height %>" data-x="<%= note.x %>" data-y="<%= note.y %>" data-id="<%= note.id %>" data-body="<%= note.body %>"><%= format_text(note.body) %></article> <article data-width="<%= note.width %>" data-height="<%= note.height %>" data-x="<%= note.x %>" data-y="<%= note.y %>" data-id="<%= note.id %>" data-body="<%= note.body %>"><%= format_text(note.body, allow_color: true) %></article>

View File

@ -6,7 +6,7 @@
<%= error_messages_for "pool" %> <%= error_messages_for "pool" %>
<%= f.input :name, :as => :string, :input_html => { :value => @pool.pretty_name } %> <%= f.input :name, :as => :string, :input_html => { :value => @pool.pretty_name } %>
<%= f.input :description, as: :dtext, limit: Danbooru.config.pool_descr_max_size %> <%= f.input :description, as: :dtext, limit: Danbooru.config.pool_descr_max_size, allow_color: false %>
<%= f.input :post_ids_string, as: :text, label: "Posts" %> <%= f.input :post_ids_string, as: :text, label: "Posts" %>
<%= f.input :category, :collection => ["series", "collection"], :include_blank => false %> <%= f.input :category, :collection => ["series", "collection"], :include_blank => false %>
<%= f.input :is_active %> <%= f.input :is_active %>

View File

@ -6,7 +6,7 @@
<%= custom_form_for(@pool) do |f| %> <%= custom_form_for(@pool) do |f| %>
<%= f.input :name, :as => :string, :required => true %> <%= f.input :name, :as => :string, :required => true %>
<%= f.input :description, as: :dtext, limit: Danbooru.config.pool_descr_max_size %> <%= f.input :description, as: :dtext, limit: Danbooru.config.pool_descr_max_size, allow_color: false %>
<%= f.input :post_ids_string, as: :text, label: "Posts" %> <%= f.input :post_ids_string, as: :text, label: "Posts" %>
<%= f.input :category, :collection => ["series", "collection"], :include_blank => true, :selected => "", :required => true %> <%= f.input :category, :collection => ["series", "collection"], :include_blank => true, :selected => "", :required => true %>
<%= f.input :is_active %> <%= f.input :is_active %>

View File

@ -5,7 +5,7 @@
<%= f.input :shortname, label: 'Short Name', as: :string, <%= f.input :shortname, label: 'Short Name', as: :string,
hint: "The short name is used for the set's metatag name. Can only contain letters, numbers, and underscores hint: "The short name is used for the set's metatag name. Can only contain letters, numbers, and underscores
and must contain at least one letter or underscore. <a href=\"/post?tags=set%3Aexample\">set:example</a>".html_safe %> and must contain at least one letter or underscore. <a href=\"/post?tags=set%3Aexample\">set:example</a>".html_safe %>
<%= f.input :description, as: :dtext, limit: Danbooru.config.pool_descr_max_size %> <%= f.input :description, as: :dtext, limit: Danbooru.config.pool_descr_max_size, allow_color: false %>
<%= f.input :is_public, label: "Public", hint: "Private sets are only visible to you. Public sets are visible to anyone, but only you and users you <%= f.input :is_public, label: "Public", hint: "Private sets are only visible to you. Public sets are visible to anyone, but only you and users you
assign as maintainers can edit the set. Only accounts three days or older can make public sets." %> assign as maintainers can edit the set. Only accounts three days or older can make public sets." %>

View File

@ -42,7 +42,7 @@
<%= f.input :source, as: :text, label: "Sources", input_html: { size: "60x5", spellcheck: false } %> <%= f.input :source, as: :text, label: "Sources", input_html: { size: "60x5", spellcheck: false } %>
<div class="input"> <div class="input">
<%= f.input :description, as: :dtext, limit: Danbooru.config.post_descr_max_size %> <%= f.input :description, as: :dtext, limit: Danbooru.config.post_descr_max_size, allow_color: true %>
</div> </div>
<% if CurrentUser.is_privileged? %> <% if CurrentUser.is_privileged? %>

View File

@ -6,6 +6,6 @@
<% unless user_feedback.new_record? %> <% unless user_feedback.new_record? %>
<%= f.input :send_update_dmail, label: "Send update DMail", as: :boolean %> <%= f.input :send_update_dmail, label: "Send update DMail", as: :boolean %>
<% end %> <% end %>
<%= f.input :body, as: :dtext, limit: Danbooru.config.user_feedback_max_size %> <%= f.input :body, as: :dtext, limit: Danbooru.config.user_feedback_max_size, allow_color: false %>
<%= f.button :submit, "Submit" %> <%= f.button :submit, "Submit" %>
<% end %> <% end %>

View File

@ -34,9 +34,9 @@
<%= f.input :avatar_id, as: :string, label: "Avatar Post ID" %> <%= f.input :avatar_id, as: :string, label: "Avatar Post ID" %>
<%= f.input :profile_about, as: :dtext, label: "About Me", limit: Danbooru.config.user_about_max_size %> <%= f.input :profile_about, as: :dtext, label: "About Me", limit: Danbooru.config.user_about_max_size, allow_color: true %>
<%= f.input :profile_artinfo, as: :dtext, label: "Commission Info", limit: Danbooru.config.user_about_max_size %> <%= f.input :profile_artinfo, as: :dtext, label: "Commission Info", limit: Danbooru.config.user_about_max_size, allow_color: true %>
<%= f.input :time_zone, :include_blank => false %> <%= f.input :time_zone, :include_blank => false %>

View File

@ -10,7 +10,7 @@
<h1 id="wiki-page-title"><%= @wiki_page.pretty_title %></h1> <h1 id="wiki-page-title"><%= @wiki_page.pretty_title %></h1>
<% end %> <% end %>
<%= f.input :body, as: :dtext, limit: Danbooru.config.wiki_page_max_size %> <%= f.input :body, as: :dtext, limit: Danbooru.config.wiki_page_max_size, allow_color: true %>
<% if CurrentUser.is_janitor? && @wiki_page.is_deleted? %> <% if CurrentUser.is_janitor? && @wiki_page.is_deleted? %>
<%= f.input :is_deleted, :label => "Deleted", :hint => "Uncheck to restore this wiki page" %> <%= f.input :is_deleted, :label => "Deleted", :hint => "Uncheck to restore this wiki page" %>