Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An image viewer popup for thumbnails and image previews #1325

Merged
merged 2 commits into from
Jul 18, 2017

Conversation

astorije
Copy link
Member

@astorije astorije commented Jul 12, 2017

Inspired from #1130 for the styling, with some improved logic like support for Escape key.

screen shot 2017-07-12 at 03 00 33

TODOs

  • Split thumbnail and content into 2 adjacent links to make sure clicking on thumbnail margin opens the viewer (will also make code simpler)
    NB: Not sure why, but when I switched to this it fixed the image preview shrinking on master 🎉
  • Try to fix link going beyond image borders when resizing
  • Check / Make GPU taking care of animation

@astorije astorije added the Type: Feature Tickets that describe a desired feature or PRs that add them to the project. label Jul 12, 2017
@astorije astorije added this to the 2.4.0 milestone Jul 12, 2017
@astorije
Copy link
Member Author

The flexbox thing behind link/image on the viewer is kinda 💩. Play with resize, or wide images, and the button won't stick to the image anymore, and the link will be on the image + on big top/bottom margins.
Probably not the right way to go, but I have made an unreasonable amount of attempts, so I'd love some help :D (or maybe it's good enough for this PR and can be improved later, I'd vote for that!).

Reason why 2 links btw is because I don't want the black areas around the button to be clickable too. Only image and button are/should be clickable.

@MaxLeiter
Copy link
Member

Personally not sure how I feel about the open image button -- I think most people can figure out save as or drag to desktop. Overall great feature.

@MiniDigger
Copy link
Contributor

👍 on this one, I am currently using the one from bews PR and it works great.

what limits the size of the image? can't we make it bigger? I also don't like how the button looks, but I can just change that via css. I definitely am in favor of having such a button since you might want to get to the actual site where that image is coming from (eg. viewing youtube thumbnail and then watching the video)


// Reason to make this a specific handler is, for images, to open the image
// viewer even when clicking in the margins of the thumbnail
$("#viewport").on("click", ".toggle-content.toggle-type-image", function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried stopPropagation in this event? It might be possible to get rid of the event above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay that won't work as you want the thumbnail too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll rewrite that part to make it simpler and remove an edge case (accidentally clicking on margin of image in link previews, not image previews, will open the link instead of the viewer).

return false;
});

$(document).on("click", "#image-viewer", function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can cache #viewport into a variable and bind all these events on it instead of document.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can cache #viewport into a variable

Will do!

bind all these events on it instead of document.

Any benefits? By not binding on body, it means your focus can be off and not catch the event, no?


$(document).keydown(function(e) {
switch (e.keyCode ? e.keyCode : e.which) {
case 27: // Escape
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also do this dropdown menus, might be a good idea to combine or something.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really want to get into keyboard handling as part of this PR. Can we do it later?
(Also, I'm not 100% sure we should, hesitating a bit, let's postpone this I'd say)

@AlMcKinlay
Copy link
Member

Personally not sure how I feel about the open image button -- I think most people can figure out save as or drag to desktop. Overall great feature.

I disagree, let's not make assumptions on that sort of level, not everyone knows these things. I would however suggest that maybe instead of this button, we could have a button that has this icon which opens it in a new tab. But that's just a small thing.

I'll do a proper review of this soon, looks good in general, @astorije

@xPaw
Copy link
Member

xPaw commented Jul 12, 2017

I don't think using blur (especially with transition) is worth the performance hit considering how dark the container already is.

For some reason object-fit: contain makes the link hitbox square, so hitting empty space still opens the link (try https://i.redd.it/bk48m38ioz8z.jpg)

@MaxLeiter
Copy link
Member

A lot of the time instead of using blur people create a div with a slight alpha like here:

https://codepen.io/imprakash/pen/GgNMXO

Could that be a better solution, @xPaw?

@astorije
Copy link
Member Author

Personally not sure how I feel about the open image button -- I think most people can figure out save as or drag to desktop.

Additionally to what @YaManicKill said, it's less trivial on mobile to open context menu than to click on a button, and while it's convenient it's not obvious that image is clickable.
For the record, Google Images shows this kind of button too.
Also, when #1307 is merged, button/link will open the original image instead of the proxied picture, which is usually what you want to do when saving or zooming (at this point we won't be compressing/resizing the image, but user does not know that).

what limits the size of the image? can't we make it bigger?

Image is: fluid until 100% of the image width max. So if image is 1000px width and your screen is 2000px wide, image will take half of it. If your screen is 500px wide, image will be reduced to fit 100% of the screen.
Does that make sense? I feel like it doesn't :D
To see it in full-size, you can click the image or the button.

For some reason object-fit: contain makes the link hitbox square, so hitting empty space still opens the link (try https://i.redd.it/bk48m38ioz8z.jpg)

Yeah, that's the issue I was mentioning above. I think I found a way to fix this, I'll try this and see what happens.

I don't think using blur (especially with transition) is worth the performance hit considering how dark the container already is.

You don't like nice things :D
I honestly think there is no issue with this at all. I will try with the slowest devices of our generation and our parent's (i.e. current phones in my household) but I doubt this will have any noticeable impact. Especially since there is no scroll or else on the blurred content.
If it's an issue, I will use the transform: translate3d(0,0,0); or transform: translateZ(0); trick, but I don't even think we'll need this.
And yeah, of course it's worth it, it's pretty! :)

@astorije
Copy link
Member Author

A lot of the time instead of using blur people create a div with a slight alpha like here:

If I understand correctly, this is doing both. It looks pretty slick as is!

@astorije astorije force-pushed the astorije/image-viewer branch 2 times, most recently from e170783 to 1602c28 Compare July 15, 2017 17:15
@astorije
Copy link
Member Author

I fixed both issues mentioned in the PR description so this should be good for review. The max-height for image is pretty disgusting but for the life of me I couldn't find anything else that works (object-fit: contain is out of the picture due to how it works).
Any suggestions? Or you're cool with the current solution?

@xPaw, I couldn't find where to check that GPU is being leverage, could you advise?

Copy link
Member

@AlMcKinlay AlMcKinlay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, pretty simple. I think I'd like the icon to be as I described in my earlier comment, but it's not a blocker. Nice feature.


/* Image viewer */

// FIXME Remove #input focus when this is open
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you aren't going to fix this in this PR (which I'm ok with) then stick up an issue on github for it and put in the number here. Otherwise this will get missed. I hate random "FIXME" and "TODO" s that don't have any number attached to them

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, here it is: #1342

opacity: 1;
}

#image-viewer .image-link img {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't actual padding on here work instead of using calc?

Copy link
Member Author

@astorije astorije Jul 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, left/right padding calc was unnecessary as the link itself has a margin (I removed them), but for the max height, padding doesn't help. What this means is that the image's max height must be all screen minus its margins and the button height, and I can't get to anything else that would work and be less "hardcoded"... :/

return false;
});

$(document).on("click", "#image-viewer", function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure the way you're binding the event here does not help and $("#image-viewer").on("click") should work exactly the same.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, done.

type: link.parent().hasClass("toggle-type-image") ? "image" : "link"
}));

$("body").addClass("image-viewer-opened");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use $(document.body)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done.

$("body").addClass("image-viewer-opened");
}

function closeImageViewer() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearing out image-viewer in here might be a good idea to unload it from memory.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, done (after transition has ended).

@astorije
Copy link
Member Author

I believe I have addressed all comments.

Copy link
Member

@xPaw xPaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@astorije, merge whenever.

@astorije astorije merged commit ce0e460 into master Jul 18, 2017
@astorije astorije deleted the astorije/image-viewer branch July 18, 2017 04:09
matburnham pushed a commit to matburnham/lounge that referenced this pull request Sep 6, 2017
An image viewer popup for thumbnails and image previews
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature Tickets that describe a desired feature or PRs that add them to the project.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants