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

TypeError: undefined is not an object – gallery.length on undefined in show() function #248

Open
czirkoszoltan opened this issue Jul 10, 2021 · 1 comment

Comments

@czirkoszoltan
Copy link

Currently the show() function looks like this:

    /**
     * Move the gallery to a specific index
     * @param `index` {number} - the position of the image
     * @param `gallery` {array} - gallery which should be opened, if omitted assumes the currently opened one
     * @return {boolean} - true on success or false if the index is invalid
     */
    function show(index, gallery) {
        if (!isOverlayVisible && index >= 0 && index < gallery.length) {
            prepareOverlay(gallery, options);
            showOverlay(index);
            return true;        

The comment says that the gallery argument can be omitted. Still, the condition takes gallery.length, which is a TypeError if gallery==undefined. The other show...() functions (from line 603 to 627) all use show() with one argument only.

@czirkoszoltan
Copy link
Author

I guess this can be fixed like this:

    function show(index, gallery) {
        gallery = gallery || currentGallery;
        if (!isOverlayVisible && index >= 0 && index < gallery.length) {

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

No branches or pull requests

1 participant