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

Revision 311, 7.5 KB checked in by niltonneto, 16 years ago (diff)

Correções críticas para funcionalidades já existentes.

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