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

# Adds public showImage method #128

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/baguetteBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,15 @@
}
return returnValue;
}

// opens specific image
function showImage(selector, imageIndex) {
if ( null === imageIndex || undefined === imageIndex || '' === imageIndex ){
imageIndex = 0;
}
Copy link
Owner

Choose a reason for hiding this comment

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

I'd replace this check with:

if (isNaN(parseInt(imageIndex)) {
    imageIndex = 0;
}

var activeImage = baguetteBox.data[selector].galleries[0][imageIndex];
activeImage.eventHandler(activeImage);
Copy link
Owner

Choose a reason for hiding this comment

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

We need to check that given index doesn't exceed the elements count:

if (activeImage) {
    activeImage.eventHandler(new MouseEvent('click'))
}

I've also replaced activeImage argument, because the method expects an event object.

}

function updateOffset() {
var offset = -currentIndex * 100 + '%';
Expand Down Expand Up @@ -692,9 +701,11 @@

return {
run: run,
data: data,
Copy link
Owner

@feimosi feimosi Oct 23, 2016

Choose a reason for hiding this comment

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

Why do we make this data public?
You can refer to data directly in the code, we're in a closure.

destroy: destroyPlugin,
showNext: showNextImage,
showPrevious: showPreviousImage
showPrevious: showPreviousImage,
showImage: showImage,
Copy link
Owner

Choose a reason for hiding this comment

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

Remove the trailing comma, it's not supported by IE.

};

}));
}));
Copy link
Owner

@feimosi feimosi Oct 23, 2016

Choose a reason for hiding this comment

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

Missing final newline. I recommend using editorconfig.org 👍