Fix dtext preview button to use event delegation.
Fixes the dtext preview button and dtext expandable to work with dynamically loaded dtext forms.
This commit is contained in:
@@ -181,10 +181,8 @@ module ApplicationHelper
|
|||||||
render "dtext/form", options
|
render "dtext/form", options
|
||||||
end
|
end
|
||||||
|
|
||||||
def dtext_preview_button(object, name, options = {})
|
def dtext_preview_button(object, name, input_id: "#{object}_#{name}", preview_id: "dtext-preview")
|
||||||
options[:input_id] ||= "#{object}_#{name}"
|
tag.input value: "Preview", type: "button", class: "dtext-preview-button", "data-input-id": input_id, "data-preview-id": preview_id
|
||||||
options[:preview_id] ||= "dtext-preview"
|
|
||||||
submit_tag("Preview", "data-input-id" => options[:input_id], "data-preview-id" => options[:preview_id])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def search_field(method, label: method.titleize, hint: nil, value: nil, **attributes)
|
def search_field(method, label: method.titleize, hint: nil, value: nil, **attributes)
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ Comment.initialize_all = function() {
|
|||||||
|
|
||||||
$(window).on("danbooru:index_for_post", (_event, post_id, current_comment_section) => {
|
$(window).on("danbooru:index_for_post", (_event, post_id, current_comment_section) => {
|
||||||
$("#threshold-comments-notice-for-" + post_id).hide();
|
$("#threshold-comments-notice-for-" + post_id).hide();
|
||||||
Dtext.initialize_expandables(current_comment_section);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,12 +6,11 @@ Dtext.initialize_all = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Dtext.initialize_links = function() {
|
Dtext.initialize_links = function() {
|
||||||
$(".simple_form input[value=Preview]").on("click.danbooru", Dtext.click_button);
|
$(document).on("click.danbooru", ".dtext-preview-button", Dtext.click_button);
|
||||||
}
|
}
|
||||||
|
|
||||||
Dtext.initialize_expandables = function($parent) {
|
Dtext.initialize_expandables = function() {
|
||||||
$parent = $parent || $(document);
|
$(document).on("click.danbooru", ".expandable-button", function(e) {
|
||||||
$parent.find(".expandable-button").on("click.danbooru", function(e) {
|
|
||||||
var button = $(this);
|
var button = $(this);
|
||||||
button.parent().next().fadeToggle("fast");
|
button.parent().next().fadeToggle("fast");
|
||||||
if (button.val() === "Show") {
|
if (button.val() === "Show") {
|
||||||
@@ -34,7 +33,6 @@ Dtext.call_preview = function(e, $button, $input, $preview) {
|
|||||||
},
|
},
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
$preview.html(data).fadeIn("fast");
|
$preview.html(data).fadeIn("fast");
|
||||||
Dtext.initialize_expandables($preview);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user