Thank you very much for the great work on this module. It's functionality is already quite comprehensive out of the box.
I am trying to use the Pro API to listen for an event. http://www.juicebox.net/support/api/ Since there isn't a variable associated with the generated gallery object, I can't hook onto it to listen for events.
Juicebox support suggested I change line 190 of includes\JuiceboxGallery.inc from:
$output .= "new juicebox({";
... to:
$output .= "var jb = new juicebox({;"
This would work fine for my implementation, because I don't have more than one gallery per page, but I know some do. In theory, a solution could be formulated to give every gallery a unique variable. However, that would make it very difficult to write Javascript that could easily be used sitewide on multiple galleries.
My proposal is a configuration option that turns the jb variable "on", with instructions that it won't work if you add more than one gallery per page. Does this seem workable?
Comments
Comment #1
jenna.tollersonComment #2
rjacobs commentedHi Jenna,
Defining explicit Juicebox js object variable names might be a good suggestion. Also, you're right about the naming convention, as hard coding something like "var" for the name would probably cause issues if one page contains multiple galleries. Each gallery does have a unique id in Drupal though, so I suppose that could be used for the js variable name. Still, as you noted, finding a programmatically-named variable later could be tricky.
Anyway, even without naming the Juicebox variables my understanding is that they are still available via a global array called "juicebox_instances", at least I think so, it's been a while since I've looked at that. So in the case of a page that only has one gallery, you could possibly get to that gallery's object via juicebox_instances[0].
I'm not sure how universally this works across all Juicebox versions and methods, but maybe it's useful. Here's one way I've used it to trigger a named record in Google Analytics each time someone browses to a new image (using the onImageChange event):
Comment #3
jenna.tollersonVery interesting, I am definitely going to try that out.
Comment #4
rjacobs commentedYeah. Let me know if it works for you, as this solution might be an interesting reference for others.
Comment #5
rjacobs commentedAssuming the var juicebox_instances[0] works globally (I'm pretty sure it does) I suppose there won't be too much value in adding any names to the "juicebox" javascript variable objects. If there does turn out to be some value to this, I'd still be happy to explore it. We'd just need to determine what the best naming convention would be (and I suppose that would be informed by specific use cases).
I'll close this for now, but it could be re-opened (or a new issue started) if needed.
Comment #6
jenna.tollersonSorry for the delayed response, but yes, using
juicebox_instances[0]definitely works with the onExpand event. Thank you for the tip and for the awesome work on this module!Comment #7
rudetrue commentedThanks, I ran into the same issue and was using the same modification to allow access to the juicebox pro api. I'll instead use this variable and ditch the customization.
Comment #8
anybodyI can confirm
juicebox_instances[0];works great to access the juicebox object for any modifications in JS. :)