Bug?: Shadowbox.next() fires the onFinish event!

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

Bug?: Shadowbox.next() fires the onFinish event!

I have a code like this, because i want my Gallery to be autoplayed and the user shall be redirected to another page after viewing the last content.

Problem1* If i add a onFinish: reDirect to the options, the events gets fired after a Shadowbox.next() call via setInterval
Problem2* Adding options={onFinish:closeIt} or options={onFinish:reDirect} to the last Gallery Item doesnt work for some reason

<script type="text/javascript"> function reDirect() { window.location.replace('http://www.xxx.xx/index.php'); } function closeIt() { Shadowbox.close(); return true; } var options = { listenOverlay: false, overlayOpacity: 0, animate: true, displayCounter: false, counterType: 'skip', continuous: false, displayNav: true, animSequence: 'sync', autoplayMovies: true, onClose: reDirect }; window.onload = function() { Shadowbox.init(options); Shadowbox.open(document.getElementById('showStart')); window.setInterval("Shadowbox.next()", 6000); } </script></head>


<div id="rahmen">
<div id="container">

<-a id="showStart" rel="shadowbox[Mixed];width=520;height=425" href="http://www.xxx.xx/images/seq2.jpg"></-a>
<-a rel="shadowbox[Mixed];width=520;height=425" href="http://www.xxx.xx/images/seq3.jpg"></-a>
<-a rel="shadowbox[Mixed];width=520;height=355;options={onFinish:closeIt}" href="http://www.xxx.xx/media/movie.wmv"></-a>



Any suggestions?
Reply | Threaded
Open this post in threaded view

Re: Bug?: Shadowbox.next() fires the onFinish event!

With regard to the onFinish callback:
- the fact that it fires after every next() call is not a bug - it is doing exactly what it is designed to do, which is to fire upon completion of the display of any Shadowboxed element
- the fact that the element-specific onFinish callback in the last gallery link is being ignored could be considered a bug. I think you'll find (and I haven't checked this recently - I'm going from memory!) that whichever link of a gallery gets clicked to initiate that gallery, that link's options will be used for the entire gallery. I suspect it wasn't intended to work that way but ... .

There is a way round this.
The onFinish callback gets passed the cache object of the element that has just been displayed. Therefore, if you declare a general onFinish callback, and give the last element of your gallery a unique id, you can test for that id within the onFinish callback and only act if found.


var options = { ...
                   , onFinish : function(obj){ if(obj.el.id && obj.el.id=='lastInGallery'){ Shadowbox.close(); } }

Then set the id of your last element to 'lastInGallery' (or whatever you choose to use instead).

Note : the example above does an immediate close(), whereas you will probably want to put it on a timeout so that the user gets a chance to see the last element!

[The above is untested ... but should work in principle]
Combine literacy with curiosity and a whole world of information opens up to you