Start slideshow with random slide

Jul 13, 2008 at 1:35 PM
Is there an easy way to start a slideshow with a random slide from the album, instead of the first (or say 5th)?

I know you can do this:

<data startalbumindex="0" startslideindex="4" .... in the Data.xml file,

but without altering the file on the fly, is there an easy way?


Jul 16, 2008 at 10:18 AM

Yes, in SlideShow.js in class SlideShowControl change the function onDataLoad:

 this.data.startalbumindex = Math.floor(Math.random() * this.data.album.length); // <- new line

 

 

if (this.data.startalbumindex != null && !this.isAlbumIndexValid(this.data.startalbumindex))

 

 

    throw new Error("Invalid configuration: startalbumindex");

 

Nov 10, 2008 at 8:13 AM
Edited Nov 10, 2008 at 8:14 AM
I tried the solution above but I can't make it work -the code executes wihtout error, but the images are not dispayed randomy.

I run Slide.Show 1.2 in a Sharepoint envioement. Browser is IE 7

I have modified the code like this:

 onDataLoad: function(sender, e)
 {
  /// <summary>Handles the event fired when the configured data is loaded.</summary>
  /// <param name="sender">The event source.</param>
  /// <param name="e">The event arguments.</param>
  
  this.data = e.data;
  
  this.data.startalbumindex = Math.floor(Math.random() * this.data.album.length); // <- new line
  
  if (this.data)
  {
   if (this.data.startalbumindex != null && !this.isAlbumIndexValid(this.data.startalbumindex))
    throw new Error("Invalid configuration: startalbumindex");
   
   if (this.data.startslideindex != null && !this.isSlideIndexValid((this.data.startalbumindex) ? this.data.startalbumindex : 0, this.data.startslideindex))
    throw new Error("Invalid configuration: startslideindex");
  }
  
  this.fireEvent("dataLoad");
  this.onLoad(this);
 }, 

Any suggestions on how to make it work?