Forums | MacLife
You are not logged in.
#1 2006-04-15 4:30 am
- unresort
- Member

- From: lawrence, kansas
- Registered: 2003-01-25
- Posts: 778
Couloir slideshow - play feature?
http://www.couloir.org/js_slideshow/
has anyone ever figured out how to add a "play" feature to this slideshow?
Offline
#3 2006-04-15 11:41 pm
- unresort
- Member

- From: lawrence, kansas
- Registered: 2003-01-25
- Posts: 778
Re: Couloir slideshow - play feature?
thanks Scott, i was actually hoping for a little more help, but i'll take whatever i can get.
this is all the help that Scott (Couloir) himself is providing:
Scott from Couloir here. Maybe I can help...
> 3. add an Autoplay feature so that the user doesn't keep having to
> click next.
One approach is to add the following lines inside the "element.onclick"
function for the Behaviour rule you use to activate the autoplay
feature:
var myShow = new Slideshow(photoId);
autoPlay = function(){myShow.nextPhoto();}
myShow.nextPhoto();
new PeriodicalExecuter(autoPlay,5);
The PeriodicalExecuter() function is part of Prototype that works a lot
like the standard setInterval() function, but it accepts seconds as a
second argument, rather than milliseconds. In this case, the autoPlay
function will fire every 5 seconds. I've included a direct call to
nextPhoto() in order to jump the slideshow forward when the play button is clicked, rather than delay the change 5 seconds. Thereafter, the PeriodicalExecuter() moves the show forward.
You'd then need to write a method to kill PeriodicalExecuter now that
you've started it and attach that to another event (when someone clicks the next/previous buttons, for instance).
not quite sure i understand it. help?
Last edited by unresort (2006-04-15 11:48 pm)
Offline
#4 2006-04-16 12:27 am
Re: Couloir slideshow - play feature?
The PeriodicalExecuter() function is part of Prototype that works a lot
like the standard setInterval() function, but it accepts seconds as a
second argument, rather than milliseconds
What the hell is it with prototype.js and reinventing the wheel? It's nice but it's too damn bloated.
But I guess I may as well get used to it, it looks like web applications with hundreds of kilobytes of unused javascript functions are the way of the future.
Couloir.org wrote:
This photo slideshow is a demonstration of Flash-like behavior implemented solely in Javascript, HTML, and CSS.
.... aaaand Flash.
Offline
#5 2006-04-16 12:39 am
Re: Couloir slideshow - play feature?
I don't like how this slideshow script is written.
Add near the top:
Code:
// Something to hold the setInterval ID
var playingInterval;
function cancelSlideshow() {
if (playingInterval) {
window.clearInterval(playingInterval);
playingInterval = null;
}
}Modify later on:
Code:
var myrules = {
'#Photo' : function(element){
element.onload = function(){
var myPhoto = new Slideshow(photoId);
myPhoto.showPhoto();
}
},
'#PrevLink' : function(element){
element.onmouseover = function(){
soundManager.play('beep');
}
element.onclick = function(){
cancelSlideshow();
var myPhoto = new Slideshow(photoId);
myPhoto.prevPhoto();
soundManager.play('select');
}
},
'#NextLink' : function(element){
element.onmouseover = function(){
soundManager.play('beep');
}
element.onclick = function(){
cancelSlideshow();
var myPhoto = new Slideshow(photoId);
myPhoto.nextPhoto();
soundManager.play('select');
}
},
'#PlayLink' : function(element){
element.onmouseover = function(){
soundManager.play('beep');
}
element.onclick = function(){
cancelSlideshow();
var next = function () {
var myPhoto = new Slideshow(photoId);
myPhoto.nextPhoto();
}
playingInterval = window.setInterval(next, 5000);
next();
soundManager.play('select');
}
},
...You can of course also provide a stop link which calls cancelSlideshow.
You could I suppose use PeriodicalExecuter, but it doesn't really simplify anything to do so, and apparently there's no way to stop one.
Offline
#6 2006-04-16 1:58 am
- unresort
- Member

- From: lawrence, kansas
- Registered: 2003-01-25
- Posts: 778
Re: Couloir slideshow - play feature?
Miles,
holy crap man! thank you soooo much, i really really appreciate it. it works perfectly.
Offline
#8 2006-04-16 9:36 am
Re: Couloir slideshow - play feature?
Miles wrote:
You could I suppose use PeriodicalExecuter, but it doesn't really simplify anything to do so, and apparently there's no way to stop one.
Sure there is you can pause and unpause it.
PeriodicalExecuter is not just a replacement for setInterval, it is integrated into the prototype framework. So it benefits from from that class and gets things like synchronization. But in this case doing it manually works just the same. For larger applications it is beneficial to use it.
Prototype is only 50ish k, not hundreds. If you add in scriptaculous you are right at about 100k. That covers most things you need to commonly do and it is easy to extend. Not really bloat. The core of is the ajax stuff and object structure, most everything else is only a couple of lines. Especially if you do a lot of application based stuff, you are using a bulk of the code and get a lot of stuff for free.
I used to write my own stuff all the time, but more often than not I use prototype and extend where needed. It is tight and well written.
Offline
#9 2006-04-16 4:24 pm
Re: Couloir slideshow - play feature?
Scott wrote:
Miles wrote:
You could I suppose use PeriodicalExecuter, but it doesn't really simplify anything to do so, and apparently there's no way to stop one.
Sure there is you can pause and unpause it.
You can pause it, but there's no way to clear the interval, so it's still being called every so often, just not executing your function. The effect is the same, but... 
Scott wrote:
Prototype is only 50ish k, not hundreds. If you add in scriptaculous you are right at about 100k. That covers most things you need to commonly do and it is easy to extend. Not really bloat. The core of is the ajax stuff and object structure, most everything else is only a couple of lines. Especially if you do a lot of application based stuff, you are using a bulk of the code and get a lot of stuff for free.
I used to write my own stuff all the time, but more often than not I use prototype and extend where needed. It is tight and well written.
prototype.js really is a great framework, and for involved applications that are doing a lot of DOM manipulation and XMLHttpRequest, it makes a lot of sense. But for simpler purposes, it just seems too heavy, and the file size isn't trivial for dial-up users. I recently had to write some scripts to drive the management interface for an application that generates forms dynamically, and the management interface does a lot of DOM manipulation—adding elements and form fields, toggling visibility/disabled states, and allowing drag-and-drop sorting. I couldn't find a drag-and-drop library that worked well enough, so I ended up rolling my own. The total amount of JavaScript? 13K—and that's with substantially more commenting than prototype.js or scriptaculous have.
I have to admit, though, that a lot of my distrust for prototype.js is probably uninformed; I just really don't like the idea of creating all those objects on page load and adding methods to existing objects unnecessarily if they're not all going to be used. I really should do some benchmarking to see what kind of performance costs are involved with using prototype.js.
Offline
#10 2006-04-16 6:24 pm
Re: Couloir slideshow - play feature?
Miles wrote:
I have to admit, though, that a lot of my distrust for prototype.js is probably uninformed;
Don't get me wrong, it is not perfect. There are some problems. The most significant if you write your own stuff and use event handlers. Prototype assumes it is in control of all js. If you know that it, it isn't a problem. Extending it is usually more efficient than mixing and matching.
Miles wrote:
I just really don't like the idea of creating all those objects on page load and adding methods to existing objects unnecessarily if they're not all going to be used. I really should do some benchmarking to see what kind of performance costs are involved with using prototype.js.
You really don't (create a bunch of objects). They all extend a base class. Using the periodic updater for example. It is only a few lines within prototype and is its own object. If you don't call it the only impact is few lines in your cache.
And frankly, I don't care about dial up users. They are getting very rare. And slow is just part of the dial-up experience. They are used to waiting. Additionally if a site is using ajax/dhtml/heavy scripting, a 100k is probably an insignificant chunk as opposed to what else is involved in the site. Even so, since external scripts are cached is only a one time hit over the course of a site. I am not saying that I go nuts with the images and assume that everyone is using a fat pipe, but it is a balance. In your example of a dynamic form, even if it were 100k+, you are already making up for it by not forcing page reloads and connects by building on one page.
And think about the most common sites that would be used by dial up users, GMail, Yahoo mail, etc... talk about a lot of external code...
I write mostly web applications, some very large in scope. The one thing that really endears me to prototype is that it is solid and all the cross-platform crap is addressed. I used to spend so much time testing in browsers getting dynamic stuff to work equally in IE, Safari and FF/Moz. I rarely have to worry about it any more. If extend the base stuff I know I am starting on solid ground.
Offline
#11 2006-07-25 4:29 pm
- wildcat
- Member
- Registered: 2006-07-25
- Posts: 2
Re: Couloir slideshow - play feature?
I found this thread while searching for info on editing the code for this slideshow (http://www.couloir.org/js_slideshow/)
Miles's code tweeks for adding an 'auto play' feature worked really well and is almost exactly what I need. However, what I would like to do is to simply have the slideshow start playing when the page loads, without user input.
Can anyone offer any pointers as to how I might do this?
Thank!
Offline
#12 2006-07-27 11:49 am
Re: Couloir slideshow - play feature?
What you want to do is to make the Play code automatically called when the page loads. Modify the init() function at the end of slideshow.js, which is set to the window.onload event by Behaviour:
Code:
// Add window.onload event to initialize
Behaviour.addLoadEvent(init);
Behaviour.apply();
function init() {
var myPhoto = new Slideshow(photoId);
myPhoto.initSwap();
soundManagerInit();
var next = function () {
var myPhoto = new Slideshow(photoId);
myPhoto.nextPhoto();
}
playingInterval = window.setInterval(next, 5000);
}You'll still need to make the modifications listed above, particularly declaring playingInterval and cancelSlideshow(), and calling cancelSlideshow() with the Prev and Next buttons.]
Good luck! 
Offline
#13 2006-07-27 1:27 pm
- wildcat
- Member
- Registered: 2006-07-25
- Posts: 2
Re: Couloir slideshow - play feature?
Miles,
Thanks so much. It worked perfectly. I really appreciate it!
This stuff is making more and more sense every little bit at a time.
Offline
#14 2008-08-04 9:42 pm
- gomerpylevw
- Member
- Registered: 2008-08-04
- Posts: 2
Re: Couloir slideshow - play feature?
I am new to javascript and had a question about expanding this AWESOME scriptaculous slideshow. How would I have the slideshow.js script file scan a given directory for images and add them as slides instead of manually entering them into the file?
Thanks,
gomer
Offline
#15 2008-08-05 8:14 am
- Booksley
- Planely insane!
- From: Toronto, Ontario
- Registered: 2001-02-16
- Posts: 4770
Re: Couloir slideshow - play feature?
gomerpylevw wrote:
I am new to javascript and had a question about expanding this AWESOME scriptaculous slideshow. How would I have the slideshow.js script file scan a given directory for images and add them as slides instead of manually entering them into the file?
Thanks,
gomer
Javascript executes on the browser, not on the server, so I can't see a way to do it in pure js. If you added a server-side language to mix, you could use that to generate a list.
Honestly, you're probably better off just adding the filenames.
Offline
#16 2008-08-05 8:28 am
- gomerpylevw
- Member
- Registered: 2008-08-04
- Posts: 2
Re: Couloir slideshow - play feature?
Yeah, I didn't think about the js executing on the client-side. Well, looks like here comes AJAX to the rescue I hope. I am going to try to create a webmethod that grabs the filelist and see if I can use ClientScript to push it back to the slideshow.js include.
Thanks,
gomer
Offline

