From c01ef54a71e1d176357854d9d302f9a9639fe05f Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Thu, 19 Dec 2019 02:02:08 -0500 Subject: [PATCH] avoid showing massive spoiler boxes in forums --- lib/philomena/textile/renderer.ex | 8 +++--- .../templates/image/_image_target.html.slime | 28 +++++++++++++++---- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/lib/philomena/textile/renderer.ex b/lib/philomena/textile/renderer.ex index e57b4a0f..5eef301b 100644 --- a/lib/philomena/textile/renderer.ex +++ b/lib/philomena/textile/renderer.ex @@ -79,15 +79,15 @@ defmodule Philomena.Textile.Renderer do match [image, "p"] -> - Phoenix.View.render(PhilomenaWeb.ImageView, "_image_container.html", image: image, size: :medium, conn: conn) + Phoenix.View.render(PhilomenaWeb.ImageView, "_image_target.html", image: image, size: :medium, conn: conn) |> safe_to_string() [image, "t"] -> - Phoenix.View.render(PhilomenaWeb.ImageView, "_image_container.html", image: image, size: :small, conn: conn) + Phoenix.View.render(PhilomenaWeb.ImageView, "_image_target.html", image: image, size: :small, conn: conn) |> safe_to_string() [image, "s"] -> - Phoenix.View.render(PhilomenaWeb.ImageView, "_image_container.html", image: image, size: :thumb_small, conn: conn) + Phoenix.View.render(PhilomenaWeb.ImageView, "_image_target.html", image: image, size: :thumb_small, conn: conn) |> safe_to_string() [image] -> @@ -112,4 +112,4 @@ defmodule Philomena.Textile.Renderer do |> Repo.all() |> Map.new(fn image -> {image.id, image} end) end -end \ No newline at end of file +end diff --git a/lib/philomena_web/templates/image/_image_target.html.slime b/lib/philomena_web/templates/image/_image_target.html.slime index febf65eb..bbe5b338 100644 --- a/lib/philomena_web/templates/image/_image_target.html.slime +++ b/lib/philomena_web/templates/image/_image_target.html.slime @@ -1,4 +1,6 @@ -= content_tag :div, [data: image_container_data(@conn, @image, :full), class: "image-show-container"] do +- size = assigns[:size] || :full + += content_tag :div, [data: image_container_data(@conn, @image, size), class: "image-show-container"] do .block.block--fixed.block--warning.block--no-margin.image-filtered.hidden strong = link("This image is blocked by your current filter - click here to display it anyway", to: "#", data: [click_unfilter: @image.id]) @@ -8,8 +10,22 @@ =< link("your current filter", to: Routes.filter_path(@conn, :show, @conn.assigns.current_filter), class: "filter-link") ' . - #image_target.hidden.image-show data-scaled=scaled_value(@conn.assigns.current_user) data-uris=Jason.encode!(thumb_urls(@image, can?(@conn, :hide, @image))) data-width=@image.image_width data-height=@image.image_height - = if @image.image_mime_type == "video/webm" do - video controls=true - - else - picture \ No newline at end of file + = if size == :full do + #image_target.hidden.image-show data-scaled=scaled_value(@conn.assigns.current_user) data-uris=Jason.encode!(thumb_urls(@image, can?(@conn, :hide, @image))) data-width=@image.image_width data-height=@image.image_height + = if @image.image_mime_type == "video/webm" do + video controls=true + - else + picture + - else + .image-show.hidden + a href=Routes.image_path(@conn, :show, @image) + span.imgspoiler + - thumb_url = thumb_url(@image, can?(@conn, :show, @image), size) + + = if @image.image_mime_type == "video/webm" do + video data-image-id=@image.id autoplay="autoplay" loop="loop" muted="muted" playsinline="playsinline" + source src=thumb_url type="video/webm" + source src=String.replace(thumb_url, ".webm", ".mp4") type="video/mp4" + - else + picture data-image-id=@image.id + img src=thumb_url