dimsemenov / PhotoSwipe

JavaScript image gallery for mobile and desktop, modular, framework independent
http://photoswipe.com
MIT License
24.18k stars 3.31k forks source link

Are two arguments required for `loadAndOpen()`? #2026

Closed arayutw closed 1 year ago

arayutw commented 1 year ago

Hello. Thank you for your wonderful project.

I would like to check if the second argument of loadAndOpen(), DataSource, can be omitted. Which is correct, types or the documentation?

loadAndOpen(index: number, dataSource: DataSource, initialPoint?: import("../photoswipe.js").Point | null | undefined): boolean;

https://github.com/dimsemenov/PhotoSwipe/blob/master/dist/types/lightbox/lightbox.d.ts#L85

// Open slide by index
lightbox.loadAndOpen(0);

https://photoswipe.com/methods/#photoswipelightbox-methods

dimsemenov commented 1 year ago

Hi, I just added a section in the documentation with an example and some clarifications, let me know if it helps- https://photoswipe.com/methods/#open-lightbox-via-external-button-with-loadandopen

Types should be looked at as well.

BeeMargarida commented 1 year ago

The data source argument is not defined as optional, so it throws out an error when using it as .loadAndOpen(0). As mentioned in https://photoswipe.com/methods/#photoswipelightbox-methods. It seems like loadAndOpen requires dataSource, but the preload function (which is called by loadAndOpen) does not has dataSource as required.

Is this supposed to be, or is it a bug?

dimsemenov commented 1 year ago

ty @BeeMargarida I updated the docs too and made dataSource fully optional https://photoswipe.com/methods/#loadandopenindex-datasource-point

BeeMargarida commented 1 year ago

That's great, thank you!