This took a little while to get working properly earlier this week, so I figured I’d share the love…
var album = { startup: function() { new PeriodicalExecuter(album.cycle, 5) // change image every 5 seconds }, cycle: function() { new Effect.Fade(‘image’, { // the id of the <DIV> containing the photos duration: 1, fps: 50, afterFinish: function() { new Ajax.Updater(‘image’,‘/album/next’, { // URL for next <IMG> tag asynchronous: true, onSuccess: function() { new Effect.Appear(‘image’, { duration: 1, fps: 50, queue:‘end’ }) } }) } }) } }
window.onload = album.startup
I don’t generally advertise that I wrote thousands and thousands of lines of JavaScript in the 2001-2003 time period, most of it nice and clean like the Prototype library. I even tried to open source my work and was threatened with a lawsuit. (Get me drunk and I might share some of that story!) But anyway, after a long time of wanting to avoid it, I am realizing that one of the biggest reasons I took to Ruby so strongly is because I was already accustomed to programming with closures.
I post regularly about Ruby and other stuff on my blog, but I expect to be adding Ruby and JavaScript tips and tricks to this one more often.