Now that we have the plan and the skeleton of our script set up, it is time to think about the tool methods we need to achieve this functionality. In its lowest form, any helper library for DOM scripting should include:
addEvent() for the moment.We add these tool methods to the main object and we are ready to roll:
JavaScript:
slideshow = {
current:0, // current slide number
init:function(){
// initializing and setting the event
// handlers
},
show:function(e){
// event listener, the e will be the
// event object sent by the browser.
},
addEvent:function( obj, type, fn ) {
if ( obj.attachEvent ) {
obj['e'+type+fn] = fn;
obj[type+fn] = function(){
obj['e'+type+fn]( window.event );
}
obj.attachEvent( 'on'+type, obj[type+fn] );
} else
obj.addEventListener( type, fn, false );
},
removeClass:function(o,c){
var rep=o.className.match(' '+c)?' '+c:c;
o.className=o.className.replace(rep,'');
},
addClass:function(o,c){
var test = new RegExp("(^|\\s)" +
c + "(\\s|$)").test(o.className);
if(!test){o.className+=o.className?' '+c:c;}
},
cancelClick:function(e){
if (window.event){
window.event.cancelBubble = true;
window.event.returnValue = false;
}
if (e && e.stopPropagation && e.preventDefault){
e.stopPropagation();
e.preventDefault();
}
}
}
The first thing that needs doing is call the init() method when
the document has finished loading:
JavaScript:
slideshow = {
current:0, // current slide number
init:function(){
// initializing and setting the event
// handlers
},
show:function(e){
// event listener, the e will be the
// event object sent by the browser.
},
addEvent:function( obj, type, fn ) {
if ( obj.attachEvent ) {
obj['e'+type+fn] = fn;
obj[type+fn] = function(){
obj['e'+type+fn]( window.event );
}
obj.attachEvent( 'on'+type, obj[type+fn] );
} else
obj.addEventListener( type, fn, false );
},
removeClass:function(o,c){
var rep=o.className.match(' '+c)?' '+c:c;
o.className=o.className.replace(rep,'');
},
addClass:function(o,c){
var test = new RegExp("(^|\\s)" +
c + "(\\s|$)").test(o.className);
if(!test){o.className+=o.className?' '+c:c;}
},
cancelClick:function(e){
if (window.event){
window.event.cancelBubble = true;
window.event.returnValue = false;
}
if (e && e.stopPropagation && e.preventDefault){
e.stopPropagation();
e.preventDefault();
}
}
}
slideshow.addEvent(window,'load',slideshow.init);





This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License. Written by Christian Heilmann, CSS based on the Yahoo! User Interface Library