OSDN Git Service

add eclipse related files
[cloudmanganw/git_repo.git] / src / jp / sourceforge / manganetwork / page / javascripts / spinelz / switcher.js
1 var Switcher = Class.create();
2 Switcher.classNames = {
3   open:  'switcher_state_open',
4   close: 'switcher_state_close'
5 }
6 Switcher.prototype = {
7   initialize: function(sw, content) {
8     this.options = Object.extend({
9       open:        false,
10       duration:    0.4,
11       beforeOpen:  Prototype.emptyFunction,
12       afterOpen:   Prototype.emptyFunction,
13       beforeClose: Prototype.emptyFunction,
14       afterClose:  Prototype.emptyFunction,
15       effect:      false,
16       cssPrefix:   'custom_'
17     }, arguments[2] || {});
18
19     this.sw = $(sw);
20     this.content = $(content);
21
22     var customCss = CssUtil.appendPrefix(this.options.cssPrefix, Switcher.classNames);
23     this.classNames = new CssUtil([Switcher.classNames, customCss]);
24
25     if (this.options.open) {
26       Element.show(this.content);
27       this.classNames.addClassNames(this.sw, 'open');
28     } else {
29       Element.hide(this.content);
30       this.classNames.addClassNames(this.sw, 'close');
31     }
32
33     Event.observe(this.sw, 'click', this.toggle.bind(this));
34   },
35
36   toggle: function() {
37     if (Element.hasClassName(this.sw, Switcher.classNames.close)) {
38       this.open();
39     }else {
40       this.close();
41     }
42   },
43
44   open: function() {
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});
49     } else {
50       Element.show(this.content);
51     }
52     this.options.afterOpen(this.content);
53   },
54
55   close: function() {
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});
60     } else {
61       Element.hide(this.content);
62     }
63     this.options.afterClose(this.content);
64   }
65 }