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

[wip] Allow long captions #2

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open

Conversation

andi34
Copy link
Owner

@andi34 andi34 commented Aug 12, 2020

Long caption solution by @PeterSweetAndSour

dimsemenov#1692

@andi34 andi34 force-pushed the master branch 2 times, most recently from 0c558bc to cc99a07 Compare August 12, 2020 17:17
@andi34 andi34 force-pushed the allow_long_captions-prettier branch from 67cdd34 to 2679c13 Compare August 12, 2020 17:58
@andi34 andi34 mentioned this pull request Aug 12, 2020
@andi34 andi34 changed the title [wip] Allow long captions prettier [wip] Allow long captions Aug 12, 2020
@andi34 andi34 force-pushed the master branch 5 times, most recently from cbe905f to a8277d0 Compare August 23, 2020 08:49
…ement' to avoid confusion with the boolean option of the same name a few lines below. Also add some extra whitespace to separate functions.
…ption to go under the picture and be able to scroll to see it.
…lement and arrows and figure out why it is failing on mobile.
…top/bottom gaps so that caption function can be initiated with just the event. Not sure if this is better or just different.
…tion toggles now. Adding/removing whitespace for clarity.
…to indicate the end. Make caption text white so people like me can actually read it.
…apping on the caption because it is too easy to close accidentally when you thought you were swiping.
…nd/collapse arrows without another request to get an image and still have it work on IE11. Now need to get the event to fire when clicking on the arrow itself. Not sure it is worth the trouble.
…ize set explicitly so that it will work with IE11.
…o where the keydown events are handled. Also removing some console output.
Note that Google says that doing a CSS animation on height (and width) is bad for performance so I may revisit this later but it seems to work just fine. https://developers.google.com/web/updates/2017/03/performant-expand-and-collapse
…her than attempting to manipulate an existing one.
…n a phone does not call the goTo function so the resetCaption function was not getting called which had some odd results.
Unfortunately it did not work reliably and so it is now commented out in the hope that someone else will understand how to fix it.
Added lines 348 and 719 as I thought they might be why I could usually expand the caption with an upward swipe but could not close it. It seems those lines should be there but they did not seem to help so now commented out.
…en when allowLongCaptions is true.

Don't close caption on vertical drag when allowLongCaption is true.
Don't close caption when tap is on an element inside the caption
@andi34 andi34 force-pushed the allow_long_captions-prettier branch from 2679c13 to 17bf594 Compare September 4, 2020 18:25
@andi34
Copy link
Owner Author

andi34 commented Sep 5, 2020

If caption expanded and next picture contains a caption too it can not collapse the caption.
If caption is collapsed it's also working to expand/collapse caption of next picture or if previous opened picture does not have a caption.

@@ -59,14 +59,14 @@

// If allowLongCaptions is true, position caption just under picture and show "Expand" button if necessary
if (_options.allowLongCaptions) {
var imagePositionTop = item.initialPosition.y;
Copy link
Owner Author

Choose a reason for hiding this comment

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

It can't get item.initialPosition.y somehow

Copy link
Owner Author

Choose a reason for hiding this comment

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

Uncaught TypeError: Cannot read property 'y' of undefined

Choose a reason for hiding this comment

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

This is a mystery since it was working for me earlier.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I am only using the title attribute, could this cause an issue? (See the index.html)

Have a good flight!

Choose a reason for hiding this comment

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

@andi34 I remembered to look at this again. In my rush to get out the door for our trip, I didn't understand the issue. My long caption solution has the captions - both the teaser and the full version - in

elements (one with class="figure__caption--thumbnail" and the other "figure__caption--fullsize") using the structure shown here https://github.com/dimsemenov/PhotoSwipe/blob/master/website/documentation/getting-started.md#-how-to-build-an-array-of-slides-from-a-list-of-links and then the Javascript harvests that information to create the options object. Aside from being easier (for me) to generate the HTML, instead of the JS that includes the options object, from the database , putting the information in the figcaption elements means that it can contain arbitrary HTML so links and even other images can be included.

I'm going to update the documentation to make that clear and also check that I have not broken it for those using only the title object for the standard implementation. I wish I had done that earlier since now I can barely remember how it works!

I noticed in commit 83885ed that you moved some declarations further up. I had it where it was so that code would only be exercised if _options.allowLongCaptions was true.

Do you have a public-facing test page? When I ran your index.html I did not see any captions.

Copy link
Owner Author

@andi34 andi34 Sep 27, 2020

Choose a reason for hiding this comment

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

Thanks for your reply!

There's a test page inside the source, only dist files haven't been generated.
You could clone my fork and checkout the "allow_long_captions-prettier" branch and generate them. I can do also and push to that branch if needed.

https://github.com/andi34/PhotoSwipe/blob/allow_long_captions-prettier/index.html

Without 83885ed it wasn't working and had some errors visible in the browser console. My fork is far ahead of the official tree, have added a lot of stuff from the open Pullrequests.

Thanks a lot for looking at it, let me know if you need anything :)

var gapTop = item.vGap.top;

ui.resetCaption();
var naturalCaptionHeight = innerCaptionElement.clientHeight;

var captionCtrl = captionElement.querySelector('.pswp__button--caption--ctrl');
var captionCtrl = document.querySelector('.pswp__button--caption--ctrl');
Copy link
Owner Author

Choose a reason for hiding this comment

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

Doesn't work without this...

@PeterSweetAndSour
Copy link

PeterSweetAndSour commented Sep 5, 2020 via email

@andi34 andi34 force-pushed the allow_long_captions-prettier branch from 07ff53d to 2e70369 Compare September 6, 2020 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants