commit | author | age
|
4e17e6
|
1 |
/* |
T |
2 |
+-----------------------------------------------------------------------+ |
e019f2
|
3 |
| Roundcube common js library | |
4e17e6
|
4 |
| | |
e019f2
|
5 |
| This file is part of the Roundcube web development suite | |
e224b0
|
6 |
| Copyright (C) 2005-2007, The Roundcube Dev Team | |
30233b
|
7 |
| Licensed under the GNU GPL | |
4e17e6
|
8 |
| | |
T |
9 |
+-----------------------------------------------------------------------+ |
|
10 |
| Author: Thomas Bruederli <roundcube@gmail.com> | |
|
11 |
+-----------------------------------------------------------------------+ |
5e3512
|
12 |
|
T |
13 |
$Id$ |
4e17e6
|
14 |
*/ |
T |
15 |
|
6b47de
|
16 |
// Constants |
T |
17 |
var CONTROL_KEY = 1; |
|
18 |
var SHIFT_KEY = 2; |
|
19 |
var CONTROL_SHIFT_KEY = 3; |
4e17e6
|
20 |
|
6b47de
|
21 |
|
T |
22 |
/** |
|
23 |
* Default browser check class |
186537
|
24 |
* @constructor |
6b47de
|
25 |
*/ |
4e17e6
|
26 |
function roundcube_browser() |
8fa922
|
27 |
{ |
8fd1cf
|
28 |
var n = navigator; |
A |
29 |
|
|
30 |
this.ver = parseFloat(n.appVersion); |
|
31 |
this.appver = n.appVersion; |
|
32 |
this.agent = n.userAgent; |
|
33 |
this.agent_lc = n.userAgent.toLowerCase(); |
|
34 |
this.name = n.appName; |
|
35 |
this.vendor = n.vendor ? n.vendor : ''; |
|
36 |
this.vendver = n.vendorSub ? parseFloat(n.vendorSub) : 0; |
|
37 |
this.product = n.product ? n.product : ''; |
|
38 |
this.platform = String(n.platform).toLowerCase(); |
|
39 |
this.lang = (n.language) ? n.language.substring(0,2) : |
|
40 |
(n.browserLanguage) ? n.browserLanguage.substring(0,2) : |
|
41 |
(n.systemLanguage) ? n.systemLanguage.substring(0,2) : 'en'; |
4e17e6
|
42 |
|
89e31b
|
43 |
this.win = (this.platform.indexOf('win') >= 0); |
T |
44 |
this.mac = (this.platform.indexOf('mac') >= 0); |
|
45 |
this.linux = (this.platform.indexOf('linux') >= 0); |
|
46 |
this.unix = (this.platform.indexOf('unix') >= 0); |
4e17e6
|
47 |
|
T |
48 |
this.dom = document.getElementById ? true : false; |
|
49 |
this.dom2 = (document.addEventListener && document.removeEventListener); |
|
50 |
|
b231f6
|
51 |
this.ie = (document.all && !window.opera); |
4e17e6
|
52 |
this.ie4 = (this.ie && !this.dom); |
T |
53 |
this.ie5 = (this.dom && this.appver.indexOf('MSIE 5')>0); |
f8dae9
|
54 |
this.ie8 = (this.dom && this.appver.indexOf('MSIE 8')>0); |
8b7f5a
|
55 |
this.ie7 = (this.dom && this.appver.indexOf('MSIE 7')>0); |
f8dae9
|
56 |
this.ie6 = (this.dom && !this.ie8 && !this.ie7 && this.appver.indexOf('MSIE 6')>0); |
4e17e6
|
57 |
|
89e31b
|
58 |
this.ns = ((this.ver < 5 && this.name == 'Netscape') || (this.ver >= 5 && this.vendor.indexOf('Netscape') >= 0)); |
T |
59 |
this.chrome = (this.agent_lc.indexOf('chrome') > 0); |
8fd1cf
|
60 |
this.safari = (!this.chrome && (this.agent_lc.indexOf('safari') > 0 || this.agent_lc.indexOf('applewebkit') > 0)); |
e23b1d
|
61 |
this.mz = (this.dom && !this.ie && !this.ns && !this.chrome && !this.safari && this.agent.indexOf('Mozilla') >= 0); |
372d3b
|
62 |
this.konq = (this.agent_lc.indexOf('konqueror') > 0); |
89e31b
|
63 |
this.iphone = (this.safari && this.agent_lc.indexOf('iphone') > 0); |
T |
64 |
this.ipad = (this.safari && this.agent_lc.indexOf('ipad') > 0); |
|
65 |
this.opera = window.opera ? true : false; |
4e17e6
|
66 |
|
89e31b
|
67 |
if (this.opera && window.RegExp) |
8fd1cf
|
68 |
this.vendver = (/opera(\s|\/)([0-9\.]+)/.test(this.agent_lc)) ? parseFloat(RegExp.$2) : -1; |
89e31b
|
69 |
else if (this.chrome && window.RegExp) |
8fd1cf
|
70 |
this.vendver = (/chrome\/([0-9\.]+)/.test(this.agent_lc)) ? parseFloat(RegExp.$1) : 0; |
89e31b
|
71 |
else if (!this.vendver && this.safari) |
8fd1cf
|
72 |
this.vendver = (/(safari|applewebkit)\/([0-9]+)/.test(this.agent_lc)) ? parseInt(RegExp.$2) : 0; |
89e31b
|
73 |
else if ((!this.vendver && this.mz) || this.agent.indexOf('Camino')>0) |
4e17e6
|
74 |
this.vendver = (/rv:([0-9\.]+)/.test(this.agent)) ? parseFloat(RegExp.$1) : 0; |
89e31b
|
75 |
else if (this.ie && window.RegExp) |
8fd1cf
|
76 |
this.vendver = (/msie\s+([0-9\.]+)/.test(this.agent_lc)) ? parseFloat(RegExp.$1) : 0; |
89e31b
|
77 |
else if (this.konq && window.RegExp) |
8fd1cf
|
78 |
this.vendver = (/khtml\/([0-9\.]+)/.test(this.agent_lc)) ? parseFloat(RegExp.$1) : 0; |
42b113
|
79 |
|
4e17e6
|
80 |
// get real language out of safari's user agent |
129aef
|
81 |
if (this.safari && (/;\s+([a-z]{2})-[a-z]{2}\)/.test(this.agent_lc))) |
4e17e6
|
82 |
this.lang = RegExp.$1; |
T |
83 |
|
|
84 |
this.dhtml = ((this.ie4 && this.win) || this.ie5 || this.ie6 || this.ns4 || this.mz); |
|
85 |
this.vml = (this.win && this.ie && this.dom && !this.opera); |
89e31b
|
86 |
this.pngalpha = (this.mz || (this.opera && this.vendver >= 6) || (this.ie && this.mac && this.vendver >= 5) || |
T |
87 |
(this.ie && this.win && this.vendver >= 5.5) || this.safari); |
|
88 |
this.opacity = (this.mz || (this.ie && this.vendver >= 5.5 && !this.opera) || (this.safari && this.vendver >= 100)); |
8fd1cf
|
89 |
this.cookies = n.cookieEnabled; |
b231f6
|
90 |
|
a95e0e
|
91 |
// test for XMLHTTP support |
89e31b
|
92 |
this.xmlhttp_test = function() |
T |
93 |
{ |
a95e0e
|
94 |
var activeX_test = new Function("try{var o=new ActiveXObject('Microsoft.XMLHTTP');return true;}catch(err){return false;}"); |
89e31b
|
95 |
this.xmlhttp = (window.XMLHttpRequest || (window.ActiveXObject && activeX_test())); |
a95e0e
|
96 |
return this.xmlhttp; |
89e31b
|
97 |
}; |
b231f6
|
98 |
|
89e31b
|
99 |
// set class names to html tag according to the current user agent detection |
T |
100 |
// this allows browser-specific css selectors like "html.chrome .someclass" |
|
101 |
this.set_html_class = function() |
|
102 |
{ |
|
103 |
var classname = ' js'; |
|
104 |
|
|
105 |
if (this.ie) { |
|
106 |
classname += ' ie'; |
|
107 |
if (this.ie5) |
|
108 |
classname += ' ie5'; |
|
109 |
else if (this.ie6) |
|
110 |
classname += ' ie6'; |
|
111 |
else if (this.ie7) |
|
112 |
classname += ' ie7'; |
|
113 |
else if (this.ie8) |
|
114 |
classname += ' ie8'; |
|
115 |
} |
|
116 |
else if (this.opera) |
|
117 |
classname += ' opera'; |
|
118 |
else if (this.konq) |
|
119 |
classname += ' konqueror'; |
|
120 |
else if (this.safari) |
|
121 |
classname += ' safari'; |
|
122 |
|
|
123 |
if (this.chrome) |
|
124 |
classname += ' chrome'; |
|
125 |
else if (this.iphone) |
|
126 |
classname += ' iphone'; |
|
127 |
else if (this.ipad) |
|
128 |
classname += ' ipad'; |
|
129 |
|
|
130 |
if (document.documentElement) |
|
131 |
document.documentElement.className += classname; |
|
132 |
}; |
8fa922
|
133 |
}; |
4e17e6
|
134 |
|
T |
135 |
|
cc97ea
|
136 |
// static functions for DOM event handling |
6b47de
|
137 |
var rcube_event = { |
T |
138 |
|
a0ce2f
|
139 |
/** |
T |
140 |
* returns the event target element |
|
141 |
*/ |
|
142 |
get_target: function(e) |
|
143 |
{ |
|
144 |
e = e || window.event; |
|
145 |
return e && e.target ? e.target : e.srcElement; |
|
146 |
}, |
|
147 |
|
|
148 |
/** |
|
149 |
* returns the event key code |
|
150 |
*/ |
|
151 |
get_keycode: function(e) |
|
152 |
{ |
|
153 |
e = e || window.event; |
|
154 |
return e && e.keyCode ? e.keyCode : (e && e.which ? e.which : 0); |
|
155 |
}, |
9bbb17
|
156 |
|
6b47de
|
157 |
/** |
f89f03
|
158 |
* returns the event key code |
T |
159 |
*/ |
|
160 |
get_button: function(e) |
|
161 |
{ |
|
162 |
e = e || window.event; |
ef4f59
|
163 |
return e && e.button !== undefined ? e.button : (e && e.which ? e.which : 0); |
f89f03
|
164 |
}, |
T |
165 |
|
|
166 |
/** |
6b47de
|
167 |
* returns modifier key (constants defined at top of file) |
T |
168 |
*/ |
|
169 |
get_modifier: function(e) |
|
170 |
{ |
|
171 |
var opcode = 0; |
|
172 |
e = e || window.event; |
|
173 |
|
8fa922
|
174 |
if (bw.mac && e) { |
6b47de
|
175 |
opcode += (e.metaKey && CONTROL_KEY) + (e.shiftKey && SHIFT_KEY); |
b231f6
|
176 |
return opcode; |
8fa922
|
177 |
} |
A |
178 |
if (e) { |
6b47de
|
179 |
opcode += (e.ctrlKey && CONTROL_KEY) + (e.shiftKey && SHIFT_KEY); |
T |
180 |
return opcode; |
8fa922
|
181 |
} |
6b47de
|
182 |
}, |
T |
183 |
|
|
184 |
/** |
|
185 |
* Return absolute mouse position of an event |
|
186 |
*/ |
|
187 |
get_mouse_pos: function(e) |
|
188 |
{ |
|
189 |
if (!e) e = window.event; |
b231f6
|
190 |
var mX = (e.pageX) ? e.pageX : e.clientX, |
A |
191 |
mY = (e.pageY) ? e.pageY : e.clientY; |
6b47de
|
192 |
|
8fa922
|
193 |
if (document.body && document.all) { |
6b47de
|
194 |
mX += document.body.scrollLeft; |
T |
195 |
mY += document.body.scrollTop; |
|
196 |
} |
|
197 |
|
cf6bc5
|
198 |
if (e._offset) { |
cc97ea
|
199 |
mX += e._offset.left; |
T |
200 |
mY += e._offset.top; |
cf6bc5
|
201 |
} |
A |
202 |
|
6b47de
|
203 |
return { x:mX, y:mY }; |
T |
204 |
}, |
|
205 |
|
|
206 |
/** |
|
207 |
* Add an object method as event listener to a certain element |
|
208 |
*/ |
|
209 |
add_listener: function(p) |
|
210 |
{ |
|
211 |
if (!p.object || !p.method) // not enough arguments |
|
212 |
return; |
|
213 |
if (!p.element) |
|
214 |
p.element = document; |
|
215 |
|
|
216 |
if (!p.object._rc_events) |
|
217 |
p.object._rc_events = []; |
b231f6
|
218 |
|
6b47de
|
219 |
var key = p.event + '*' + p.method; |
T |
220 |
if (!p.object._rc_events[key]) |
|
221 |
p.object._rc_events[key] = function(e){ return p.object[p.method](e); }; |
|
222 |
|
|
223 |
if (p.element.addEventListener) |
|
224 |
p.element.addEventListener(p.event, p.object._rc_events[key], false); |
8fa922
|
225 |
else if (p.element.attachEvent) { |
a265ab
|
226 |
// IE allows multiple events with the same function to be applied to the same object |
T |
227 |
// forcibly detach the event, then attach |
|
228 |
p.element.detachEvent('on'+p.event, p.object._rc_events[key]); |
6b47de
|
229 |
p.element.attachEvent('on'+p.event, p.object._rc_events[key]); |
8fa922
|
230 |
} |
6b47de
|
231 |
else |
T |
232 |
p.element['on'+p.event] = p.object._rc_events[key]; |
|
233 |
}, |
|
234 |
|
|
235 |
/** |
|
236 |
* Remove event listener |
|
237 |
*/ |
|
238 |
remove_listener: function(p) |
|
239 |
{ |
|
240 |
if (!p.element) |
|
241 |
p.element = document; |
|
242 |
|
|
243 |
var key = p.event + '*' + p.method; |
|
244 |
if (p.object && p.object._rc_events && p.object._rc_events[key]) { |
|
245 |
if (p.element.removeEventListener) |
|
246 |
p.element.removeEventListener(p.event, p.object._rc_events[key], false); |
|
247 |
else if (p.element.detachEvent) |
|
248 |
p.element.detachEvent('on'+p.event, p.object._rc_events[key]); |
|
249 |
else |
|
250 |
p.element['on'+p.event] = null; |
|
251 |
} |
|
252 |
}, |
|
253 |
|
|
254 |
/** |
|
255 |
* Prevent event propagation and bubbeling |
|
256 |
*/ |
|
257 |
cancel: function(evt) |
|
258 |
{ |
|
259 |
var e = evt ? evt : window.event; |
|
260 |
if (e.preventDefault) |
|
261 |
e.preventDefault(); |
|
262 |
if (e.stopPropagation) |
|
263 |
e.stopPropagation(); |
|
264 |
|
|
265 |
e.cancelBubble = true; |
|
266 |
e.returnValue = false; |
|
267 |
return false; |
8ef2f3
|
268 |
}, |
T |
269 |
|
|
270 |
touchevent: function(e) |
|
271 |
{ |
|
272 |
return { pageX:e.pageX, pageY:e.pageY, offsetX:e.pageX - e.target.offsetLeft, offsetY:e.pageY - e.target.offsetTop, target:e.target, istouch:true }; |
6b47de
|
273 |
} |
T |
274 |
|
|
275 |
}; |
4e17e6
|
276 |
|
T |
277 |
|
cc97ea
|
278 |
/** |
T |
279 |
* rcmail objects event interface |
|
280 |
*/ |
|
281 |
function rcube_event_engine() |
|
282 |
{ |
|
283 |
this._events = {}; |
8fa922
|
284 |
}; |
cc97ea
|
285 |
|
T |
286 |
rcube_event_engine.prototype = { |
|
287 |
|
|
288 |
/** |
|
289 |
* Setter for object event handlers |
|
290 |
* |
|
291 |
* @param {String} Event name |
|
292 |
* @param {Function} Handler function |
|
293 |
* @return Listener ID (used to remove this handler later on) |
|
294 |
*/ |
|
295 |
addEventListener: function(evt, func, obj) |
|
296 |
{ |
|
297 |
if (!this._events) |
|
298 |
this._events = {}; |
|
299 |
if (!this._events[evt]) |
|
300 |
this._events[evt] = []; |
b231f6
|
301 |
|
cc97ea
|
302 |
var e = {func:func, obj:obj ? obj : window}; |
T |
303 |
this._events[evt][this._events[evt].length] = e; |
|
304 |
}, |
|
305 |
|
|
306 |
/** |
|
307 |
* Removes a specific event listener |
|
308 |
* |
|
309 |
* @param {String} Event name |
|
310 |
* @param {Int} Listener ID to remove |
|
311 |
*/ |
|
312 |
removeEventListener: function(evt, func, obj) |
|
313 |
{ |
ef4f59
|
314 |
if (obj === undefined) |
cc97ea
|
315 |
obj = window; |
b231f6
|
316 |
|
cc97ea
|
317 |
for (var h,i=0; this._events && this._events[evt] && i < this._events[evt].length; i++) |
T |
318 |
if ((h = this._events[evt][i]) && h.func == func && h.obj == obj) |
|
319 |
this._events[evt][i] = null; |
|
320 |
}, |
|
321 |
|
|
322 |
/** |
|
323 |
* This will execute all registered event handlers |
|
324 |
* |
|
325 |
* @param {String} Event to trigger |
|
326 |
* @param {Object} Event object/arguments |
|
327 |
*/ |
|
328 |
triggerEvent: function(evt, e) |
|
329 |
{ |
|
330 |
var ret, h; |
ef4f59
|
331 |
if (e === undefined) |
0e99d3
|
332 |
e = this; |
ef4f59
|
333 |
else if (typeof e === 'object') |
cc97ea
|
334 |
e.event = evt; |
f52c93
|
335 |
|
cc97ea
|
336 |
if (this._events && this._events[evt] && !this._event_exec) { |
T |
337 |
this._event_exec = true; |
|
338 |
for (var i=0; i < this._events[evt].length; i++) { |
|
339 |
if ((h = this._events[evt][i])) { |
ef4f59
|
340 |
if (typeof h.func === 'function') |
0e99d3
|
341 |
ret = h.func.call ? h.func.call(h.obj, e) : h.func(e); |
ef4f59
|
342 |
else if (typeof h.obj[h.func] === 'function') |
0e99d3
|
343 |
ret = h.obj[h.func](e); |
b231f6
|
344 |
|
cc97ea
|
345 |
// cancel event execution |
ef4f59
|
346 |
if (ret !== undefined && !ret) |
cc97ea
|
347 |
break; |
T |
348 |
} |
|
349 |
} |
|
350 |
} |
|
351 |
|
|
352 |
this._event_exec = false; |
|
353 |
return ret; |
|
354 |
} |
|
355 |
|
8fa922
|
356 |
}; // end rcube_event_engine.prototype |
cc97ea
|
357 |
|
4e17e6
|
358 |
|
6b47de
|
359 |
|
T |
360 |
/** |
e019f2
|
361 |
* Roundcube generic layer (floating box) class |
6b47de
|
362 |
* |
T |
363 |
* @constructor |
|
364 |
*/ |
4e17e6
|
365 |
function rcube_layer(id, attributes) |
cc97ea
|
366 |
{ |
4e17e6
|
367 |
this.name = id; |
b231f6
|
368 |
|
4e17e6
|
369 |
// create a new layer in the current document |
T |
370 |
this.create = function(arg) |
8fa922
|
371 |
{ |
b231f6
|
372 |
var l = (arg.x) ? arg.x : 0, |
A |
373 |
t = (arg.y) ? arg.y : 0, |
|
374 |
w = arg.width, |
|
375 |
h = arg.height, |
|
376 |
z = arg.zindex, |
|
377 |
vis = arg.vis, |
|
378 |
parent = arg.parent, |
|
379 |
obj = document.createElement('DIV'); |
4e17e6
|
380 |
|
b231f6
|
381 |
with (obj) { |
4e17e6
|
382 |
id = this.name; |
b231f6
|
383 |
with (style) { |
8fa922
|
384 |
position = 'absolute'; |
4e17e6
|
385 |
visibility = (vis) ? (vis==2) ? 'inherit' : 'visible' : 'hidden'; |
T |
386 |
left = l+'px'; |
|
387 |
top = t+'px'; |
e5686f
|
388 |
if (w) |
8fa922
|
389 |
width = w.toString().match(/\%$/) ? w : w+'px'; |
e5686f
|
390 |
if (h) |
8fa922
|
391 |
height = h.toString().match(/\%$/) ? h : h+'px'; |
b231f6
|
392 |
if (z) |
A |
393 |
zIndex = z; |
8fa922
|
394 |
} |
A |
395 |
} |
e5686f
|
396 |
|
A |
397 |
if (parent) |
|
398 |
parent.appendChild(obj); |
|
399 |
else |
|
400 |
document.body.appendChild(obj); |
4e17e6
|
401 |
|
T |
402 |
this.elm = obj; |
8fa922
|
403 |
}; |
4e17e6
|
404 |
|
T |
405 |
// create new layer |
b231f6
|
406 |
if (attributes != null) { |
4e17e6
|
407 |
this.create(attributes); |
T |
408 |
this.name = this.elm.id; |
8fa922
|
409 |
} |
4e17e6
|
410 |
else // just refer to the object |
T |
411 |
this.elm = document.getElementById(id); |
|
412 |
|
b231f6
|
413 |
if (!this.elm) |
4e17e6
|
414 |
return false; |
T |
415 |
|
|
416 |
|
|
417 |
// ********* layer object properties ********* |
|
418 |
|
|
419 |
this.css = this.elm.style; |
|
420 |
this.event = this.elm; |
|
421 |
this.width = this.elm.offsetWidth; |
|
422 |
this.height = this.elm.offsetHeight; |
|
423 |
this.x = parseInt(this.elm.offsetLeft); |
|
424 |
this.y = parseInt(this.elm.offsetTop); |
|
425 |
this.visible = (this.css.visibility=='visible' || this.css.visibility=='show' || this.css.visibility=='inherit') ? true : false; |
|
426 |
|
|
427 |
|
|
428 |
// ********* layer object methods ********* |
|
429 |
|
|
430 |
// move the layer to a specific position |
|
431 |
this.move = function(x, y) |
8fa922
|
432 |
{ |
4e17e6
|
433 |
this.x = x; |
T |
434 |
this.y = y; |
|
435 |
this.css.left = Math.round(this.x)+'px'; |
|
436 |
this.css.top = Math.round(this.y)+'px'; |
8fa922
|
437 |
}; |
4e17e6
|
438 |
|
T |
439 |
// change the layers width and height |
|
440 |
this.resize = function(w,h) |
8fa922
|
441 |
{ |
4e17e6
|
442 |
this.css.width = w+'px'; |
T |
443 |
this.css.height = h+'px'; |
|
444 |
this.width = w; |
|
445 |
this.height = h; |
8fa922
|
446 |
}; |
4e17e6
|
447 |
|
T |
448 |
// show or hide the layer |
|
449 |
this.show = function(a) |
8fa922
|
450 |
{ |
A |
451 |
if(a == 1) { |
4e17e6
|
452 |
this.css.visibility = 'visible'; |
T |
453 |
this.visible = true; |
8fa922
|
454 |
} |
A |
455 |
else if(a == 2) { |
4e17e6
|
456 |
this.css.visibility = 'inherit'; |
T |
457 |
this.visible = true; |
8fa922
|
458 |
} |
A |
459 |
else { |
4e17e6
|
460 |
this.css.visibility = 'hidden'; |
T |
461 |
this.visible = false; |
|
462 |
} |
8fa922
|
463 |
}; |
4e17e6
|
464 |
|
T |
465 |
// write new content into a Layer |
|
466 |
this.write = function(cont) |
8fa922
|
467 |
{ |
4e17e6
|
468 |
this.elm.innerHTML = cont; |
8fa922
|
469 |
}; |
4e17e6
|
470 |
|
8fa922
|
471 |
}; |
4e17e6
|
472 |
|
6b47de
|
473 |
|
10a699
|
474 |
// check if input is a valid email address |
2c5762
|
475 |
// By Cal Henderson <cal@iamcal.com> |
S |
476 |
// http://code.iamcal.com/php/rfc822/ |
10a699
|
477 |
function rcube_check_email(input, inline) |
8fa922
|
478 |
{ |
A |
479 |
if (input && window.RegExp) { |
e99991
|
480 |
var qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]', |
A |
481 |
dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]', |
|
482 |
atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+', |
|
483 |
quoted_pair = '\\x5c[\\x00-\\x7f]', |
|
484 |
quoted_string = '\\x22('+qtext+'|'+quoted_pair+')*\\x22', |
|
485 |
// Use simplified domain matching, because we need to allow Unicode characters here |
|
486 |
// So, e-mail address should be validated also on server side after idn_to_ascii() use |
|
487 |
//domain_literal = '\\x5b('+dtext+'|'+quoted_pair+')*\\x5d', |
|
488 |
//sub_domain = '('+atom+'|'+domain_literal+')', |
5c1dfb
|
489 |
// allow punycode/unicode top-level domain |
A |
490 |
domain = '([^@\\x2e]+\\x2e)+([^\\x00-\\x40\\x5b-\\x60\\x7b-\\x7f]{2,}|xn--[a-z0-9]{2,})', |
47f55c
|
491 |
// ICANN e-mail test (http://idn.icann.org/E-mail_test) |
A |
492 |
icann_domains = [ |
|
493 |
'\\u0645\\u062b\\u0627\\u0644\\x2e\\u0625\\u062e\\u062a\\u0628\\u0627\\u0631', |
|
494 |
'\\u4f8b\\u5b50\\x2e\\u6d4b\\u8bd5', |
|
495 |
'\\u4f8b\\u5b50\\x2e\\u6e2c\\u8a66', |
|
496 |
'\\u03c0\\u03b1\\u03c1\\u03ac\\u03b4\\u03b5\\u03b9\\u03b3\\u03bc\\u03b1\\x2e\\u03b4\\u03bf\\u03ba\\u03b9\\u03bc\\u03ae', |
|
497 |
'\\u0909\\u0926\\u093e\\u0939\\u0930\\u0923\\x2e\\u092a\\u0930\\u0940\\u0915\\u094d\\u0937\\u093e', |
|
498 |
'\\u4f8b\\u3048\\x2e\\u30c6\\u30b9\\u30c8', |
|
499 |
'\\uc2e4\\ub840\\x2e\\ud14c\\uc2a4\\ud2b8', |
|
500 |
'\\u0645\\u062b\\u0627\\u0644\\x2e\\u0622\\u0632\\u0645\\u0627\\u06cc\\u0634\u06cc', |
|
501 |
'\\u043f\\u0440\\u0438\\u043c\\u0435\\u0440\\x2e\\u0438\\u0441\\u043f\\u044b\\u0442\\u0430\\u043d\\u0438\\u0435', |
|
502 |
'\\u0b89\\u0ba4\\u0bbe\\u0bb0\\u0ba3\\u0bae\\u0bcd\\x2e\\u0baa\\u0bb0\\u0bbf\\u0b9f\\u0bcd\\u0b9a\\u0bc8', |
|
503 |
'\\u05d1\\u05f2\\u05b7\\u05e9\\u05e4\\u05bc\\u05d9\\u05dc\\x2e\\u05d8\\u05e2\\u05e1\\u05d8' |
|
504 |
], |
|
505 |
icann_addr = 'mailtest\\x40('+icann_domains.join('|')+')', |
e99991
|
506 |
word = '('+atom+'|'+quoted_string+')', |
A |
507 |
delim = '[,;\s\n]', |
|
508 |
local_part = word+'(\\x2e'+word+')*', |
47f55c
|
509 |
addr_spec = '(('+local_part+'\\x40'+domain+')|('+icann_addr+'))', |
e99991
|
510 |
reg1 = inline ? new RegExp('(^|<|'+delim+')'+addr_spec+'($|>|'+delim+')', 'i') : new RegExp('^'+addr_spec+'$', 'i'); |
A |
511 |
|
2c5762
|
512 |
return reg1.test(input) ? true : false; |
10a699
|
513 |
} |
e99991
|
514 |
|
8fa922
|
515 |
return false; |
A |
516 |
}; |
|
517 |
|
4e17e6
|
518 |
|
7910c0
|
519 |
// recursively copy an object |
T |
520 |
function rcube_clone_object(obj) |
|
521 |
{ |
|
522 |
var out = {}; |
b231f6
|
523 |
|
7910c0
|
524 |
for (var key in obj) { |
ef4f59
|
525 |
if (obj[key] && typeof obj[key] === 'object') |
7910c0
|
526 |
out[key] = clone_object(obj[key]); |
T |
527 |
else |
|
528 |
out[key] = obj[key]; |
|
529 |
} |
b231f6
|
530 |
|
7910c0
|
531 |
return out; |
8fa922
|
532 |
}; |
4e17e6
|
533 |
|
4d4264
|
534 |
// make a string URL safe |
T |
535 |
function urlencode(str) |
|
536 |
{ |
6b47de
|
537 |
return window.encodeURIComponent ? encodeURIComponent(str) : escape(str); |
8fa922
|
538 |
}; |
4d4264
|
539 |
|
T |
540 |
|
4e17e6
|
541 |
// get any type of html objects by id/name |
T |
542 |
function rcube_find_object(id, d) |
cc97ea
|
543 |
{ |
4e17e6
|
544 |
var n, f, obj, e; |
T |
545 |
if(!d) d = document; |
|
546 |
|
|
547 |
if(d.getElementsByName && (e = d.getElementsByName(id))) |
|
548 |
obj = e[0]; |
|
549 |
if(!obj && d.getElementById) |
|
550 |
obj = d.getElementById(id); |
|
551 |
if(!obj && d.all) |
|
552 |
obj = d.all[id]; |
|
553 |
|
|
554 |
if(!obj && d.images.length) |
|
555 |
obj = d.images[id]; |
|
556 |
|
cc97ea
|
557 |
if (!obj && d.forms.length) { |
T |
558 |
for (f=0; f<d.forms.length; f++) { |
4e17e6
|
559 |
if(d.forms[f].name == id) |
T |
560 |
obj = d.forms[f]; |
|
561 |
else if(d.forms[f].elements[id]) |
|
562 |
obj = d.forms[f].elements[id]; |
|
563 |
} |
cc97ea
|
564 |
} |
T |
565 |
|
|
566 |
if (!obj && d.layers) { |
|
567 |
if (d.layers[id]) obj = d.layers[id]; |
|
568 |
for (n=0; !obj && n<d.layers.length; n++) |
|
569 |
obj = rcube_find_object(id, d.layers[n].document); |
|
570 |
} |
4e17e6
|
571 |
|
T |
572 |
return obj; |
8fa922
|
573 |
}; |
a7d5c6
|
574 |
|
f89f03
|
575 |
// determine whether the mouse is over the given object or not |
T |
576 |
function rcube_mouse_is_over(ev, obj) |
|
577 |
{ |
129aef
|
578 |
var mouse = rcube_event.get_mouse_pos(ev), |
A |
579 |
pos = $(obj).offset(); |
cc97ea
|
580 |
|
T |
581 |
return ((mouse.x >= pos.left) && (mouse.x < (pos.left + obj.offsetWidth)) && |
|
582 |
(mouse.y >= pos.top) && (mouse.y < (pos.top + obj.offsetHeight))); |
8fa922
|
583 |
}; |
f89f03
|
584 |
|
dd53e2
|
585 |
|
T |
586 |
// cookie functions by GoogieSpell |
|
587 |
function setCookie(name, value, expires, path, domain, secure) |
8fa922
|
588 |
{ |
dd53e2
|
589 |
var curCookie = name + "=" + escape(value) + |
T |
590 |
(expires ? "; expires=" + expires.toGMTString() : "") + |
|
591 |
(path ? "; path=" + path : "") + |
|
592 |
(domain ? "; domain=" + domain : "") + |
|
593 |
(secure ? "; secure" : ""); |
|
594 |
document.cookie = curCookie; |
8fa922
|
595 |
}; |
dd53e2
|
596 |
|
T |
597 |
function getCookie(name) |
8fa922
|
598 |
{ |
129aef
|
599 |
var dc = document.cookie, |
A |
600 |
prefix = name + "=", |
|
601 |
begin = dc.indexOf("; " + prefix); |
|
602 |
|
8fa922
|
603 |
if (begin == -1) { |
dd53e2
|
604 |
begin = dc.indexOf(prefix); |
129aef
|
605 |
if (begin != 0) |
A |
606 |
return null; |
8fa922
|
607 |
} |
129aef
|
608 |
else { |
dd53e2
|
609 |
begin += 2; |
129aef
|
610 |
} |
A |
611 |
|
0e7b66
|
612 |
var end = document.cookie.indexOf(";", begin); |
dd53e2
|
613 |
if (end == -1) |
T |
614 |
end = dc.length; |
129aef
|
615 |
|
dd53e2
|
616 |
return unescape(dc.substring(begin + prefix.length, end)); |
8fa922
|
617 |
}; |
dd53e2
|
618 |
|
8fa922
|
619 |
roundcube_browser.prototype.set_cookie = setCookie; |
a7d5c6
|
620 |
roundcube_browser.prototype.get_cookie = getCookie; |
T |
621 |
|
f11541
|
622 |
// tiny replacement for Firebox functionality |
T |
623 |
function rcube_console() |
|
624 |
{ |
|
625 |
this.log = function(msg) |
|
626 |
{ |
c1e9b0
|
627 |
var box = rcube_find_object('dbgconsole'); |
e5686f
|
628 |
|
a83697
|
629 |
if (box) { |
e5686f
|
630 |
if (msg.charAt(msg.length-1)=='\n') |
cc97ea
|
631 |
msg += '--------------------------------------\n'; |
715553
|
632 |
else |
a83697
|
633 |
msg += '\n--------------------------------------\n'; |
A |
634 |
|
129aef
|
635 |
// Konqueror doesn't allow to just change the value of hidden element |
a83697
|
636 |
if (bw.konq) { |
A |
637 |
box.innerText += msg; |
|
638 |
box.value = box.innerText; |
|
639 |
} else |
|
640 |
box.value += msg; |
|
641 |
} |
f11541
|
642 |
}; |
715553
|
643 |
|
f11541
|
644 |
this.reset = function() |
T |
645 |
{ |
c1e9b0
|
646 |
var box = rcube_find_object('dbgconsole'); |
715553
|
647 |
if (box) |
a83697
|
648 |
box.innerText = box.value = ''; |
f11541
|
649 |
}; |
8fa922
|
650 |
}; |
f11541
|
651 |
|
b4b081
|
652 |
var bw = new roundcube_browser(); |
89e31b
|
653 |
bw.set_html_class(); |
b0dbf3
|
654 |
|
S |
655 |
|
|
656 |
// Add escape() method to RegExp object |
|
657 |
// http://dev.rubyonrails.org/changeset/7271 |
|
658 |
RegExp.escape = function(str) |
8fa922
|
659 |
{ |
b0dbf3
|
660 |
return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1'); |
8fa922
|
661 |
}; |
bafadd
|
662 |
|
A |
663 |
|
|
664 |
// Make getElementById() case-sensitive on IE |
|
665 |
if (bw.ie) |
8fa922
|
666 |
{ |
bafadd
|
667 |
document._getElementById = document.getElementById; |
A |
668 |
document.getElementById = function(id) |
8fa922
|
669 |
{ |
27480b
|
670 |
var i = 0, obj = document._getElementById(id); |
bafadd
|
671 |
|
283a37
|
672 |
if (obj && obj.id != id) |
A |
673 |
while ((obj = document.all[i]) && obj.id != id) |
|
674 |
i++; |
27480b
|
675 |
|
A |
676 |
return obj; |
bafadd
|
677 |
} |
b231f6
|
678 |
} |