source: trunk/instant_messenger/js/windows.js @ 305

Revision 305, 7.3 KB checked in by niltonneto, 16 years ago (diff)

Correçoes

Line 
1(function()
2{
3        var _drag_drop = new DragDrop();
4
5        var _xtools;
6        var index = 10000;
7        var _all_windows = [];
8
9        function _load(pId)
10        {
11                if ( !(top.document.getElementById(pId + '__window_master')) )
12                {
13                        var xml = _xtools.xml('window');
14
15                        var name = xml.createElement('name');
16                        name.appendChild(xml.createTextNode(pId));
17                        xml.documentElement.appendChild(name);
18
19                        var _window = top.document.createElement("div");
20                        _window.innerHTML = _xtools.parse(xml, 'window.xsl');
21                        _window.setAttribute('id', pId + '__window_master');
22                        _window.setAttribute('class', 'window');
23
24                        _window = this._TARGET.appendChild(_window);
25
26                        _focus(_window);
27
28                        function _click(e)
29                        {
30                                _focus(e);
31                                _window.oncontextmenu = new Function("return false");
32                                return false;
33                        }
34
35                        _config(_window, 'onmousedown', _click);
36
37                        _drag_drop.drag(_window);
38                        _window.childNodes[1].setAttribute('dragdrop_child','true');
39                        _window.childNodes[1].childNodes[0].setAttribute('dragdrop_child','true');
40                        _window.childNodes[1].childNodes[1].setAttribute('dragdrop_child','true');
41
42                        _config(_window.childNodes[1].childNodes[1].childNodes[0], 'onclick', _button);
43                        _config(_window.childNodes[1].childNodes[1].childNodes[1], 'onclick', _button);
44                        _config(_window.childNodes[1].childNodes[1].childNodes[2], 'onclick', _button);
45
46                        _all_windows[pId + '__window_master'] = {
47                                'id' : pId,
48                                'wm' : _window, // wm - window master
49                                'wt' : _window.childNodes[1].firstChild, // wt - window title
50                                'bc' : _window.childNodes[1].childNodes[1].childNodes[0], // bc - button close
51                                'bx' : _window.childNodes[1].childNodes[1].childNodes[1], // bx - button maximize
52                                'bz' : _window.childNodes[1].childNodes[1].childNodes[2], // bz - button minimize
53                                'wc' : _window.childNodes[2].firstChild, // wc - window content
54                                'wf' : _window.childNodes[3], // wf - window footer
55                                'button' : _button,
56                                'content' : _content,
57                                'focus' : _focus,
58                                'position' : _position,
59                                'size' : _size,
60                                'title' : _title
61                        };
62
63                }
64                return _all_windows[pId + '__window_master'];
65        }
66
67        function _browser()
68        {
69                var _width = 0, _height = 0;
70                if ( typeof( window.innerWidth ) == 'number' )
71                {
72                        //Non-IE
73                        _width = top.window.innerWidth;
74                        _height = top.window.innerHeight;
75                }
76                else if ( top.document.documentElement && ( top.document.documentElement.clientWidth || top.document.documentElement.clientHeight ) )
77                {
78                        //IE 6+ in 'standards compliant mode'
79                        _width = top.document.documentElement.clientWidth;
80                        _height = top.document.documentElement.clientHeight;
81                }
82                else if( top.document.body && ( top.document.body.clientWidth || top.document.body.clientHeight ) )
83                {
84                        //IE 4 compatible
85                        _width = top.document.body.clientWidth;
86                        _height = top.document.body.clientHeight;
87                }
88
89                return {'width' : _width, 'height' : _height}
90        }
91
92        function _button()
93        {
94                var b = arguments[0];
95                b = ( !b.type ) ?
96                        b : ( b.target ) ?
97                                b.target : b.srcElement;
98
99                var w = b.parentNode.parentNode.parentNode;
100                switch ( b.title )
101                {
102                        case 'close' :
103                                w.parentNode.removeChild(w);
104                                delete _all_windows[w.id];
105                        break;
106                        case 'maximize' :
107                                if ( !w.getAttribute('wParams') )
108                                {
109                                        var _wParams  = (parseFloat(w.style.width) - 13);
110                                                _wParams += ':' + parseFloat(w.childNodes[2].firstChild.style.height);
111                                                _wParams += ':' + parseFloat(w.style.left);
112                                                _wParams += ':' + parseFloat(w.style.right);
113                                                _wParams += ':' + parseFloat(w.style.top);
114                                                _wParams += ':' + parseFloat(w.style.bottom);
115                                        w.setAttribute('wParams', _wParams);
116
117                                        var _bwr = _browser();
118                                        w.style.top = "0px";
119                                        w.style.left = "0px";
120                                        w.style.height = "100%";
121                                        w.style.width = "100%";
122
123                                        w.childNodes[2].firstChild.style.height = (_bwr.height - 41) + "px";
124                                }
125                                else
126                                {
127                                        var _wParams = w.getAttribute('wParams').split(':');
128                                        w.removeAttribute('wParams');
129
130                                        var _style = w.getAttribute('style');
131                                        if ( typeof _style == 'object' && _style.cssText )
132                                                _style = _style.cssText;
133
134                                        _style = _style.replace(/height: ?100%;?/i, '').replace(/width: ?100%;?/i, '');
135                                        _style = _style.replace(/left: ?0px;?/i, '').replace(/top: ?0px;?/i, '');
136
137                                        // for IE
138                                        if ( w.style.cssText )
139                                                w.style.cssText = '';
140
141                                        w.setAttribute('style', _style);
142
143                                        w = _all_windows[w.id];
144
145                                        _style = w.wc.getAttribute('style');
146                                        if ( typeof _style == 'object' && _style.cssText )
147                                                _style = _style.cssText;
148
149                                        _style = _style.replace(/height: ?\d+px;?/i, '');
150
151                                        // for IE
152                                        if ( w.wc.style.cssText )
153                                                w.wc.style.cssText = '';
154
155                                        w.wc.setAttribute('style', _style);
156
157                                        w.size(parseFloat(_wParams[0]), parseFloat(_wParams[1]));
158
159                                        var x = '';
160                                        var _right = false;
161                                        if ( !isNaN(_wParams[2]) )
162                                                x = parseFloat(_wParams[2]);
163                                        else if ( !isNaN(_wParams[3]) )
164                                        {
165                                                x = parseFloat(_wParams[3]);
166                                                _right = true;
167                                        }
168
169                                        var y = '';
170                                        var _bottom = false;
171                                        if ( !isNaN(_wParams[4]) )
172                                                y = parseFloat(_wParams[4]);
173                                        else if ( !isNaN(_wParams[5]) )
174                                        {
175                                                y = parseFloat(_wParams[5]);
176                                                _bottom = true;
177                                        }
178
179                                        w.position(x, y, _right, _bottom);
180                                }
181                        break;
182                        case 'minimize' :
183                                w.style.display = 'none';
184                        break;
185                }
186        }
187
188        function _config(pObj, pEvent, pHandler)
189        {
190                if ( typeof pObj == 'object' )
191                {
192                        if ( pEvent.substring(0, 2) == 'on' )
193                                pEvent = pEvent.substring(2, pEvent.length);
194
195                        if ( pObj.addEventListener )
196                                pObj.addEventListener(pEvent, pHandler, false);
197                        else if ( pObj.attachEvent )
198                                pObj.attachEvent('on' + pEvent, pHandler);
199                }
200        }
201
202        function _content()
203        {
204                var _content = this.wc;
205                while ( _content.hasChildNodes() )
206                        _content.removeChild(_content.firstChild);
207                var l = arguments.length;
208                for ( var i = 0; i < l; i++ )
209                        if ( typeof arguments[i] == 'object' )
210                                _content.appendChild(arguments[i]);
211                        else if ( typeof arguments[i] == 'string' )
212                                _content.innerHTML += arguments[i];
213        }
214
215        function _focus()
216        {
217                var w;
218                if ( arguments.length )
219                        w = arguments[0];
220                else
221                        w = this.wm;
222
223                w = ( !w.type ) ?
224                        w : ( w.target ) ?
225                                w.target : w.srcElement;
226
227                while ( w.id.indexOf('__window_master') == -1 )
228                        w = w.parentNode;
229
230                index += 10;
231                w.style.zIndex = index;
232        }
233
234        function _get(_pId)
235        {
236                var _win = false;
237                if ( _all_windows[_pId + '__window_master'] )
238                        _win = _all_windows[_pId + '__window_master'];
239                return _win;
240        }
241
242        function _position(pX, pY)
243        {
244                this.wm.style.position = 'absolute';
245
246                if ( typeof pX == 'number' )
247                        if ( arguments[2] === true )
248                                this.wm.style.right = pX + 'px';
249                        else
250                                this.wm.style.left = pX + 'px';
251
252                if ( typeof pY == 'number' )
253                        if ( arguments[3] === true )
254                                this.wm.style.bottom = pY + 'px';
255                        else
256                                this.wm.style.top = pY + 'px';
257        }
258
259        function _size(pWidth, pHeight)
260        {
261                if ( typeof pWidth == 'number' && !isNaN(pWidth) )
262                        this.wm.style.width = (13 + pWidth) + 'px';
263
264                if ( typeof pHeight == 'number' && !isNaN(pHeight) )
265                        this.wc.style.height = pHeight + 'px';
266        }
267
268        function _title(pTitle)
269        {
270                var _title = this.wt;
271                while ( _title.hasChildNodes() )
272                        _title.removeChild(_title.firstChild);
273                _title.appendChild(top.document.createTextNode(pTitle));
274        }
275
276        function Windows()
277        {
278                var _argv = arguments;
279                this._TARGET = ( _argv[_argv.length - 1].id ) ?
280                        _argv[_argv.length - 1] : document.body;
281
282                _xtools = arguments[0];
283        }
284
285        Windows.prototype.load = _load;
286        Windows.prototype.get = _get;
287        window.Windows = Windows;
288}
289)();
Note: See TracBrowser for help on using the repository browser.