/* ------------------------------------------------------- * SlideShow.es * Author: G. Wade Johnson * Created: 11/13/2003 * Copyright 2003 G. Wade Johnson * Available for any use if this notice is maintained. */ var svgNS = "http://www.w3.org/2000/svg"; var xlinkNS = "http://www.w3.org/1999/xlink"; //constructor function SlideShow( delay, img, ctr, nam ) { this.images = null; this.delay = (null != delay) ? delay : 1000; this.imgElem = img; this.cntrElem = ctr; this.nameElem = nam; this.curr = 0; this.timer = null; this.running = false; } SlideShow.prototype.init = function( arr, prot ) { this.images = arr; this.max = this.images.length - 1; this.display(); _enable_buttons( prot ); }; SlideShow.prototype.display = function() { var image = this.images[this.curr]; this.imgElem.setAttributeNS( xlinkNS, "href", image ); if(null != this.cntrElem) setText(this.cntrElem, this.curr+1); if(null != this.nameElem) { var ndx = image.lastIndexOf( '/' ); if(-1 != ndx) image = image.substring( ndx+1 ); setText(this.nameElem, image); } }; SlideShow.prototype.first_image = function() { this.curr=0; this.display(); }; SlideShow.prototype.first = function() { this.stop(); this.first_image(); }; SlideShow.prototype.last_image = function() { this.curr=this.max; this.display(); }; SlideShow.prototype.last = function() { this.stop(); this.last_image(); }; SlideShow.prototype.next_image = function() { if(++this.curr > this.max) this.curr=0; this.display(); }; SlideShow.prototype.next = function() { this.stop(); this.next_image(); }; SlideShow.prototype.previous_image = function() { if(--this.curr < 0) this.curr=this.max; this.display(); }; SlideShow.prototype.previous = function() { this.stop(); this.previous_image(); }; SlideShow.prototype.nextslide = function() { if(this.running) { if(this.curr == this.max) this.stop(); else this.next_image(); } }; SlideShow.prototype.slideshow = function( objname ) { this.running = true; if(null == this.timer) this.timer = setInterval( objname+".nextslide()", this.delay ); }; SlideShow.prototype.stop = function() { if(null != this.timer) { // clearInterval( this.timer ); // this.timer = null; this.running = false; } }; function setText(elem, str) { var text = document.createTextNode( str ); elem.replaceChild( text, elem.getFirstChild() ); } function _enable_buttons( prot ) { if(prot == null) return; prot.setAttributeNS( null, "pointer-events", "none" ); }