Remove HTML data attributes from thumbnails #4943
Remove most data attributes from thumbnails, except the ones used by our own Javascript.
This commit is contained in:
@@ -90,36 +90,14 @@ class PostPreviewComponent < ApplicationComponent
|
|||||||
end
|
end
|
||||||
|
|
||||||
def data_attributes
|
def data_attributes
|
||||||
attributes = {
|
{
|
||||||
"data-id" => post.id,
|
"data-id" => post.id,
|
||||||
"data-has-sound" => has_sound?,
|
|
||||||
"data-tags" => post.tag_string,
|
"data-tags" => post.tag_string,
|
||||||
"data-approver-id" => post.approver_id,
|
|
||||||
"data-rating" => post.rating,
|
"data-rating" => post.rating,
|
||||||
"data-large-width" => post.large_image_width,
|
|
||||||
"data-large-height" => post.large_image_height,
|
|
||||||
"data-width" => post.image_width,
|
|
||||||
"data-height" => post.image_height,
|
|
||||||
"data-flags" => post.status_flags,
|
"data-flags" => post.status_flags,
|
||||||
"data-parent-id" => post.parent_id,
|
|
||||||
"data-has-children" => post.has_children?,
|
|
||||||
"data-score" => post.score,
|
"data-score" => post.score,
|
||||||
"data-fav-count" => post.fav_count,
|
|
||||||
"data-pixiv-id" => post.pixiv_id,
|
|
||||||
"data-file-ext" => post.file_ext,
|
|
||||||
"data-source" => post.source,
|
|
||||||
"data-uploader-id" => post.uploader_id,
|
"data-uploader-id" => post.uploader_id,
|
||||||
"data-normalized-source" => post.normalized_source,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if post.visible?(current_user)
|
|
||||||
attributes["data-md5"] = post.md5
|
|
||||||
attributes["data-file-url"] = post.file_url
|
|
||||||
attributes["data-large-file-url"] = post.large_file_url
|
|
||||||
attributes["data-preview-file-url"] = post.preview_file_url
|
|
||||||
end
|
|
||||||
|
|
||||||
attributes
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_sound?
|
def has_sound?
|
||||||
|
|||||||
@@ -43,4 +43,27 @@ module PostsHelper
|
|||||||
def is_danbirthday?(post)
|
def is_danbirthday?(post)
|
||||||
post.id == 1 && post.created_at.strftime("%m-%d") == Time.zone.today.strftime("%m-%d")
|
post.id == 1 && post.created_at.strftime("%m-%d") == Time.zone.today.strftime("%m-%d")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def image_container_data_attributes(post, current_user)
|
||||||
|
attributes = {
|
||||||
|
"data-id" => post.id,
|
||||||
|
"data-tags" => post.tag_string,
|
||||||
|
"data-rating" => post.rating,
|
||||||
|
"data-large-width" => post.large_image_width,
|
||||||
|
"data-large-height" => post.large_image_height,
|
||||||
|
"data-width" => post.image_width,
|
||||||
|
"data-height" => post.image_height,
|
||||||
|
"data-flags" => post.status_flags,
|
||||||
|
"data-score" => post.score,
|
||||||
|
"data-uploader-id" => post.uploader_id,
|
||||||
|
"data-source" => post.source,
|
||||||
|
"data-normalized-source" => post.normalized_source,
|
||||||
|
}
|
||||||
|
|
||||||
|
if post.visible?(current_user)
|
||||||
|
attributes["data-file-url"] = post.file_url
|
||||||
|
end
|
||||||
|
|
||||||
|
attributes
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
|
|
||||||
<%= render "posts/partials/show/notices", :post => @post %>
|
<%= render "posts/partials/show/notices", :post => @post %>
|
||||||
|
|
||||||
<%= tag.section class: ["image-container", "note-container", ("danbirthday" if is_danbirthday?(@post))], **PostPreviewComponent.new(post: @post).data_attributes do -%>
|
<%= tag.section class: ["image-container", "note-container", ("danbirthday" if is_danbirthday?(@post))], **image_container_data_attributes(@post, CurrentUser.user) do -%>
|
||||||
<%= render "posts/partials/show/embedded", post: @post %>
|
<%= render "posts/partials/show/embedded", post: @post %>
|
||||||
<div id="note-preview"></div>
|
<div id="note-preview"></div>
|
||||||
<% end -%>
|
<% end -%>
|
||||||
|
|||||||
Reference in New Issue
Block a user