Thursday, February 15, 2007

Slide Show Widget Version 2

<b:widget id='PictureSlideShow' locked='false' title='Pictures' type='TextList'>
<b:includable id='main'>

<b:if cond='data:title'><h2><data:title/></h2></b:if>
<div class='widget-content'>

<script type='text/javascript'>
/*<![CDATA[*/

(function (timing,allowLink)
{
var imgName = 'slide'+ parseInt(Math.round(100000*Math.random()));

var picObject =
{
slideshowspeed: timing,
canlink: allowLink,

slideimages: new Array(),
slidelinks: new Array(),

whichimage: 0,

addImageAndLink: function (imageURL)
{
var currLength = this.slideimages.length;

this.slideimages[currLength] = new Image();
this.slideimages[currLength].src = imageURL;
this.slidelinks[currLength]=imageURL;

this.whichimage=Math.round((this.slideimages.length-1)*Math.random());
},

gotoshow: function ()
{
var curr = (this.whichimage+this.slidelinks.length-1) % this.slidelinks.length;

if (!window.winslide||winslide.closed)
winslide=window.open(this.slidelinks[curr]);
else
winslide.location=this.slidelinks[curr];

winslide.focus();
},

slideit: function()
{
if (!document.images) return;

document.images[imgName].src=this.slideimages[this.whichimage].src;

if (this.whichimage<this.slideimages.length-1) this.whichimage++;
else this.whichimage=0;

var thisobj = this;
if (this.slideshowspeed != 0) setTimeout(function() {thisobj.slideit();},this.slideshowspeed);
}

}

document.write('<img border=\'0\' name=\'' + imgName + '\' width=\'80%\'/>');

var timg = document.images[imgName];

timg.style.padding='2px 2px';
timg.style.border='2px GRAY SOLID';

timg.onclick = function (e)
{
if (!e) var e = window.event;
if (picObject.canlink == 1) picObject.gotoshow();
}

timg.onmouseover = function (e)
{
if (!e) var e = window.event;
if (picObject.slideshowspeed == 0) picObject.slideit();
}


/*]]>*/
<b:loop values='data:items' var='item'>
picObject.addImageAndLink("<data:item/>");
</b:loop>
/*<![CDATA[*/

picObject.slideit();

}) (1000, 1);

/*]]>*/
</script>
<b:include name='quickedit'/>
</div>
</b:includable>
</b:widget>

No comments: