Go To Next Slide When Vimeo Finished
If you are using Squarespace Gallery block to host Vimeo videos, it makes sense go to next slide when video stops playing. And this actually can be easily done.
So we need to know when exactly the Vimeo video ends.
1) We may use their Player.js for that. Good call, but only if we need some more extra using Vimeo API. Also in this case we need to pass iframe element to Player class and this will be a little bit tricky, because Squarespace Videoloader dynamically adds video iframe in the moment you click Play button by default.
2) Almost all communication with iframes using window.postMessage() method. And Vimeo iframe already posts ready event messages to our top window. After ready event we may tell the iframe to push other messages to main window and control the video also.
I found second way more simple and clean. So here is the logic:
Wait for window.onload ($(document).ready or Y.on('domready')) event to make sure Gallery was initialized.
Subscribe to message event.
Check for ready message and make sure it has Vimeo URL origin and iframe content window is equal current active slide iframe.contentWindow (to be sure it is not a message from some other iframe on the page)
Use addEventListener method to make iframe post proper messages to our window
If this is an event we are waiting for - call the Next Slide.
After the slide changed, check the new slide for video, and play it.
Two words about 5 clause: I saw many codes from devs, who trigger next/prev slide from code with simulating 'click' on gallery controls (arrows). Well, it makes sense, even if Squarespace will change something in their gallery code. But while I may retrieve galleries instance (with the ability to call all other Gallery methods) from GalleryManager or from Gallery Node with the code below, let me use that.
So I need to use this for first gallery on page and here is the full code you may inject to Header/Footer or Page Injection Tab: