]> www.average.org Git - mkgallery.git/blob - include/controls.js
nitpicks
[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: 9,
30                         buttonClass: 'controlButton',
31                 }
32         },
33
34         initialize: function(name, parent, options){
35                 this.setOptions(this.getOptions(), options);
36                 this.parent = $(parent);
37                 this.container = new Element('div').addClass(name).
38                 setProperties({
39                         id: name,
40                         name: name,
41                 }).setStyles({
42                         zIndex: this.options.zIndex,
43                 }).addEvent('click', function(){
44                         this.options.onClick()
45                 }.bind(this)).injectInside(this.parent);
46                 var buttons = ['prev','stop','play','next','exit','comm'];
47                 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.prevdisabled) { return; }
76                 if (this.show.prev) { this.show.prev() }
77                 else { alert('no method for "prev", file complaint with UN') }
78         },
79
80         stop: function(){
81                 if (this.show.stop) { this.show.stop() }
82                 else { alert('no method for "stop", file complaint with UN') }
83         },
84
85         play: function(){
86                 if (this.show.play) { this.show.play() }
87                 else { alert('no method for "play", file complaint with UN') }
88         },
89
90         next: function(){
91                 if (this.nextdisabled) { return; }
92                 if (this.show.next) { this.show.next() }
93                 else { alert('no method for "next", file complaint with UN') }
94         },
95
96         exit: function(){
97                 if (this.show.exit) { this.show.exit() }
98                 else { alert('no method for "exit", file complaint with UN') }
99         },
100
101         comm: function(){
102                 if (this.show.comm) { this.show.comm() }
103                 else { alert('no method for "comm", file complaint with UN') }
104         },
105
106         info: function(pos, max, ref, txt){
107                 var p1 = pos + 1;
108                 this.refbox.set('html',txt);
109                 this.refbox.set('href',ref);
110                 this.posbox.set('text',p1+' of '+max);
111                 if (p1 < 2) {
112                         this.prevbox.set('id', 'prevDisabled');
113                         this.prevdisabled = true;
114                 } else {
115                         this.prevbox.set('id', 'prev');
116                         this.prevdisabled = false;
117                 }
118                 if (p1 >= max) {
119                         this.nextbox.set('id', 'nextDisabled');
120                         this.nextdisabled = true;
121                 } else {
122                         this.nextbox.set('id', 'next');
123                         this.nextdisabled = false;
124                 }
125         },
126
127         running: function(isrunning){
128                 if (isrunning) {
129                         this.playbox.setStyle('display', 'none');
130                         this.stopbox.setStyle('display', 'block');
131                 } else {
132                         this.stopbox.setStyle('display', 'none');
133                         this.playbox.setStyle('display', 'block');
134                 }
135         },
136 });
137
138 Controls.implement(new Options);
139