1 var Switcher = Class.create();
2 Switcher.classNames = {
3 open: 'switcher_state_open',
4 close: 'switcher_state_close'
7 initialize: function(sw, content) {
8 this.options = Object.extend({
11 beforeOpen: Prototype.emptyFunction,
12 afterOpen: Prototype.emptyFunction,
13 beforeClose: Prototype.emptyFunction,
14 afterClose: Prototype.emptyFunction,
17 }, arguments[2] || {});
20 this.content = $(content);
22 var customCss = CssUtil.appendPrefix(this.options.cssPrefix, Switcher.classNames);
23 this.classNames = new CssUtil([Switcher.classNames, customCss]);
25 if (this.options.open) {
26 Element.show(this.content);
27 this.classNames.addClassNames(this.sw, 'open');
29 Element.hide(this.content);
30 this.classNames.addClassNames(this.sw, 'close');
33 Event.observe(this.sw, 'click', this.toggle.bind(this));
37 if (Element.hasClassName(this.sw, Switcher.classNames.close)) {
45 this.options.beforeOpen(this.content);
46 this.classNames.refreshClassNames(this.sw, 'open');
47 if (this.options.effect) {
48 new Effect.BlindDown(this.content, {duration: this.options.duration});
50 Element.show(this.content);
52 this.options.afterOpen(this.content);
56 this.options.beforeClose(this.content);
57 this.classNames.refreshClassNames(this.sw, 'close');
58 if (this.options.effect) {
59 new Effect.BlindUp(this.content, {duration: this.options.duration});
61 Element.hide(this.content);
63 this.options.afterClose(this.content);