switch to "new" slideshow (which is not working yet)
[mkgallery.git] / include / controls.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         Inspired by slideshow http://www.phatfusion.net/slideshow/
9 */
10
11 /*
12         Slideshow controls
13
14   - First, initialize "controls" without hooks to the "show".
15   - Then, initialize "show" passing "controls" object as an argument to
16     the constructor.
17   - From the "show" constructuor, call "controls"'s "complete initialization"
18     method passing them "this", so that they will be able to access "show"'s
19     methods.
20   - Because this is slightly simpler than symmetric "co-routine" approach,
21     and arguably better suits the task at hand.
22 */
23
24 var Controls = new Class({
25
26         getOptions: function(){
27                 return {
28                         onClick: $empty,
29                         zIndex: 3,
30                         buttonClass: 'controlButton',
31                         buttons: ['prev','stop','play','next','exit','comm'],
32                 }
33         },
34
35         initialize: function(name, parent, options){
36                 this.setOptions(this.getOptions(), options);
37                 this.parent = $(parent);
38                 this.container = new Element('div').addClass(name).
39                 setProperties({
40                         id: name,
41                         name: name,
42                 }).setStyles({
43                         zIndex: this.options.zIndex,
44                 }).addEvent('click', function(){
45                         this.options.onClick()
46                 }.bind(this)).injectInside(this.parent);
47                 this.options.buttons.each(function(el){
48                         var sub = new Element('div');
49                         sub.addClass(this.options.buttonClass).setProperties({
50                                 id: el,
51                                 name: el,
52                                 title: el,
53                         }).addEvent('click', function(){
54                                 this[el]();
55                         }.bind(this)).injectInside(this.container);
56                         this[el+'box'] = sub;
57                 },this);
58                 this.posbox = new Element('span').
59                 addClass('controlPosition').setProperties({
60                         id: 'controlPosition',
61                 }).injectInside(this.commbox);
62                 this.refbox = new Element('a', {
63                         href: 'javascript: void(1);',
64                         html: 'title',
65                 }).addClass('controlRef').setProperties({
66                         id: 'controlRef',
67                 }).injectInside(this.commbox);
68         },
69
70         registershow: function(show){
71                 this.show = show;
72         },
73
74         prev: function(){
75                 if (this.show.prev) { this.show.prev() }
76                 else { alert('no method for "prev", file complaint with UN') }
77         },
78
79         stop: function(){
80                 if (this.show.stop) { this.show.stop() }
81                 else { alert('no method for "stop", file complaint with UN') }
82         },
83
84         play: function(){
85                 if (this.show.play) { this.show.play() }
86                 else { alert('no method for "play", file complaint with UN') }
87         },
88
89         next: function(){
90                 if (this.show.next) { this.show.next() }
91                 else { alert('no method for "next", file complaint with UN') }
92         },
93
94         exit: function(){
95                 if (this.show.exit) { this.show.exit() }
96                 else { alert('no method for "exit", file complaint with UN') }
97         },
98
99         comm: function(){
100                 if (this.show.comm) { this.show.comm() }
101                 else { alert('no method for "comm", file complaint with UN') }
102         },
103
104         info: function(pos, max, ref, txt){
105                 var msg = 'pos='+pos+', max='+max+', ref='+ref+', txt='+txt;
106                 this.refbox.set('html',txt);
107                 this.refbox.set('href',ref);
108                 this.posbox.set('text',pos+' of '+max);
109         },
110
111         running: function(isrunning){
112                 if (isrunning) {
113                         this.playbox.setStyle('display', 'none');
114                         this.stopbox.setStyle('display', 'block');
115                 } else {
116                         this.stopbox.setStyle('display', 'none');
117                         this.playbox.setStyle('display', 'block');
118                 }
119         },
120 });
121 Controls.implement(new Options);
122