Now that we have all the tool methods in place and init() gets called when the window has finished loading, we can start fleshing out the method.
Notice that this is only the init() method, not the whole script. Copying and pasting will also result in errors as there are line numbers!
1: init:function(){
2: if(document.getElementById &&
document.createTextNode){
3: var list = document.getElementById('slideshow');
4: if(list){
5: slideshow.items = list.getElementsByTagName('li');
6: slideshow.all = slideshow.items.length;
7: if(slideshow.all > 1){
8: slideshow.addClass(list, 'js');
9: slideshow.createNav(list);
10: }
11: }
12: slideshow.show();
13: }
14: },
slideshow and does not execute the rest of the method when it is not defined.items and all respectively.js class to the list - thus hiding the list items and applying the different styling.createNav() and provides the list as a parameter.show() to show the slide predefined in the current propertyThe createNav() method uses DOM scripting to generate all the HTML necessary for the slideshow to work (¬ is an enforced linebreak).
1: createNav:function(o){
2: var p = document.createElement('p');
3: slideshow.addClass(p, 'slidenav');
4: slideshow.prev = document.createElement('a');
5: slideshow.prev.setAttribute('href', '#');
6: var templabel = document.createTextNode('<<');
7: slideshow.prev.appendChild(templabel);
8: slideshow.addEvent(slideshow.prev, 'click', ¬
slideshow.show);
9: p.appendChild(slideshow.prev);
10: slideshow.count = document.createElement('span');
11: templabel = document.createTextNode( ¬
(slideshow.current+1) + ' / ' + slideshow.all);
12: slideshow.count.appendChild(templabel);
13: p.appendChild(slideshow.count);
14: slideshow.next = document.createElement('a');
15: slideshow.next.setAttribute('href', '#');
16: var templabel = document.createTextNode('>>');
17: slideshow.next.appendChild(templabel);
18: slideshow.addEvent(slideshow.next, 'click', ¬
slideshow.show);
19: p.appendChild(slideshow.next);
20: o.parentNode.insertBefore(p, o);
21: },
P element which will host the whole slideshow navigation and apply a class called slidenav to it.prev and set a # as the href attribute. This is necessary to make the link appear as a real link and keyboard accessible.show() listener method.SPAN element and storing it in the count property.current property as humans start counting at 1 and not at 0.SPAN and line 13 adds that one to the paragraph.next property.That is all the necessary markup created, all that is left to do is to define a listener method called show() which reacts to the links being clicked.
1: show:function(e){
2: if(this === slideshow.next || this === slideshow.prev){
3: slideshow.removeClass( ¬
slideshow.items[slideshow.current], 'current');
4: var addto = (this === slideshow.next) ? 1 : -1;
5: slideshow.current = slideshow.current + addto;
6: if(slideshow.current < 0){
7: slideshow.current = (slideshow.all-1);
8: }
9: if(slideshow.current > slideshow.all-1){
10: slideshow.current = 0;
11: }
12: }
13: var templabel = document.createTextNode( ¬
(slideshow.current+1) + ' / ' + slideshow.all);
14: slideshow.count.replaceChild(templabel, ¬
slideshow.count.firstChild);
15: slideshow.addClass(slideshow.items[slideshow.current], ¬
'current');
16: slideshow.cancelClick(e);
17: },
e. This is only necessary to call cancelClick() later on.this is returned by addEvent())current class from the currently shown slide. As there was a clicked link this will be possible.current counter should be increased or decreased by comparing this with the next property and line 5 modifies the counter accordingly.current class.cancelClick().That is all there is to this script, you can see it in its full glory by downloading slideshow-plain.js and slideshow.css.
The script works, but is not really maintainable yet.





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