View difference between Paste ID: AE1XWm4Q and
SHOW:
|
|
- or go back to the newest paste.
1 | - | |
1 | + | function slideshow_load() |
2 | { | |
3 | var slideshow = | |
4 | { | |
5 | showwin : null, | |
6 | showimg : null, | |
7 | list : null, | |
8 | current : 0, | |
9 | baseURL : wgServer + wgArticlePath.replace( "$1" , "File:"), | |
10 | ||
11 | nextImage : function() | |
12 | { | |
13 | with(slideshow) | |
14 | { | |
15 | if( showwin != null && showwin.document != null ) | |
16 | { | |
17 | showimg.src = 'http://toolserver.org/tsthumb/tsthumb?w=800&h=800&domain=commons.wikimedia.org&f='+encodeURIComponent(slideshow.list[slideshow.current]); | |
18 | current++; | |
19 | if( current >= list.length ) current = 0; | |
20 | window.setTimeout(slideshow.nextImage,3000); | |
21 | } | |
22 | } | |
23 | }, | |
24 | ||
25 | showButton : function() { this.startButton.style.visibility = 'visible'; }, | |
26 | hideButton : function() { this.startButton.style.visibility = 'hidden'; }, | |
27 | ||
28 | // cross-browser event attachment (John Resig) | |
29 | // http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html | |
30 | addEvent : function ( obj, type, fn ) | |
31 | { | |
32 | if (obj.addEventListener) | |
33 | obj.addEventListener( type, fn, false ); | |
34 | else if (obj.attachEvent) | |
35 | { | |
36 | obj["e"+type+fn] = fn; | |
37 | obj[type+fn] = function() { obj["e"+type+fn]( window.event ); } | |
38 | obj.attachEvent( "on"+type, obj[type+fn] ); | |
39 | } | |
40 | }, | |
41 | ||
42 | start : function( e ) | |
43 | { | |
44 | slideshow.list = new Array(); | |
45 | slideshow.current = 0; | |
46 | var links; | |
47 | ||
48 | if( typeof(this.gallery) != 'undefined' ) | |
49 | { | |
50 | slideshow.showwin = window.open('', 'showwin', 'left=0,top=0,width=' + screen.width + ',height=' + screen.height + ',toolbar=0,resizable=0,fullscreen=1'); | |
51 | ||
52 | var divs = this.gallery.getElementsByTagName('div'); | |
53 | for( var key=0; key< divs.length; key++ ) | |
54 | { | |
55 | if( divs[key].className == 'thumb' ) | |
56 | { | |
57 | links = divs[key].getElementsByTagName('a'); | |
58 | if( links.length > 0 && links[0].href.substr( 0, slideshow.baseURL.length ) == slideshow.baseURL ) | |
59 | slideshow.list.push( links[0].href.substr( slideshow.baseURL.length ) ); | |
60 | } | |
61 | } | |
62 | ||
63 | slideshow.showwin.document.open('text/html'); | |
64 | slideshow.showwin.document.write('<html><body><table border="0" width="100%" height="100%"><tr><td valign="center" align="center"><img id="showimg"></td></tr></table></body></html>'); | |
65 | slideshow.showwin.document.close(); | |
66 | ||
67 | slideshow.showimg = slideshow.showwin.document.getElementById('showimg'); | |
68 | slideshow.nextImage(); | |
69 | } | |
70 | }, | |
71 | ||
72 | install : function() | |
73 | { | |
74 | var galleries = document.getElementsByTagName('table'); | |
75 | var cells; | |
76 | var button; | |
77 | ||
78 | for( var key=0; key < galleries.length; key++ ) | |
79 | { | |
80 | if( galleries[key].className == 'gallery' ) | |
81 | { | |
82 | cells = galleries[key].getElementsByTagName('div'); | |
83 | if( cells.length > 0 ) | |
84 | { | |
85 | button = document.createElement('div'); | |
86 | button.style.border = '1px solid gray'; | |
87 | button.style.position = 'absolute'; | |
88 | button.style.padding = '0.5em'; | |
89 | button.style.backgroundColor = '#ddffdd'; | |
90 | button.style.top = '0.5em'; | |
91 | button.style.left = '0.5em'; | |
92 | button.style.cursor = 'pointer'; | |
93 | button.style.visibility = 'hidden'; | |
94 | button.gallery = galleries[key]; | |
95 | ||
96 | button.appendChild( document.createTextNode( 'Slideshow' ) ); | |
97 | slideshow.addEvent( button, 'click', slideshow.start ); | |
98 | ||
99 | galleries[key].startButton = button; | |
100 | slideshow.addEvent( galleries[key], 'mouseover', slideshow.showButton ); | |
101 | slideshow.addEvent( galleries[key], 'mouseout', slideshow.hideButton ); | |
102 | ||
103 | cells[0].style.position = 'relative'; | |
104 | cells[0].insertBefore( button, cells[0].childNodes[0] ); | |
105 | } | |
106 | ||
107 | } | |
108 | } | |
109 | ||
110 | } | |
111 | } | |
112 | ||
113 | addOnloadHook(slideshow.install); | |
114 | } | |
115 | ||
116 | if (window.addEventListener) | |
117 | window.addEventListener('load', slideshow_load, false); // W3C DOM | |
118 | else | |
119 | window.attachEvent('onload', slideshow_load); // MSIE |