Core code
Copy codeThe Code is as follows:
Function slide (src, link, text, target, attr, desc ){
This. desc = desc
This. src = src;
This. link = link;
This. text = text;
This.tar get = target;
This. attr = attr;
If (document. images ){
This. image = new Image ();
}
This. loaded = false;
This. load = function (){
If (! Document. images) {return ;}
If (! This. loaded ){
This. image. src = this. src;
This. loaded = true;
}
}
This. hotlink = function (){
Var mywindow;
If (! This. link) return;
If (this.tar get ){
If (this. attr ){
Mywindow = window. open (this. link, this.tar get, this. attr );
} Else {
Mywindow = window. open (this. link, this.tar get );
}
If (mywindow & mywindow. focus) mywindow. focus ();
} Else {
Location. href = this. link;
}
}
}
Function slideshow (slideshowname ){
This. name = slideshowname;
This. repeat = true;
This. prefetch =-1;
This. image;
This. textid;
This. textarea;
This. timeout = 5000;
This. slides = new Array ();
This. current = 0;
This. timeoutid = 0;
This. add_slide = function (slide ){
Var I = this. slides. length;
If (this. prefetch =-1 ){
Slide. load ();
}
This. slides [I] = slide;
}
This. play = function (timeout ){
This. pause ();
If (timeout ){
This. timeout = timeout;
}
If (typeof this. slides [this. current]. timeout! = 'Undefined '){
Timeout = this. slides [this. current]. timeout;
} Else {
Timeout = this. timeout;
}
This. timeoutid = setTimeout (this. name + ". loop ()", timeout );
}
This. pause = function (){
If (this. timeoutid! = 0 ){
ClearTimeout (this. timeoutid );
This. timeoutid = 0;
}
}
This. update = function (){
If (! This. valid_image () {return ;}
If (typeof this. pre_update_hook = 'function '){
This. pre_update_hook ();
}
Var slide = this. slides [this. current];
Var dofilter = false;
If (this. image &&
Typeof this. image. filters! = 'Undefined '&&
Typeof this. image. filters [0]! = 'Undefined '){
Dofilter = true;
}
Slide. load ();
If (dofilter ){
If (slide. filter &&
This. image. style &&
This. image. style. filter ){
This. image. style. filter = slide. filter;
}
This. image. filters [0]. Apply ();
}
This. image. src = slide. image. src;
If (dofilter ){
This. image. filters [0]. Play ();
}
This. display_text ();
If (typeof this. post_update_hook = 'function '){
This. post_update_hook ();
}
If (this. prefetch> 0 ){
Var next, prev, count;
Next = this. current;
Prev = this. current;
Count = 0;
Do {
If (++ next> = this. slides. length) next = 0;
If (-- prev <0) prev = this. slides. length-1;
This. slides [next]. load ();
This. slides [prev]. load ();
} While (++ count <this. prefetch );
}
}
This. goto_slide = function (n ){
If (n =-1 ){
N = this. slides. length-1;
}
If (n <this. slides. length & n> = 0 ){
This. current = n;
}
This. update ();
}
This. goto_random_slide = function (include_current ){
Var I;
If (this. slides. length> 1 ){
Do {
I = Math. floor (Math. random () * this. slides. length );
} While (I = this. current );
This. goto_slide (I );
}
}
This. next = function (){
If (this. current <this. slides. length-1 ){
This. current ++;
} Else if (this. repeat ){
This. current = 0;
}
This. update ();
}
This. previous = function (){
If (this. current> 0 ){
This. current --;
} Else if (this. repeat ){
This. current = this. slides. length-1;
}
This. update ();
}
This. shuffle = function (){
Var I, i2, slides_copy, slides_randomized;
Slides_copy = new Array ();
For (I = 0; I <this. slides. length; I ++ ){
Slides_copy [I] = this. slides [I];
}
Slides_randomized = new Array ();
Do {
I = Math. floor (Math. random () * slides_copy.length );
Slides_randomized [slides_randomized.length] =
Slides_copy [I];
For (i2 = I + 1; i2 <slides_copy.length; i2 ++ ){
Slides_copy [i2-1] = slides_copy [i2];
}
Slides_copy.length --;
} While (slides_copy.length );
This. slides = slides_randomized;
}
This. get_text = function (){
Return (this. slides [this. current]. text );
}
This. get_all_text = function (before_slide, after_slide ){
All_text = "";
For (I = 0; I <this. slides. length; I ++ ){
Slide = this. slides [I];
If (slide. text ){
All_text + = before_slide + slide. text + after_slide;
}
}
Return (all_text );
}
This. display_text = function (text ){
If (! Text ){
Text = this. slides [this. current]. text;
}
If (this. textarea & typeof this. textarea. value! = 'Undefined '){
This. textarea. value = text;
}
If (this. textid ){
R = this. getElementById (this. textid );
If (! R) {return false ;}
If (typeof r. innerHTML = 'undefined') {return false ;}
R. innerHTML = text;
}
}
This. hotlink = function (){
This. slides [this. current]. hotlink ();
}
This. save_position = function (cookiename ){
If (! Cookiename ){
Cookiename = this. name + '_ slideshow ';
}
Document. cookie = cookiename + '=' + this. current;
}
This. restore_position = function (cookiename ){
If (! Cookiename ){
Cookiename = this. name + '_ slideshow ';
}
Var search = cookiename + "= ";
If (document. cookie. length> 0 ){
Offset = document. cookie. indexOf (search );
If (offset! =-1 ){
Offset + = search. length;
End = document. cookie. indexOf (";", offset );
If (end =-1) end = document. cookie. length;
This. current = parseInt (unescape (document. cookie. substring (offset, end )));
}
}
}
This. noscript = function (){
$ Html = "\ n ";
For (I = 0; I <this. slides. length; I ++ ){
Slide = this. slides [I];
$ Html + = '<P> ';
If (slide. link ){
$ Html + = '<a href = "' + slide. link + '"> ';
}
$ Html + = ' ';
If (slide. link ){
$ Html + = "<\/a> ";
}
If (slide. text ){
$ Html + = "<BR> \ n" + slide. text;
}
$ Html + = "<\/P>" + "\ n ";
}
$ Html = $ html. replace (// \ &/g ,"&");
$ Html = $ html. replace (/</g, "<");
$ Html = $ html. replace (/>/g, "> ");
Return ('<pre>' + $ html + '</pre> ');
}
This. loop = function (){
If (this. current <this. slides. length-1 ){
Next_slide = this. slides [this. current + 1];
If (next_slide.image.complete = null | next_slide.image.complete ){
This. next ();
}
} Else {
This. next ();
}
This. play ();
}
This. valid_image = function (){
If (! This. image ){
Return false;
}
Else {
Return true;
}
}
This. getElementById = function (element_id ){
If (document. getElementById ){
Return document. getElementById (element_id );
}
Else if (document. all ){
Return document. all [element_id];
}
Else if (document. layers ){
Return document. layers [element_id];
} Else {
Return undefined;
}
}
This. set_image = function (imageobject ){
If (! Document. images)
Return;
This. image = imageobject;
}
This. set_textarea = function (textareaobject ){
This. textarea = textareaobject;
This. display_text ();
}
This. set_textid = function (textidstr ){
This. textid = textidstr;
This. display_text ();
}
}
Online demonstration of Sina image player
Package and download Sina image player