1 | (function() |
---|
2 | { |
---|
3 | function _config(pObj, pEvent, pHandler) |
---|
4 | { |
---|
5 | if ( typeof pObj == 'object' ) |
---|
6 | { |
---|
7 | if ( pEvent.substring(0, 2) == 'on' ) |
---|
8 | pEvent = pEvent.substring(2, pEvent.length); |
---|
9 | |
---|
10 | if ( pObj.addEventListener ) |
---|
11 | pObj.addEventListener(pEvent, pHandler, false); |
---|
12 | else if ( pObj.attachEvent ) |
---|
13 | pObj.attachEvent('on' + pEvent, pHandler); |
---|
14 | } |
---|
15 | } |
---|
16 | |
---|
17 | if ( !(top.document.getElementById('instant_messenger_content')) ) |
---|
18 | { |
---|
19 | var _im_content = top.document.createElement('div'); |
---|
20 | _im_content.setAttribute('id', 'instant_messenger_content'); |
---|
21 | _im_content = top.document.body.appendChild(_im_content); |
---|
22 | } |
---|
23 | |
---|
24 | var buffer = ''; |
---|
25 | var _disconnected = false; |
---|
26 | |
---|
27 | var _conn = new IMConnector(path_im); |
---|
28 | var _xtools = new XTools(path_im); |
---|
29 | var _window = new Windows(_xtools, _im_content); |
---|
30 | var _ldap = new InstantMessengerLDAP(_conn, _xtools, _window); |
---|
31 | var _jabber = new Jabber(_conn, _xtools, _window, _ldap); |
---|
32 | |
---|
33 | // XSL preload |
---|
34 | var _xsl_preload = ['chat.xsl','layer.xsl','contacts']; |
---|
35 | var _xsl_preload_legth = _xsl_preload.length; |
---|
36 | for ( var i = 0; i < _xsl_preload_legth; i++ ) |
---|
37 | _xtools.load(_xsl_preload[i]); |
---|
38 | |
---|
39 | var local; |
---|
40 | if ( (local = top.document.getElementById('user_info')) ) |
---|
41 | { |
---|
42 | local.innerHTML = ' ' + local.innerHTML; |
---|
43 | var _status = top.document.createElement('img'); |
---|
44 | _status.setAttribute('id','im_status_src'); |
---|
45 | _status.src = im_available.src; |
---|
46 | |
---|
47 | local.insertBefore(_status, local.firstChild); |
---|
48 | |
---|
49 | _config(_status, 'onclick', _contacts); |
---|
50 | |
---|
51 | var _menu; |
---|
52 | _menu = top.document.createElement('span'); |
---|
53 | _menu.setAttribute('id','fast_menu_im'); |
---|
54 | local.insertBefore(_menu, local.firstChild); |
---|
55 | |
---|
56 | _menu = top.document.createElement('img'); |
---|
57 | _menu.src = im_fast_menu.src; |
---|
58 | local.insertBefore(_menu, local.firstChild); |
---|
59 | |
---|
60 | //var local_old = local.innerHTML ; |
---|
61 | //local.innerHTML = '<img src="' + im_fast_menu.src + '" onclick="javascript:templates.fast_menu();">'; |
---|
62 | //local.innerHTML += '<img id="im_status_src" src="' + im_available.src + '" onclick="javascript:load_im_contacts();"/>'; |
---|
63 | //local.innerHTML += local_old; |
---|
64 | //local.innerHTML += '<div id="instant_messenger_content"></div><span id="fast_menu_im"/>'; |
---|
65 | } |
---|
66 | |
---|
67 | function _stream(data) |
---|
68 | { |
---|
69 | data = data.replace(/^ | $/, ''); |
---|
70 | |
---|
71 | if ( !(data.length) ) |
---|
72 | return false; |
---|
73 | |
---|
74 | if ( data.indexOf('disconnected') != -1 || data.indexOf('</stream:stream>') != -1 ) |
---|
75 | { |
---|
76 | _disconnected = true; |
---|
77 | //alert('disconnected'); |
---|
78 | } |
---|
79 | else |
---|
80 | { |
---|
81 | if ( data.lastIndexOf('>') != data.length - 1) |
---|
82 | buffer += data + ' '; |
---|
83 | else |
---|
84 | { |
---|
85 | if ( buffer.length ) |
---|
86 | { |
---|
87 | data = buffer + data; |
---|
88 | buffer = ''; |
---|
89 | } |
---|
90 | |
---|
91 | // com xmlns ocorre problemas durante o parse entre |
---|
92 | // xml e xsl e por esse motivo está sendo retirado |
---|
93 | data = data.replace(/ xmlns='.*?'/g, ''); |
---|
94 | data = '<handler>' + data + '</handler>'; |
---|
95 | |
---|
96 | var _xml = _xtools.convert(data); |
---|
97 | |
---|
98 | if ( _xml ) |
---|
99 | { |
---|
100 | var _node = _xml.documentElement.firstChild; |
---|
101 | |
---|
102 | while ( _node ) |
---|
103 | { |
---|
104 | if ( _node.nodeType == 1 ) |
---|
105 | _jabber.action(_node); |
---|
106 | //else |
---|
107 | // alert('name : ' + _node.nodeName + "\n\nhas children:" + _node.hasChildNodes() + "\nvalue\n\n" + _node.nodeValue); |
---|
108 | |
---|
109 | _node = _node.nextSibling; |
---|
110 | } |
---|
111 | } |
---|
112 | } |
---|
113 | } |
---|
114 | } |
---|
115 | |
---|
116 | function _request() |
---|
117 | { |
---|
118 | if ( !_disconnected ) |
---|
119 | return _conn.go( |
---|
120 | '$this.Ujabber.listen', |
---|
121 | {'stream':_stream, 'request':_wait}, |
---|
122 | 'classCostructor=read' |
---|
123 | ); |
---|
124 | } |
---|
125 | |
---|
126 | function _wait() |
---|
127 | { |
---|
128 | setTimeout(_request, 3000); |
---|
129 | } |
---|
130 | |
---|
131 | function _reconnect() |
---|
132 | { |
---|
133 | _disconnected = false; |
---|
134 | _request(); |
---|
135 | } |
---|
136 | |
---|
137 | function _disconnect() |
---|
138 | { |
---|
139 | _disconnected = true; |
---|
140 | } |
---|
141 | |
---|
142 | function _contacts() |
---|
143 | { |
---|
144 | var _win = _window.get('contact_list'); |
---|
145 | if ( _win ) |
---|
146 | if ( _win.wm.style.display != 'none' ) |
---|
147 | _win.wm.style.display = 'none'; |
---|
148 | else |
---|
149 | _win.wm.style.display = 'block'; |
---|
150 | else |
---|
151 | if ( !_disconnected ) |
---|
152 | _conn.go('$this.Ujabber.getContacts'); |
---|
153 | } |
---|
154 | |
---|
155 | function Client() |
---|
156 | { |
---|
157 | _request(); |
---|
158 | setTimeout('InstantMessengerContacts()', 3000); |
---|
159 | } |
---|
160 | |
---|
161 | window.InstantMessengerClient = Client; |
---|
162 | window.InstantMessengerReconnect = _reconnect; |
---|
163 | window.InstantMessengerDisconnect = _disconnect; |
---|
164 | window.InstantMessengerContacts = _contacts; |
---|
165 | } |
---|
166 | )(); |
---|