I have a lightbox opened by clicking a horizontal menu item. I want to close it via a gallery _click function inside it. Then pass the .currentItem click data from the lightbox gallery to the page. When I try a simple wixWindow.Lightbox.close(); it returns undefined and the .getContext function for the lightbox doesn’t appear either. Any thoughts?
The undefined message has to do with Lightbox needing to be in lower case.
wixWindow.lightbox.close();
After several failed attempts, and everything I read suggesting that in order to pass back data to the page, the lightbox DOES need to be opened programically, I came up with this workaround in case anyone is interested:
//For context the gallery is a 3D carousel with two images whose names include the 3rd and 4th "const" values. The page is the overlay area outside the lightbox.
*****************
* Lightbox Code *
*****************
import wixWindow from "wix-window";
$w.onReady(function() {
$w("#campaignsgallery").onItemClicked((event) => {
const imageSelected = $w("#" + event.target.id).currentItem.title;
const anchorName = imageSelected.match(/[^UniTEE Campaign(](.+?)(?=\))/g)[0];
if(wixWindow.formFactor === "Mobile") {
const quarantine = 429;
const revolutionary = 244;
}
else {
const quarantine = 1350;
const revolutionary = 1011;
}
wixWindow.getBoundingRect()
.then((view) => {
const leftOffset = view.scroll.x;
wixWindow.scrollTo(leftOffset, eval(anchorName));
wixWindow.lightbox.close();
});
});
$w("#page").onClick((event) => {
wixWindow.lightbox.close();
});
});
Closes when you click outside the lightbox and when clicking a gallery item, it scrolls to the corresponding anchor and also closes the lightbox. It really mimics flawlessly the standard (non-code) Wix functionality.
ps. Thanks Anthony for the tip, I missed that.