]> www.average.org Git - mkgallery.git/blob - include/gallery.js
e4eeef39ebd4ba18b2b8acc47b0fe105013091fc
[mkgallery.git] / include / gallery.js
1 /*
2         $Id$
3
4         This is a part of mkgallery.pl suite
5         http://www.average.org/mkgallery/
6
7         Uses mootools (1.2) http://www.mootools.net/
8         Uses multibox http://www.phatfusion.net/multibox/
9         Inspired by slideshow http://www.phatfusion.net/slideshow/
10 */
11
12 /*
13         Use slideshow classes with the index generated by mkgallery.pl
14 */
15
16 /* Initialize everything, to be called on domready */
17 function init_gallery() {
18
19         /* List of lists of img variations. Each image variation is
20          * a three-element array: [width, height, url]. Index of the
21          * outer array is the global ID.
22          *
23          * [
24          *  [ id, title, [
25          *                [ width, height, url ]
26          *                ...
27          *               ]
28          *   ...
29          *  ]
30          *  ...
31          * ]
32         */
33         var vimgs=[];
34
35         /* resolve string ID to index No which is the index in vimgs[] array */
36         var rimgs=[];
37
38         /* Populate images list */
39
40         $$('div.varimages').each(function(el,i){
41                 rimgs[el.id] = i;
42                 vimgs[i] = [el.id, el.title, []];
43                 el.getElements('a').each(function(ael,j){
44                         dim = /(\d+)[^\d](\d+)/.exec(ael.text);
45                         w = dim[1];
46                         h = dim[2];
47                         vimgs[i][2][j]=[w,h,ael.href];
48                 });
49         });
50
51                         /* debugging output
52         var msg='loaded '+vimgs.length+' image descriptions:';
53         vimgs.each(function(vimg,i){
54                 msg+='\nid='+i+' ('+vimg[0]+') title='+vimg[1];
55                 vimg[2].each(function(vv,i){
56                         msg+='\n     w='+vv[0]+' h='+vv[1]+' url='+vv[2];
57                 });
58         });
59         alert(msg);
60                         /* end debugging output */
61
62         /* Initialize objects */
63
64         var ovlparams = {};
65         ovl = new overlay(ovlparams);
66
67         var iboxparams = {
68                 overlay: ovl,
69                 showNumbers: false,
70                 showControls: true,
71                 openFromLink: false,
72                 movieWidth: 640,
73                 movieHeight: 480,
74                 descClassName: 'infoBoxDesc',
75         };
76         ibox = new multiBox('infoBox', iboxparams);
77
78         var winparms = {
79                 tohide: 'indexContainer',
80         };
81         var showwin = new showWindow('slideshowContainer',winparms);
82
83         var ctlparams = {
84         };
85         var ctl = new Controls('slideshowControls','slideshowContainer',
86                                 ctlparams);
87
88         var showparms = {
89                 cbStart: function(){ showwin.show(); },
90                 cbExit: function(){ showwin.hide(); },
91         };
92         var show = new Show(vimgs,showwin,ctl,showparms);
93
94         /* Update HTML */
95
96         $$('.conceal').each(function(el){
97                 el.setStyle('display', 'none');
98         });
99         $$('a.infoBox').each(function(el){
100                 var url=el.get('href');
101                 el.set('href',url+'?conceal');
102         });
103
104         $$('a.showStart').each(function(el){
105                 el.addEvent('click',
106                                 show.start.bind(show,[rimgs[el.get('id')],1]));
107         });
108         $$('a.showImage').each(function(el){
109                 el.addEvent('click',
110                                 show.start.bind(show,[rimgs[el.get('id')],0]));
111         });
112
113         /* Determine if we need to go directly into show mode */
114
115         parsedurl = parseUrl(document.URL);
116         /* alert('Anchor: '+parsedurl['anchor']+'\nURL: '+document.URL); */
117         if ($chk(parsedurl['anchor'])){
118                 show.start(rimgs[parsedurl['anchor']],0);
119         }
120 }
121
122 /* Initialization */
123 window.addEvent('domready',init_gallery)