When the original script only has one image, a JavaScript script error will pop up. We hereby post the modified version.
The Code is as follows:
/*---------------------------------------------------------------------------*\
| Subject: Rotate AD
| NameSpace: System. Web. UI. WebControls. mzrtateimage
| Author: meizz
| Created: 2006-11-11
| Version: 2006-12-06
| -----------------------------------
| MSN: huangfr@msn.com QQ: 112889082 Copyright (c) meizz
| Http://www.meizz.com/jsframework/ MIT-style license
| The above copyright notice and this permission notice shall be
| Included in all copies or substantial portions of the Software
| Changer: Worm
| AlterDate:
\*---------------------------------------------------------------------------*/
// Using ("System. Data. MzDataProvider ");
// Using ("System. Web. Forms. MzBehavior ");
// Node {url, target, summary, img, alt}
Function mzrtateimage ()
{
MzDataProvider. call (this); this. stateChangeHandle (1 );
This. Length = 280;
This. height = 187;
This. timer = null;
This. interval= 10000;
This. duration= 2000;
This. activeIndex = 1;
This. currentIndex = 0;
This. floatControlBar = true;
This. useFilter = System. ie & MzBrowser. version >=5.5;
}
Mzrtateimage. Extends (MzDataProvider, "mzrtateimage ");
System. loadCssFile (System. resourcePath + "/mzrtateimage.css? 1.1.14 "," mzrtateimage_css ");
Mzrtateimage. prototype. render = function ()
{
This. dataInit (); this. images = new Array ();
Var d = this. nodes = this. rootNode. childNodes;
For (var I = 0; I {
This. images [I] = new Image ();
This. images [I]. src = d [I]. get ("img ");
}
Var id = this. id = "mzrtateimage _" + this. hashCode, s = [];
Var width = this. width = parseInt (this. width );
Var height = this. height = parseInt (this. height );
S. push ("
");
S. push ("
");
If (this. useFilter) {if (d. length> 0) // filter: revealTrans
{
Var alt = d [0]. get ("alt"), src = this. images [0]. src;
S. push ("1)
S. push ("style = 'filter: revealTrans (duration =" + (this. duration/1000) + ")'");
S. push ("id = '" + id + "_ img' style = 'border: none' width =" + this. width + "height =" + this. height + "/> ");
S. push ("
"+ Alt +"
");
}
}
Else {for (I = 0; I {
S. push ("
");
S. push ("s. push ("target = '" + (d [I]. get ("target") | "_ self") + "'> ");
S. push ("s. push (" src = '"+ this. images [I]. src +"'/> ");
S. push ("
"+ D [I]. get (" alt ") +"
");
}
}
S. push ("
S. push ("id = '" + id + "_ ControlBar' class = 'mzrtateimage _ ControlBar '> ");
For (I = 0; I ");
S. push ("
"); S. push ("
"); S = s. join ("");
This. stateChangeHandle (2); this. _ onload ();
Return s;
};
Mzrtateimage. prototype. stateChangeHandle = function (n)
{
This. readyState = n | 0;
This. dispatchEvent (new System. Event ("onreadystatechange "));
};
Mzrtateimage. prototype. _ onload = function ()
{
Var me = this;
If (MzElement. check (this. id ))
{
This. stateChangeHandle (4 );
If (this. useFilter) this. timer =
SetTimeout (function () {me. filter () ;}, me. interval + me. duration );
Else
{
This. _ rotate = new MzBehavior. Rotate (me. id + "_ ImageBox ",
{Interval: me. interval, duration: me. duration });
This. _ rotate. addEventListeners ("onchange", function (e)
{
Me. activeIndex = e.tar get. activeIndex;
Me. currentIndex = e.tar get. currentIndex;
E = new System. Event ("onchange"); e.tar get = me;
Me. dispatchEvent (e );
});
}
Var A = MzElement. check (this. id + "_ ControlBar"). getElementsByTagName ("INPUT ");
A [this. currentIndex]. className = "active ";
This. addEventListeners ("onchange", function (e)
{
For (var I = 0; iif (A. length> 1)
{
A[e.tar get. activeIndex]. className = "active ";
}
Else
{
A [0]. className = "active ";
}
});
For (var I = 0; I {
Var f = new Function ("Instance ('" + this. hashCode + "'). focus (" + I + ")");
A [I]. onmouseover = f; A [I]. onclick = f;
}
}
Else setTimeout (function () {me. _ onload () ;}, 10 );
};
Mzrtateimage. prototype. focus = function (n)
{
ClearTimeout (this. timer );
If (this. useFilter) {this. activeIndex = n; this. filter ();}
Else if (this. _ rotate) this. _ rotate. focus (n );
};
Mzrtateimage. prototype. filter = function ()
{
Var me = this;
If (me. dispatchEvent (new System. Event ("onchange ")))
{
Var img;
If (img = MzElement. check (me. id + "_ img "))
{
Var a = img. parentNode;
Var N;
If (me. nodes. length = 1)
N = 0
Else
N = me. activeIndex;
This. currentIndex = N;
This. activeIndex = N + 1> = me. nodes. length? 0: N + 1;
Var dv = MzElement. check (me. id + "_ p ");
Dv. innerText = me. nodes [N]. get ("alt ");
A. href = (me. nodes [N]. get ("url") | "#");
A.tar get = (me. nodes [N]. get ("target") | "_ self ");
Img. src = me. images [N]. src;
Img. alt = me. nodes [N]. get ("alt ");
If (me. nodes. length> 1)
{
Img. filters. revealTrans. Transition = 23;
Img. filters. revealTrans. apply ();
Img. filters. revealTrans. play ();
}
}
}
Me. interval = 5000;
This. timer = setTimeout (function () {me. filter () ;}, me. interval + me. duration );
};