mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 22:27:59 +01:00
Merge pull request #176 from philomena-dev/image-view-fix
Fix embedded image views for small images
This commit is contained in:
commit
c2dd9e84a3
7 changed files with 38 additions and 23 deletions
|
@ -168,7 +168,7 @@ span.spoiler div.image-container {
|
||||||
|
|
||||||
/* This and the one above needed for older browsers for some reason, appears to be a bug */
|
/* This and the one above needed for older browsers for some reason, appears to be a bug */
|
||||||
|
|
||||||
#image_target {
|
.image-target {
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { clearEl } from './utils/dom';
|
import { $$, clearEl } from './utils/dom';
|
||||||
import store from './utils/store';
|
import store from './utils/store';
|
||||||
|
|
||||||
const imageVersions = {
|
const imageVersions = {
|
||||||
|
@ -157,20 +157,19 @@ function bindImageForClick(target) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function bindImageTarget() {
|
function bindImageTarget(node = document) {
|
||||||
const target = document.getElementById('image_target');
|
$$('.image-target', node).forEach(target => {
|
||||||
if (!target) return;
|
|
||||||
|
|
||||||
pickAndResize(target);
|
|
||||||
|
|
||||||
if (target.dataset.mimeType === 'video/webm') {
|
|
||||||
// Don't interfere with media controls on video
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
bindImageForClick(target);
|
|
||||||
window.addEventListener('resize', () => {
|
|
||||||
pickAndResize(target);
|
pickAndResize(target);
|
||||||
|
|
||||||
|
if (target.dataset.mimeType === 'video/webm') {
|
||||||
|
// Don't interfere with media controls on video
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bindImageForClick(target);
|
||||||
|
window.addEventListener('resize', () => {
|
||||||
|
pickAndResize(target);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { fetchJson } from './utils/requests';
|
import { fetchJson } from './utils/requests';
|
||||||
|
import { bindImageTarget } from './image_expansion';
|
||||||
import { filterNode } from './imagesclientside';
|
import { filterNode } from './imagesclientside';
|
||||||
import { hideEl, showEl } from './utils/dom';
|
import { hideEl, showEl } from './utils/dom';
|
||||||
|
|
||||||
|
@ -49,6 +50,7 @@ function getPreview(body, anonymous, previewLoading, previewIdle, previewContent
|
||||||
.then(data => {
|
.then(data => {
|
||||||
previewContent.innerHTML = data;
|
previewContent.innerHTML = data;
|
||||||
filterNode(previewContent);
|
filterNode(previewContent);
|
||||||
|
bindImageTarget(previewContent);
|
||||||
showEl(previewIdle);
|
showEl(previewIdle);
|
||||||
hideEl(previewLoading);
|
hideEl(previewLoading);
|
||||||
});
|
});
|
||||||
|
|
|
@ -81,7 +81,7 @@ defmodule PhilomenaWeb.MarkdownRenderer do
|
||||||
[_id, "p"] when not img.hidden_from_users and img.approved ->
|
[_id, "p"] when not img.hidden_from_users and img.approved ->
|
||||||
Phoenix.View.render(@image_view, "_image_target.html",
|
Phoenix.View.render(@image_view, "_image_target.html",
|
||||||
image: img,
|
image: img,
|
||||||
size: :medium,
|
size: @image_view.select_version(img, :medium),
|
||||||
conn: conn
|
conn: conn
|
||||||
)
|
)
|
||||||
|> safe_to_string()
|
|> safe_to_string()
|
||||||
|
@ -89,7 +89,7 @@ defmodule PhilomenaWeb.MarkdownRenderer do
|
||||||
[_id, "t"] when not img.hidden_from_users and img.approved ->
|
[_id, "t"] when not img.hidden_from_users and img.approved ->
|
||||||
Phoenix.View.render(@image_view, "_image_target.html",
|
Phoenix.View.render(@image_view, "_image_target.html",
|
||||||
image: img,
|
image: img,
|
||||||
size: :small,
|
size: @image_view.select_version(img, :small),
|
||||||
conn: conn
|
conn: conn
|
||||||
)
|
)
|
||||||
|> safe_to_string()
|
|> safe_to_string()
|
||||||
|
@ -97,7 +97,7 @@ defmodule PhilomenaWeb.MarkdownRenderer do
|
||||||
[_id, "s"] when not img.hidden_from_users and img.approved ->
|
[_id, "s"] when not img.hidden_from_users and img.approved ->
|
||||||
Phoenix.View.render(@image_view, "_image_target.html",
|
Phoenix.View.render(@image_view, "_image_target.html",
|
||||||
image: img,
|
image: img,
|
||||||
size: :thumb_small,
|
size: @image_view.select_version(img, :thumb_small),
|
||||||
conn: conn
|
conn: conn
|
||||||
)
|
)
|
||||||
|> safe_to_string()
|
|> safe_to_string()
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
' .
|
' .
|
||||||
|
|
||||||
= if size == :full do
|
= 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 data-image-size=@image.image_size data-mime-type=@image.image_mime_type
|
.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 data-image-size=@image.image_size data-mime-type=@image.image_mime_type
|
||||||
= if @image.image_mime_type == "video/webm" do
|
= if @image.image_mime_type == "video/webm" do
|
||||||
video controls=true
|
video controls=true
|
||||||
- else
|
- else
|
||||||
|
|
|
@ -6,6 +6,8 @@ meta name="format-detection" content="telephone=no"
|
||||||
- image = @conn.assigns.image
|
- image = @conn.assigns.image
|
||||||
- filtered = not image.thumbnails_generated
|
- filtered = not image.thumbnails_generated
|
||||||
- description = "##{image.id} - #{Philomena.Images.tag_list(image)} - Derpibooru"
|
- description = "##{image.id} - #{Philomena.Images.tag_list(image)} - Derpibooru"
|
||||||
|
- thumb_large = ImageView.thumb_urls(image, false)[:large]
|
||||||
|
- thumb_rendered = ImageView.thumb_url(image, false, :rendered)
|
||||||
|
|
||||||
meta name="keywords" content=tag_list(image)
|
meta name="keywords" content=tag_list(image)
|
||||||
meta name="description" content=description
|
meta name="description" content=description
|
||||||
|
@ -25,16 +27,16 @@ meta name="format-detection" content="telephone=no"
|
||||||
= cond do
|
= cond do
|
||||||
- image.image_mime_type == "video/webm" and not filtered ->
|
- image.image_mime_type == "video/webm" and not filtered ->
|
||||||
meta property="og:type" content="video.other"
|
meta property="og:type" content="video.other"
|
||||||
meta property="og:image" content=ImageView.thumb_url(image, false, :rendered)
|
meta property="og:image" content=thumb_rendered
|
||||||
meta property="og:video" content=ImageView.thumb_url(image, false, :large)
|
meta property="og:video" content=thumb_large
|
||||||
|
|
||||||
- image.image_mime_type == "image/svg+xml" and not filtered ->
|
- image.image_mime_type == "image/svg+xml" and not filtered ->
|
||||||
meta property="og:type" content="website"
|
meta property="og:type" content="website"
|
||||||
meta property="og:image" content=ImageView.thumb_url(image, false, :rendered)
|
meta property="og:image" content=thumb_rendered
|
||||||
|
|
||||||
- not filtered ->
|
- not filtered ->
|
||||||
meta property="og:type" content="website"
|
meta property="og:type" content="website"
|
||||||
meta property="og:image" content=ImageView.thumb_url(image, false, :large)
|
meta property="og:image" content=thumb_large
|
||||||
|
|
||||||
- true ->
|
- true ->
|
||||||
meta property="og:type" content="website"
|
meta property="og:type" content="website"
|
||||||
|
|
|
@ -58,6 +58,18 @@ defmodule PhilomenaWeb.ImageView do
|
||||||
|> append_gif_urls(image, show_hidden)
|
|> append_gif_urls(image, show_hidden)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def select_version(image, version_name) do
|
||||||
|
Thumbnailer.thumbnail_versions()
|
||||||
|
|> Map.new(fn {name, {width, height}} ->
|
||||||
|
if image.image_width > width or image.image_height > height do
|
||||||
|
{name, version_name}
|
||||||
|
else
|
||||||
|
{name, :full}
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|> Map.get(version_name, :full)
|
||||||
|
end
|
||||||
|
|
||||||
defp append_full_url(urls, %{hidden_from_users: false} = image, _show_hidden),
|
defp append_full_url(urls, %{hidden_from_users: false} = image, _show_hidden),
|
||||||
do: Map.put(urls, :full, pretty_url(image, true, false))
|
do: Map.put(urls, :full, pretty_url(image, true, false))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue