Rename trunk directory to public_html
[ldapsaisie.git] / public_html / includes / js / LSinfosBox.js
1 var LSinfosBox = new Class({
2     initialize: function(options){
3       // Default options
4       this._options = {
5         closeBtn:       0,
6         name:           '',
7         fxDuration:     500,
8         opacity:        0.8,
9         autoClose:      3000
10       };
11       
12       // Load options from argument
13       if ($type(options)=='object') {
14         $each(options,function(val,name) {
15           if ($type(this._options[name])) {
16             this._options[name]=val;
17           }
18         },this);
19       }
20       
21       this.build();
22       
23       this.opened=0;
24     },
25     
26     build: function() {
27       var classes;
28       if (this._options.name!='') {
29         classes='LSinfosBox '+this._options.name;
30       }
31       else {
32         classes='LSinfosBox'
33       }
34       
35       this.core = new Element('div');
36       this.core.addClass(classes);
37       this.core.addEvent('dblclick',this.close.bind(this));
38       
39       if(this._options.closeBtn) {
40         this.closeBtn = new Element('span');
41         this.closeBtn.addClass(classes);
42         this.closeBtn.set('html','X');
43         this.closeBtn.addEvent('click',this.close.bind(this));
44         this.closeBtn.injectInside(this.core);
45       }
46       
47       this.content = new Element('p');
48       this.content.addEvent(classes);
49       this.content.injectInside(this.core);
50       
51       this.fx = new Fx.Tween(
52         this.core,
53         {
54             property: 'opacity',
55             duration: this._options.fxDuration,
56             fps:      30
57         }
58       );
59       
60       this.core.inject(document.body,'top');
61     },
62     
63     isOpened: function() {
64       return this.opened;
65     },
66     
67     open: function() {
68       this.core.setStyle('top',getScrollTop()+10);
69       
70       if (this._options.autoClose>0) {
71         this.closeTime = (new Date()).getTime();
72         this.autoClose.delay((this._options.autoClose+this._options.fxDuration),this,this.closeTime);
73       }
74       
75       if (this.opened) {
76         return true;
77       }
78       
79       this.fx.start(0,this._options.opacity);
80       this.opened = 1;
81       
82     },
83     
84     close: function(withoutEffect) {
85       if (this.opened) {
86         this.opened = 0;
87         if (withoutEffect==1) {
88           this.fx.set(0);
89         }
90         else {
91           this.fx.start(this._options.opacity,0);
92         }
93       }
94     },
95     
96     autoClose: function(time) {
97       if (time==this.closeTime) {
98         this.close();
99         this.closeTime=0;
100       }
101     },
102     
103     addInfo: function(html) {
104       var ul = this.content.getLast("ul");
105       var add = 1;
106       if (!$type(ul)) {
107         add=0;
108         ul = new Element('ul');
109         if (this.content.innerHTML!="") {
110           var c_li = new Element('li');
111           c_li.set('html',this.content.innerHTML);
112           c_li.injectInside(ul);
113           add=1;
114         }
115         this.content.empty();
116         ul.injectInside(this.content);
117       }
118       if (add) {
119         var b_li = new Element('li');
120         b_li.set('html','<hr/>');
121         b_li.injectInside(ul);
122       }
123       var li = new Element('li');
124       li.set('html',html);
125       li.injectInside(ul);
126       this.open();
127     },
128     
129     display: function(html) {
130       if ($type(html)) {
131         this.content.empty();
132         this.content.set('html',html);
133       }
134       this.open();
135     },
136     
137     displayInUl: function(html) {
138       if ($type(html)) {
139         ul = new Element('ul');
140         this.content.empty();
141         ul.set('html',html);
142         ul.inject(this.content);
143       }
144       this.open();
145     },
146     
147     displayOrAdd: function(html) {
148       if (this.isOpened()) {
149         this.addInfo(html);
150       }
151       else {
152         this.displayInUl(html);
153       }
154     }
155 });