banthagroup / fslightbox

An easy to use vanilla JavaScript plug-in without production dependencies for displaying images, videos, or, through custom sources, anything you want in a clean overlying box.
MIT License
351 stars 30 forks source link

For custom toolbar icons, get properties from open image #129

Closed daften closed 3 years ago

daften commented 4 years ago

E.g. to add a delete action, we need to know the URL / id of the current photo. Is this possible. Is it possible to pass the image object for the open/active image to the function being called?

https://fslightbox.com/javascript/documentation/toolbar

piotrzdziarski commented 3 years ago

In 3.3.0 FsLightbox instance is passed as param to custom toolbar button onclick. So you can get the current source URL like this:

fsLightboxInstances['gallery'].props.customToolbarButtons = [{
  onClick: (instance) => {
    console.log(instance.props.sources[instance.stageIndexes.current]);
  }
}]; 
daften commented 3 years ago

Instead of the lightboxinstance, I get a PointerEvent though :s