0
|
1 /**
|
|
2 * Roundcube functions for default skin interface
|
|
3 *
|
|
4 * @licstart The following is the entire license notice for the
|
|
5 * JavaScript code in this file.
|
|
6 *
|
|
7 * Copyright (c) 2006-2014, The Roundcube Dev Team
|
|
8 *
|
|
9 * The JavaScript code in this page is free software: you can redistribute it
|
|
10 * and/or modify it under the terms of the GNU General Public License
|
|
11 * as published by the Free Software Foundation, either version 3 of
|
|
12 * the License, or (at your option) any later version.
|
|
13 *
|
|
14 * @licend The above is the entire license notice
|
|
15 * for the JavaScript code in this file.
|
|
16 */
|
|
17
|
|
18 /**
|
|
19 * Settings
|
|
20 */
|
|
21
|
|
22 function rcube_init_settings_tabs()
|
|
23 {
|
|
24 var el, cl, container = $('#tabsbar'),
|
|
25 last_tab = $('span:last', container),
|
|
26 tab = '#settingstabpreferences',
|
|
27 action = window.rcmail && rcmail.env.action ? rcmail.env.action : null;
|
|
28
|
|
29 // move About tab to the end
|
|
30 if (last_tab && last_tab.attr('id') != 'settingstababout' && (el = $('#settingstababout'))) {
|
|
31 cl = el.clone(true);
|
|
32 el.remove();
|
|
33 last_tab.after(cl);
|
|
34 }
|
|
35
|
|
36 // get selected tab
|
|
37 if (action)
|
|
38 tab = '#settingstab' + (action.indexOf('identity')>0 ? 'identities' : action.replace(/\./g, ''));
|
|
39
|
|
40 $(tab).addClass('tablink-selected');
|
|
41 $('a', tab).removeAttr('onclick').click(function() { return false; });
|
|
42 }
|
|
43
|
|
44 // Fieldsets-to-tabs converter
|
|
45 // Warning: don't place "caller" <script> inside page element (id)
|
|
46 function rcube_init_tabs(id, current)
|
|
47 {
|
|
48 var content = $('#'+id),
|
|
49 fs = content.children('fieldset');
|
|
50
|
|
51 if (!fs.length)
|
|
52 return;
|
|
53
|
|
54 current = current ? current : 0;
|
|
55
|
|
56 // first hide not selected tabs
|
|
57 fs.each(function(idx) { if (idx != current) $(this).hide(); });
|
|
58
|
|
59 // create tabs container
|
|
60 var tabs = $('<div>').addClass('tabsbar').appendTo(content);
|
|
61
|
|
62 // convert fildsets into tabs
|
|
63 fs.each(function(idx) {
|
|
64 var tab, a, elm = $(this), legend = elm.children('legend');
|
|
65
|
|
66 // create a tab
|
|
67 a = $('<a>').text(legend.text()).attr('href', '#');
|
|
68 tab = $('<span>').attr({'id': 'tab'+idx, 'class': 'tablink'})
|
|
69 .click(function() { rcube_show_tab(id, idx); return false })
|
|
70
|
|
71 // remove legend
|
|
72 legend.remove();
|
|
73 // style fieldset
|
|
74 elm.addClass('tabbed');
|
|
75 // style selected tab
|
|
76 if (idx == current)
|
|
77 tab.addClass('tablink-selected');
|
|
78
|
|
79 // add the tab to container
|
|
80 tab.append(a).appendTo(tabs);
|
|
81 });
|
|
82 }
|
|
83
|
|
84 function rcube_show_tab(id, index)
|
|
85 {
|
|
86 var fs = $('#'+id).children('fieldset');
|
|
87
|
|
88 fs.each(function(idx) {
|
|
89 // Show/hide fieldset (tab content)
|
|
90 $(this)[index==idx ? 'show' : 'hide']();
|
|
91 // Select/unselect tab
|
|
92 $('#tab'+idx).toggleClass('tablink-selected', idx==index);
|
|
93 });
|
|
94 }
|
|
95
|
|
96 /**
|
|
97 * Mail UI
|
|
98 */
|
|
99
|
|
100 function rcube_mail_ui()
|
|
101 {
|
|
102 this.popups = {
|
|
103 markmenu: {id:'markmessagemenu'},
|
|
104 replyallmenu: {id:'replyallmenu'},
|
|
105 forwardmenu: {id:'forwardmenu', editable:1},
|
|
106 searchmenu: {id:'searchmenu', editable:1},
|
|
107 messagemenu: {id:'messagemenu'},
|
|
108 attachmentmenu: {id:'attachmentmenu'},
|
|
109 dragmenu: {id:'dragmenu', sticky:1},
|
|
110 groupmenu: {id:'groupoptionsmenu', above:1},
|
|
111 mailboxmenu: {id:'mailboxoptionsmenu', above:1},
|
|
112 composemenu: {id:'composeoptionsmenu', editable:1, overlap:1},
|
|
113 spellmenu: {id:'spellmenu'},
|
|
114 responsesmenu: {id:'responsesmenu'},
|
|
115 // toggle: #1486823, #1486930
|
|
116 uploadmenu: {id:'attachment-form', editable:1, above:1, toggle:!bw.ie&&!bw.linux },
|
|
117 uploadform: {id:'upload-form', editable:1, toggle:!bw.ie&&!bw.linux }
|
|
118 };
|
|
119
|
|
120 var obj;
|
|
121 for (var k in this.popups) {
|
|
122 obj = $('#'+this.popups[k].id)
|
|
123 if (obj.length)
|
|
124 this.popups[k].obj = obj;
|
|
125 else {
|
|
126 delete this.popups[k];
|
|
127 }
|
|
128 }
|
|
129 }
|
|
130
|
|
131 rcube_mail_ui.prototype = {
|
|
132
|
|
133 show_popup: function(popup, show, config)
|
|
134 {
|
|
135 var obj;
|
|
136 // auto-register menu object
|
|
137 if (!this.popups[popup] && (obj = $('#'+popup)) && obj.length)
|
|
138 this.popups[popup] = $.extend(config, {id: popup, obj: obj});
|
|
139
|
|
140 if (typeof this[popup] == 'function')
|
|
141 return this[popup](show);
|
|
142 else
|
|
143 return this.show_popupmenu(popup, show);
|
|
144 },
|
|
145
|
|
146 show_popupmenu: function(popup, show)
|
|
147 {
|
|
148 var obj = this.popups[popup].obj,
|
|
149 above = this.popups[popup].above,
|
|
150 ref = $(this.popups[popup].link ? this.popups[popup].link : rcube_find_object(popup+'link'));
|
|
151
|
|
152 if (typeof show == 'undefined')
|
|
153 show = obj.is(':visible') ? false : true;
|
|
154 else if (this.popups[popup].toggle && show && this.popups[popup].obj.is(':visible') )
|
|
155 show = false;
|
|
156
|
|
157 if (show && ref.length) {
|
|
158 var parent = ref.parent(),
|
|
159 win = $(window),
|
|
160 pos = parent.hasClass('dropbutton') ? parent.offset() : ref.offset();
|
|
161
|
|
162 if (!above && pos.top + ref.height() + obj.height() > win.height())
|
|
163 above = true;
|
|
164 if (pos.left + obj.width() > win.width())
|
|
165 pos.left = win.width() - obj.width() - 30;
|
|
166
|
|
167 obj.css({ left:pos.left, top:(pos.top + (above ? -obj.height() : ref.height())) });
|
|
168 }
|
|
169
|
|
170 obj[show?'show':'hide']();
|
|
171 },
|
|
172
|
|
173 dragmenu: function(show)
|
|
174 {
|
|
175 this.popups.dragmenu.obj[show?'show':'hide']();
|
|
176 },
|
|
177
|
|
178 forwardmenu: function(show)
|
|
179 {
|
|
180 $("input[name='forwardtype'][value="+(rcmail.env.forward_attachment ? 1 : 0)+"]", this.popups.forwardmenu.obj)
|
|
181 .prop('checked', true);
|
|
182 this.show_popupmenu('forwardmenu', show);
|
|
183 },
|
|
184
|
|
185 uploadmenu: function(show)
|
|
186 {
|
|
187 if (typeof show == 'object') // called as event handler
|
|
188 show = false;
|
|
189
|
|
190 // clear upload form
|
|
191 if (!show) {
|
|
192 try { $('#attachment-form form')[0].reset(); }
|
|
193 catch(e){} // ignore errors
|
|
194 }
|
|
195
|
|
196 this.show_popupmenu('uploadmenu', show);
|
|
197
|
|
198 if (!document.all && this.popups.uploadmenu.obj.is(':visible'))
|
|
199 $('#attachment-form input[type=file]').click();
|
|
200 },
|
|
201
|
|
202 searchmenu: function(show)
|
|
203 {
|
|
204 var obj = this.popups.searchmenu.obj,
|
|
205 ref = rcube_find_object('searchmenulink');
|
|
206
|
|
207 if (typeof show == 'undefined')
|
|
208 show = obj.is(':visible') ? false : true;
|
|
209
|
|
210 if (show && ref) {
|
|
211 var pos = $(ref).offset();
|
|
212 obj.css({left:pos.left, top:(pos.top + ref.offsetHeight + 2)});
|
|
213
|
|
214 if (rcmail.env.search_mods) {
|
|
215 var n, all,
|
|
216 list = $('input:checkbox[name="s_mods[]"]', obj),
|
|
217 mbox = rcmail.env.mailbox,
|
|
218 mods = rcmail.env.search_mods,
|
|
219 scope = rcmail.env.search_scope || 'base';
|
|
220
|
|
221 if (rcmail.env.task == 'mail') {
|
|
222 mods = mods[mbox] ? mods[mbox] : mods['*'];
|
|
223 all = 'text';
|
|
224 $('input:radio[name="s_scope"]').prop('checked', false).filter('#s_scope_'+scope).prop('checked', true);
|
|
225 }
|
|
226 else {
|
|
227 all = '*';
|
|
228 }
|
|
229
|
|
230 if (mods[all])
|
|
231 list.map(function() {
|
|
232 this.checked = true;
|
|
233 this.disabled = this.value != all;
|
|
234 });
|
|
235 else {
|
|
236 list.prop('disabled', false).prop('checked', false);
|
|
237 for (n in mods)
|
|
238 $('#s_mod_' + n).prop('checked', true);
|
|
239 }
|
|
240 }
|
|
241 }
|
|
242 obj[show?'show':'hide']();
|
|
243 },
|
|
244
|
|
245 set_searchmod: function(elem)
|
|
246 {
|
|
247 var all, m, task = rcmail.env.task,
|
|
248 mods = rcmail.env.search_mods,
|
|
249 mbox = rcmail.env.mailbox,
|
|
250 scope = $('input[name="s_scope"]:checked').val();
|
|
251
|
|
252 if (scope == 'all')
|
|
253 mbox = '*';
|
|
254
|
|
255 if (!mods)
|
|
256 mods = {};
|
|
257
|
|
258 if (task == 'mail') {
|
|
259 if (!mods[mbox])
|
|
260 mods[mbox] = rcube_clone_object(mods['*']);
|
|
261 m = mods[mbox];
|
|
262 all = 'text';
|
|
263 }
|
|
264 else { //addressbook
|
|
265 m = mods;
|
|
266 all = '*';
|
|
267 }
|
|
268
|
|
269 if (!elem.checked)
|
|
270 delete(m[elem.value]);
|
|
271 else
|
|
272 m[elem.value] = 1;
|
|
273
|
|
274 // mark all fields
|
|
275 if (elem.value == all) {
|
|
276 $('input:checkbox[name="s_mods[]"]').map(function() {
|
|
277 if (this == elem)
|
|
278 return;
|
|
279
|
|
280 this.checked = true;
|
|
281 if (elem.checked) {
|
|
282 this.disabled = true;
|
|
283 delete m[this.value];
|
|
284 }
|
|
285 else {
|
|
286 this.disabled = false;
|
|
287 m[this.value] = 1;
|
|
288 }
|
|
289 });
|
|
290 }
|
|
291
|
|
292 rcmail.set_searchmods(m);
|
|
293 },
|
|
294
|
|
295 show_listmenu: function(p)
|
|
296 {
|
|
297 var self = this, buttons = {}, $dialog = $('#listmenu');
|
|
298
|
|
299 // close the dialog
|
|
300 if ($dialog.is(':visible')) {
|
|
301 $dialog.dialog('close', p.originalEvent);
|
|
302 return;
|
|
303 }
|
|
304
|
|
305 // set form values
|
|
306 $('input[name="sort_col"][value="'+rcmail.env.sort_col+'"]').prop('checked', true);
|
|
307 $('input[name="sort_ord"][value="DESC"]').prop('checked', rcmail.env.sort_order == 'DESC');
|
|
308 $('input[name="sort_ord"][value="ASC"]').prop('checked', rcmail.env.sort_order != 'DESC');
|
|
309 $('input[name="view"][value="thread"]').prop('checked', rcmail.env.threading ? true : false);
|
|
310 $('input[name="view"][value="list"]').prop('checked', rcmail.env.threading ? false : true);
|
|
311
|
|
312 // set checkboxes
|
|
313 $('input[name="list_col[]"]').each(function() {
|
|
314 $(this).prop('checked', $.inArray(this.value, rcmail.env.listcols) != -1);
|
|
315 });
|
|
316
|
|
317 buttons[rcmail.gettext('save')] = function(e) {
|
|
318 $dialog.dialog('close', e);
|
|
319 self.save_listmenu();
|
|
320 };
|
|
321
|
|
322 $dialog.dialog({
|
|
323 modal: true,
|
|
324 resizable: false,
|
|
325 closeOnEscape: true,
|
|
326 title: null,
|
|
327 open: function(e) {
|
|
328 var maxheight = 0;
|
|
329 $('#listmenu fieldset').each(function() {
|
|
330 var height = $(this).height();
|
|
331 if (height > maxheight) {
|
|
332 maxheight = height;
|
|
333 }
|
|
334 }).css("min-height", maxheight+"px").height(maxheight);
|
|
335
|
|
336 setTimeout(function() { $dialog.find('a, input:not(:disabled)').not('[aria-disabled=true]').first().focus(); }, 100);
|
|
337 },
|
|
338 close: function(e) {
|
|
339 $dialog.dialog('destroy').hide();
|
|
340 if (e.originalEvent && rcube_event.is_keyboard(e.originalEvent))
|
|
341 $('#listmenulink').focus();
|
|
342 },
|
|
343 buttons: buttons,
|
|
344 minWidth: 500,
|
|
345 width: $dialog.width()+20
|
|
346 }).show();
|
|
347 },
|
|
348
|
|
349 save_listmenu: function()
|
|
350 {
|
|
351 var sort = $('input[name="sort_col"]:checked').val(),
|
|
352 ord = $('input[name="sort_ord"]:checked').val(),
|
|
353 thread = $('input[name="view"]:checked').val(),
|
|
354 cols = $('input[name="list_col[]"]:checked')
|
|
355 .map(function(){ return this.value; }).get();
|
|
356
|
|
357 rcmail.set_list_options(cols, sort, ord, thread == 'thread' ? 1 : 0);
|
|
358 },
|
|
359
|
|
360 spellmenu: function(show)
|
|
361 {
|
|
362 var link, li,
|
|
363 lang = rcmail.spellcheck_lang(),
|
|
364 menu = this.popups.spellmenu.obj,
|
|
365 ul = $('ul', menu);
|
|
366
|
|
367 if (!ul.length) {
|
|
368 ul = $('<ul>');
|
|
369
|
|
370 for (i in rcmail.env.spell_langs) {
|
|
371 li = $('<li>');
|
|
372 link = $('<a href="#"></a>').text(rcmail.env.spell_langs[i])
|
|
373 .addClass('active').data('lang', i)
|
|
374 .click(function() {
|
|
375 rcmail.spellcheck_lang_set($(this).data('lang'));
|
|
376 });
|
|
377
|
|
378 link.appendTo(li);
|
|
379 li.appendTo(ul);
|
|
380 }
|
|
381
|
|
382 ul.appendTo(menu);
|
|
383 }
|
|
384
|
|
385 // select current language
|
|
386 $('li', ul).each(function() {
|
|
387 var el = $('a', this);
|
|
388 if (el.data('lang') == lang)
|
|
389 el.addClass('selected');
|
|
390 else if (el.hasClass('selected'))
|
|
391 el.removeClass('selected');
|
|
392 });
|
|
393
|
|
394 this.show_popupmenu('spellmenu', show);
|
|
395 },
|
|
396
|
|
397 show_attachmentmenu: function(elem, event)
|
|
398 {
|
|
399 var id = elem.parentNode.id.replace(/^attach/, '');
|
|
400
|
|
401 $('#attachmenuopen').unbind('click').attr('onclick', '').click(function(e) {
|
|
402 return rcmail.command('open-attachment', id, this);
|
|
403 });
|
|
404
|
|
405 $('#attachmenudownload').unbind('click').attr('onclick', '').click(function() {
|
|
406 rcmail.command('download-attachment', id, this);
|
|
407 });
|
|
408
|
|
409 this.popups.attachmentmenu.link = elem;
|
|
410 rcmail.command('menu-open', {menu: 'attachmentmenu', id: id}, elem, event);
|
|
411 },
|
|
412
|
|
413 menu_open: function(p)
|
|
414 {
|
|
415 if (p && p.name == 'messagelistmenu')
|
|
416 this.show_listmenu();
|
|
417 },
|
|
418
|
|
419 body_mouseup: function(e)
|
|
420 {
|
|
421 var target = e.target; ref = this;
|
|
422
|
|
423 $.each(this.popups, function(i, popup) {
|
|
424 if (popup.obj.is(':visible') && target != rcube_find_object(i + 'link')
|
|
425 && !popup.toggle
|
|
426 && target != popup.obj.get(0) // check if scroll bar was clicked (#1489832)
|
|
427 && (!popup.editable || !ref.target_overlaps(target, popup.id))
|
|
428 && (!popup.sticky || !rcube_mouse_is_over(e, rcube_find_object(popup.id)))
|
|
429 && !$(target).is('.folder-selector-link') && !$(target).children('.folder-selector-link').length
|
|
430 ) {
|
|
431 window.setTimeout('rcmail_ui.show_popup("'+i+'",false);', 50);
|
|
432 }
|
|
433 });
|
|
434 },
|
|
435
|
|
436 target_overlaps: function (target, elementid)
|
|
437 {
|
|
438 var element = rcube_find_object(elementid);
|
|
439 while (target.parentNode) {
|
|
440 if (target.parentNode == element)
|
|
441 return true;
|
|
442 target = target.parentNode;
|
|
443 }
|
|
444 return false;
|
|
445 },
|
|
446
|
|
447 body_keydown: function(e)
|
|
448 {
|
|
449 if (e.keyCode == 27) {
|
|
450 for (var k in this.popups) {
|
|
451 if (this.popups[k].obj.is(':visible'))
|
|
452 this.show_popup(k, false);
|
|
453 }
|
|
454 }
|
|
455 },
|
|
456
|
|
457 switch_preview_pane: function(elem)
|
|
458 {
|
|
459 var uid, prev_frm = $('#mailpreviewframe');
|
|
460
|
|
461 if (elem.checked) {
|
|
462 rcmail.env.contentframe = 'messagecontframe';
|
|
463 if (mailviewsplit.layer) {
|
|
464 mailviewsplit.resize();
|
|
465 mailviewsplit.layer.elm.style.display = '';
|
|
466 }
|
|
467 else
|
|
468 mailviewsplit.init();
|
|
469
|
|
470 if (bw.opera) {
|
|
471 $('#messagelistcontainer').css({height: ''});
|
|
472 }
|
|
473 prev_frm.show();
|
|
474
|
|
475 if (uid = rcmail.message_list.get_single_selection())
|
|
476 rcmail.show_message(uid, false, true);
|
|
477 }
|
|
478 else {
|
|
479 prev_frm.hide();
|
|
480 if (bw.ie7) {
|
|
481 var fr = document.getElementById('mailcontframe');
|
|
482 fr.style.bottom = 0;
|
|
483 fr.style.height = parseInt(fr.parentNode.offsetHeight)+'px';
|
|
484 }
|
|
485 else {
|
|
486 $('#mailcontframe').css({height: 'auto', bottom: 0});
|
|
487 if (bw.opera)
|
|
488 $('#messagelistcontainer').css({height: 'auto'});
|
|
489 }
|
|
490 if (mailviewsplit.layer)
|
|
491 mailviewsplit.layer.elm.style.display = 'none';
|
|
492
|
|
493 rcmail.env.contentframe = null;
|
|
494 rcmail.show_contentframe(false);
|
|
495 }
|
|
496
|
|
497 rcmail.command('save-pref', {name: 'preview_pane', value: (elem.checked?1:0)});
|
|
498 },
|
|
499
|
|
500 /* Message composing */
|
|
501 init_compose_form: function()
|
|
502 {
|
|
503 var f, v, field, fields = ['cc', 'bcc', 'replyto', 'followupto'],
|
|
504 div = document.getElementById('compose-div'),
|
|
505 headers_div = document.getElementById('compose-headers-div');
|
|
506
|
|
507 // Show input elements with non-empty value
|
|
508 for (f=0; f<fields.length; f++) {
|
|
509 v = fields[f]; field = $('#_'+v);
|
|
510 if (field.length) {
|
|
511 field.on('change', {v:v}, function(e) { if (this.value) rcmail_ui.show_header_form(e.data.v); });
|
|
512 if (field.val() != '')
|
|
513 rcmail_ui.show_header_form(v);
|
|
514 }
|
|
515 }
|
|
516
|
|
517 // prevent from form data loss when pressing ESC key in IE
|
|
518 if (bw.ie) {
|
|
519 var form = rcube_find_object('form');
|
|
520 form.onkeydown = function (e) {
|
|
521 if (rcube_event.get_keycode(e) == 27)
|
|
522 rcube_event.cancel(e);
|
|
523 };
|
|
524 }
|
|
525
|
|
526 $(window).resize(function() {
|
|
527 rcmail_ui.resize_compose_body();
|
|
528 });
|
|
529
|
|
530 $('#compose-container').resize(function() {
|
|
531 rcmail_ui.resize_compose_body();
|
|
532 });
|
|
533
|
|
534 div.style.top = (parseInt(headers_div.offsetHeight, 10) + 3) + 'px';
|
|
535 $(window).resize();
|
|
536
|
|
537 // fixes contacts-table position when there's more than one addressbook
|
|
538 $('#contacts-table').css('top', $('#directorylist').height() + 24 + 'px');
|
|
539
|
|
540 // contacts search submit
|
|
541 $('#quicksearchbox').keydown(function(e) {
|
|
542 if (rcube_event.get_keycode(e) == 13)
|
|
543 rcmail.command('search');
|
|
544 });
|
|
545 },
|
|
546
|
|
547 resize_compose_body: function()
|
|
548 {
|
|
549 var div = $('#compose-div .boxlistcontent'),
|
|
550 w = div.width() - 6,
|
|
551 h = div.height() - 2,
|
|
552 x = bw.ie || bw.opera ? 4 : 0;
|
|
553
|
|
554 $('#compose-body_ifr').width(w + 6).height(h - 1 - $('div.mce-toolbar').height());
|
|
555 $('#compose-body').width(w-x).height(h);
|
|
556 $('#googie_edit_layer').width(w).height(h);
|
|
557 },
|
|
558
|
|
559 resize_compose_body_ev: function()
|
|
560 {
|
|
561 window.setTimeout(function(){rcmail_ui.resize_compose_body();}, 100);
|
|
562 },
|
|
563
|
|
564 show_header_form: function(id)
|
|
565 {
|
|
566 var row, s,
|
|
567 link = document.getElementById(id + '-link');
|
|
568
|
|
569 if ((s = this.next_sibling(link)))
|
|
570 s.style.display = 'none';
|
|
571 else if ((s = this.prev_sibling(link)))
|
|
572 s.style.display = 'none';
|
|
573
|
|
574 link.style.display = 'none';
|
|
575
|
|
576 if ((row = document.getElementById('compose-' + id))) {
|
|
577 var div = document.getElementById('compose-div'),
|
|
578 headers_div = document.getElementById('compose-headers-div');
|
|
579 $(row).show();
|
|
580 div.style.top = (parseInt(headers_div.offsetHeight, 10) + 3) + 'px';
|
|
581 this.resize_compose_body();
|
|
582 }
|
|
583
|
|
584 return false;
|
|
585 },
|
|
586
|
|
587 hide_header_form: function(id)
|
|
588 {
|
|
589 var row, ns,
|
|
590 link = document.getElementById(id + '-link'),
|
|
591 parent = link.parentNode,
|
|
592 links = parent.getElementsByTagName('a');
|
|
593
|
|
594 link.style.display = '';
|
|
595
|
|
596 for (var i=0; i<links.length; i++)
|
|
597 if (links[i].style.display != 'none')
|
|
598 for (var j=i+1; j<links.length; j++)
|
|
599 if (links[j].style.display != 'none')
|
|
600 if ((ns = this.next_sibling(links[i]))) {
|
|
601 ns.style.display = '';
|
|
602 break;
|
|
603 }
|
|
604
|
|
605 document.getElementById('_' + id).value = '';
|
|
606
|
|
607 if ((row = document.getElementById('compose-' + id))) {
|
|
608 var div = document.getElementById('compose-div'),
|
|
609 headers_div = document.getElementById('compose-headers-div');
|
|
610 row.style.display = 'none';
|
|
611 div.style.top = (parseInt(headers_div.offsetHeight, 10) + 1) + 'px';
|
|
612 this.resize_compose_body();
|
|
613 }
|
|
614
|
|
615 return false;
|
|
616 },
|
|
617
|
|
618 next_sibling: function(elm)
|
|
619 {
|
|
620 var ns = elm.nextSibling;
|
|
621 while (ns && ns.nodeType == 3)
|
|
622 ns = ns.nextSibling;
|
|
623 return ns;
|
|
624 },
|
|
625
|
|
626 prev_sibling: function(elm)
|
|
627 {
|
|
628 var ps = elm.previousSibling;
|
|
629 while (ps && ps.nodeType == 3)
|
|
630 ps = ps.previousSibling;
|
|
631 return ps;
|
|
632 },
|
|
633
|
|
634 enable_command: function(p)
|
|
635 {
|
|
636 if (p.command == 'reply-list' && rcmail.env.reply_all_mode == 1) {
|
|
637 var label = rcmail.gettext(p.status ? 'replylist' : 'replyall');
|
|
638 $('a.button.replyAll').attr('title', label);
|
|
639 }
|
|
640 },
|
|
641
|
|
642 folder_search_init: function(container)
|
|
643 {
|
|
644 // animation to unfold list search box
|
|
645 $('.boxtitle a.search', container).click(function(e) {
|
|
646 var title = $('.boxtitle', container),
|
|
647 box = $('.listsearchbox', container),
|
|
648 dir = box.is(':visible') ? -1 : 1,
|
|
649 height = 24 + ($('select', box).length ? 24 : 0);
|
|
650
|
|
651 box.slideToggle({
|
|
652 duration: 160,
|
|
653 progress: function(animation, progress) {
|
|
654 if (dir < 0) progress = 1 - progress;
|
|
655 $('.boxlistcontent', container).css('top', (title.outerHeight() + height * progress) + 'px');
|
|
656 },
|
|
657 complete: function() {
|
|
658 box.toggleClass('expanded');
|
|
659 if (box.is(':visible')) {
|
|
660 box.find('input[type=text]').focus();
|
|
661 }
|
|
662 else {
|
|
663 $('a.reset', box).click();
|
|
664 }
|
|
665 // TODO: save state in cookie
|
|
666 }
|
|
667 });
|
|
668
|
|
669 return false;
|
|
670 });
|
|
671 }
|
|
672
|
|
673 };
|
|
674
|
|
675 /**
|
|
676 * Roundcube generic layer (floating box) class
|
|
677 *
|
|
678 * @constructor
|
|
679 */
|
|
680 function rcube_layer(id, attributes)
|
|
681 {
|
|
682 this.name = id;
|
|
683
|
|
684 // create a new layer in the current document
|
|
685 this.create = function(arg)
|
|
686 {
|
|
687 var l = (arg.x) ? arg.x : 0,
|
|
688 t = (arg.y) ? arg.y : 0,
|
|
689 w = arg.width,
|
|
690 h = arg.height,
|
|
691 z = arg.zindex,
|
|
692 vis = arg.vis,
|
|
693 parent = arg.parent,
|
|
694 obj = document.createElement('DIV');
|
|
695
|
|
696 obj.id = this.name;
|
|
697 obj.style.position = 'absolute';
|
|
698 obj.style.visibility = (vis) ? (vis==2) ? 'inherit' : 'visible' : 'hidden';
|
|
699 obj.style.left = l+'px';
|
|
700 obj.style.top = t+'px';
|
|
701 if (w)
|
|
702 obj.style.width = w.toString().match(/\%$/) ? w : w+'px';
|
|
703 if (h)
|
|
704 obj.style.height = h.toString().match(/\%$/) ? h : h+'px';
|
|
705 if (z)
|
|
706 obj.style.zIndex = z;
|
|
707
|
|
708 if (parent)
|
|
709 parent.appendChild(obj);
|
|
710 else
|
|
711 document.body.appendChild(obj);
|
|
712
|
|
713 this.elm = obj;
|
|
714 };
|
|
715
|
|
716 // create new layer
|
|
717 if (attributes != null) {
|
|
718 this.create(attributes);
|
|
719 this.name = this.elm.id;
|
|
720 }
|
|
721 else // just refer to the object
|
|
722 this.elm = document.getElementById(id);
|
|
723
|
|
724 if (!this.elm)
|
|
725 return false;
|
|
726
|
|
727
|
|
728 // ********* layer object properties *********
|
|
729
|
|
730 this.css = this.elm.style;
|
|
731 this.event = this.elm;
|
|
732 this.width = this.elm.offsetWidth;
|
|
733 this.height = this.elm.offsetHeight;
|
|
734 this.x = parseInt(this.elm.offsetLeft);
|
|
735 this.y = parseInt(this.elm.offsetTop);
|
|
736 this.visible = (this.css.visibility=='visible' || this.css.visibility=='show' || this.css.visibility=='inherit') ? true : false;
|
|
737
|
|
738
|
|
739 // ********* layer object methods *********
|
|
740
|
|
741 // move the layer to a specific position
|
|
742 this.move = function(x, y)
|
|
743 {
|
|
744 this.x = x;
|
|
745 this.y = y;
|
|
746 this.css.left = Math.round(this.x)+'px';
|
|
747 this.css.top = Math.round(this.y)+'px';
|
|
748 };
|
|
749
|
|
750 // change the layers width and height
|
|
751 this.resize = function(w,h)
|
|
752 {
|
|
753 this.css.width = w+'px';
|
|
754 this.css.height = h+'px';
|
|
755 this.width = w;
|
|
756 this.height = h;
|
|
757 };
|
|
758
|
|
759 // show or hide the layer
|
|
760 this.show = function(a)
|
|
761 {
|
|
762 if(a == 1) {
|
|
763 this.css.visibility = 'visible';
|
|
764 this.visible = true;
|
|
765 }
|
|
766 else if(a == 2) {
|
|
767 this.css.visibility = 'inherit';
|
|
768 this.visible = true;
|
|
769 }
|
|
770 else {
|
|
771 this.css.visibility = 'hidden';
|
|
772 this.visible = false;
|
|
773 }
|
|
774 };
|
|
775
|
|
776 // write new content into a Layer
|
|
777 this.write = function(cont)
|
|
778 {
|
|
779 this.elm.innerHTML = cont;
|
|
780 };
|
|
781
|
|
782 };
|
|
783
|
|
784 /**
|
|
785 * Scroller
|
|
786 *
|
|
787 * @deprecated Use treelist widget
|
|
788 */
|
|
789 function rcmail_scroller(list, top, bottom)
|
|
790 {
|
|
791 var ref = this;
|
|
792
|
|
793 this.list = $(list);
|
|
794 this.top = $(top);
|
|
795 this.bottom = $(bottom);
|
|
796 this.step_size = 6;
|
|
797 this.step_time = 20;
|
|
798 this.delay = 500;
|
|
799
|
|
800 this.top
|
|
801 .mouseenter(function() { ref.ts = window.setTimeout(function() { ref.scroll('down'); }, ref.delay); })
|
|
802 .mouseout(function() { if (ref.ts) window.clearTimeout(ref.ts); });
|
|
803
|
|
804 this.bottom
|
|
805 .mouseenter(function() { ref.ts = window.setTimeout(function() { ref.scroll('up'); }, ref.delay); })
|
|
806 .mouseout(function() { if (ref.ts) window.clearTimeout(ref.ts); });
|
|
807
|
|
808 this.scroll = function(dir)
|
|
809 {
|
|
810 var ref = this, size = this.step_size;
|
|
811
|
|
812 if (!rcmail.drag_active)
|
|
813 return;
|
|
814
|
|
815 if (dir == 'down')
|
|
816 size *= -1;
|
|
817
|
|
818 this.list.get(0).scrollTop += size;
|
|
819 this.ts = window.setTimeout(function() { ref.scroll(dir); }, this.step_time);
|
|
820 };
|
|
821 };
|
|
822
|
|
823
|
|
824 // Events handling in iframes (eg. preview pane)
|
|
825 function iframe_events()
|
|
826 {
|
|
827 // this==iframe
|
|
828 try {
|
|
829 var doc = this.contentDocument ? this.contentDocument : this.contentWindow ? this.contentWindow.document : null;
|
|
830 $(doc).mouseup(function(e) { rcmail_ui.body_mouseup(e); });
|
|
831 }
|
|
832 catch (e) {
|
|
833 // catch possible "Permission denied" error in IE
|
|
834 };
|
|
835 };
|
|
836
|
|
837 // Abbreviate mailbox names to fit width of the container
|
|
838 function rcube_render_mailboxlist()
|
|
839 {
|
|
840 var list = $('#mailboxlist > li > a, #mailboxlist ul:visible > li > a');
|
|
841
|
|
842 // it's too slow with really big number of folders, especially on IE
|
|
843 if (list.length > (bw.ie && bw.vendver < 9 ? 40 : 100))
|
|
844 return;
|
|
845
|
|
846 list.each(function() {
|
|
847 var elem = $(this),
|
|
848 text = elem.data('text');
|
|
849
|
|
850 if (!text) {
|
|
851 text = elem.text().replace(/\s+\([0-9]+\)$/, '');
|
|
852 elem.data('text', text);
|
|
853 }
|
|
854
|
|
855 if (text.length < 6)
|
|
856 return;
|
|
857
|
|
858 var abbrev = fit_string_to_size(text, elem, elem.width() - elem.children('span.unreadcount').width() - 16);
|
|
859 if (abbrev != text)
|
|
860 elem.attr('title', text);
|
|
861 elem.contents().filter(function(){ return (this.nodeType == 3); }).get(0).data = abbrev;
|
|
862 });
|
|
863 };
|
|
864
|
|
865 // inspired by https://gist.github.com/24261/7fdb113f1e26111bd78c0c6fe515f6c0bf418af5
|
|
866 function fit_string_to_size(str, elem, len)
|
|
867 {
|
|
868 var w, span, $span, result = str, ellip = '...';
|
|
869
|
|
870 if (!rcmail.env.tmp_span) {
|
|
871 // it should be appended to elem to use the same css style
|
|
872 // but for performance reasons we'll append it to body (once)
|
|
873 span = $('<b>').css({visibility: 'hidden', padding: '0px',
|
|
874 'font-family': elem.css('font-family'),
|
|
875 'font-size': elem.css('font-size')})
|
|
876 .appendTo($('body', document)).get(0);
|
|
877 rcmail.env.tmp_span = span;
|
|
878 }
|
|
879 else {
|
|
880 span = rcmail.env.tmp_span;
|
|
881 }
|
|
882
|
|
883 $span = $(span);
|
|
884 $span.text(result);
|
|
885
|
|
886 // on first run, check if string fits into the length already.
|
|
887 w = span.offsetWidth;
|
|
888 if (w > len) {
|
|
889 var cut = Math.max(1, Math.floor(str.length * ((w - len) / w) / 2)),
|
|
890 mid = Math.floor(str.length / 2),
|
|
891 offLeft = mid,
|
|
892 offRight = mid;
|
|
893
|
|
894 while (true) {
|
|
895 offLeft = mid - cut;
|
|
896 offRight = mid + cut;
|
|
897 $span.text(str.substring(0,offLeft) + ellip + str.substring(offRight));
|
|
898
|
|
899 // break loop if string fits size
|
|
900 if (offLeft < 3 || span.offsetWidth)
|
|
901 break;
|
|
902
|
|
903 cut++;
|
|
904 }
|
|
905
|
|
906 // build resulting string
|
|
907 result = str.substring(0,offLeft) + ellip + str.substring(offRight);
|
|
908 }
|
|
909
|
|
910 return result;
|
|
911 };
|
|
912
|
|
913 function update_quota(data)
|
|
914 {
|
|
915 percent_indicator(rcmail.gui_objects.quotadisplay, data);
|
|
916
|
|
917 if (data.table) {
|
|
918 var menu = $('#quotamenu');
|
|
919
|
|
920 if (!menu.length)
|
|
921 menu = $('<div id="quotamenu" class="popupmenu">').appendTo($('body'));
|
|
922
|
|
923 menu.html(data.table);
|
|
924 $('#quotaimg').css('cursor', 'pointer').off('click').on('click', function(e) {
|
|
925 return rcmail.command('menu-open', 'quotamenu', e.target, e);
|
|
926 });
|
|
927 }
|
|
928 };
|
|
929
|
|
930 // percent (quota) indicator
|
|
931 function percent_indicator(obj, data)
|
|
932 {
|
|
933 if (!data || !obj)
|
|
934 return false;
|
|
935
|
|
936 var limit_high = 80,
|
|
937 limit_mid = 55,
|
|
938 width = data.width ? data.width : rcmail.env.indicator_width ? rcmail.env.indicator_width : 100,
|
|
939 height = data.height ? data.height : rcmail.env.indicator_height ? rcmail.env.indicator_height : 14,
|
|
940 quota = data.percent ? Math.abs(parseInt(data.percent)) : 0,
|
|
941 quota_width = parseInt(quota / 100 * width),
|
|
942 pos = $(obj).position();
|
|
943
|
|
944 // workarounds for Opera and Webkit bugs
|
|
945 pos.top = Math.max(0, pos.top);
|
|
946 pos.left = Math.max(0, pos.left);
|
|
947
|
|
948 rcmail.env.indicator_width = width;
|
|
949 rcmail.env.indicator_height = height;
|
|
950
|
|
951 // overlimit
|
|
952 if (quota_width > width) {
|
|
953 quota_width = width;
|
|
954 quota = 100;
|
|
955 }
|
|
956
|
|
957 if (data.title)
|
|
958 data.title = rcmail.get_label('quota') + ': ' + data.title;
|
|
959
|
|
960 // main div
|
|
961 var main = $('<div>');
|
|
962 main.css({position: 'absolute', top: pos.top, left: pos.left,
|
|
963 width: width + 'px', height: height + 'px', zIndex: 100, lineHeight: height + 'px'})
|
|
964 .attr('title', data.title).addClass('quota_text').html(quota + '%');
|
|
965 // used bar
|
|
966 var bar1 = $('<div>');
|
|
967 bar1.css({position: 'absolute', top: pos.top + 1, left: pos.left + 1,
|
|
968 width: quota_width + 'px', height: height + 'px', zIndex: 99});
|
|
969 // background
|
|
970 var bar2 = $('<div>');
|
|
971 bar2.css({position: 'absolute', top: pos.top + 1, left: pos.left + 1,
|
|
972 width: width + 'px', height: height + 'px', zIndex: 98})
|
|
973 .addClass('quota_bg');
|
|
974
|
|
975 if (quota >= limit_high) {
|
|
976 main.addClass(' quota_text_high');
|
|
977 bar1.addClass('quota_high');
|
|
978 }
|
|
979 else if(quota >= limit_mid) {
|
|
980 main.addClass(' quota_text_mid');
|
|
981 bar1.addClass('quota_mid');
|
|
982 }
|
|
983 else {
|
|
984 main.addClass(' quota_text_low');
|
|
985 bar1.addClass('quota_low');
|
|
986 }
|
|
987
|
|
988 // replace quota image
|
|
989 $(obj).html('').append(bar1).append(bar2).append(main);
|
|
990 // update #quotaimg title
|
|
991 $('#quotaimg').attr('title', data.title);
|
|
992 };
|
|
993
|
|
994 // Optional parameters used by TinyMCE
|
|
995 var rcmail_editor_settings = {};
|
|
996
|
|
997 var rcmail_ui;
|
|
998
|
|
999 function rcube_init_mail_ui()
|
|
1000 {
|
|
1001 rcmail_ui = new rcube_mail_ui();
|
|
1002
|
|
1003 $(document.body).mouseup(function(e) { rcmail_ui.body_mouseup(e); })
|
|
1004 .mousedown(function(e) { rcmail_ui.body_keydown(e); });
|
|
1005
|
|
1006 rcmail.addEventListener('init', function() {
|
|
1007 if (rcmail.env.quota_content)
|
|
1008 update_quota(rcmail.env.quota_content);
|
|
1009 rcmail.addEventListener('setquota', update_quota);
|
|
1010
|
|
1011 $('iframe').load(iframe_events)
|
|
1012 .contents().mouseup(function(e) { rcmail_ui.body_mouseup(e); });
|
|
1013
|
|
1014 if (rcmail.env.task == 'mail') {
|
|
1015 rcmail.addEventListener('enable-command', 'enable_command', rcmail_ui)
|
|
1016 .addEventListener('menu-open', 'menu_open', rcmail_ui)
|
|
1017 .addEventListener('aftersend-attachment', 'uploadmenu', rcmail_ui)
|
|
1018 .addEventListener('aftertoggle-editor', 'resize_compose_body_ev', rcmail_ui)
|
|
1019 .gui_object('dragmenu', 'dragmenu');
|
|
1020
|
|
1021 if (rcmail.gui_objects.mailboxlist) {
|
|
1022 rcmail.treelist.addEventListener('expand', rcube_render_mailboxlist);
|
|
1023 rcmail.addEventListener('responseaftermark', rcube_render_mailboxlist)
|
|
1024 .addEventListener('responseaftergetunread', rcube_render_mailboxlist)
|
|
1025 .addEventListener('responseaftercheck-recent', rcube_render_mailboxlist)
|
|
1026 .addEventListener('responseafterrefresh', rcube_render_mailboxlist)
|
|
1027 .addEventListener('afterimport-messages', function(){ rcmail_ui.show_popup('uploadform', false); });
|
|
1028 }
|
|
1029
|
|
1030 // fix message list header on window resize (#1490213)
|
|
1031 if (bw.ie && rcmail.message_list)
|
|
1032 $(window).resize(function() {
|
|
1033 setTimeout(function() { rcmail.message_list.resize(); }, 10);
|
|
1034 });
|
|
1035
|
|
1036 if (rcmail.env.action == 'compose')
|
|
1037 rcmail_ui.init_compose_form();
|
|
1038 else if (rcmail.env.action == 'show' || rcmail.env.action == 'preview')
|
|
1039 // add menu link for each attachment
|
|
1040 $('#attachment-list > li[id^="attach"]').each(function() {
|
|
1041 $(this).append($('<a class="drop"></a>').bind('click keypress', function(e) {
|
|
1042 if (e.type != 'keypress' || e.which == 13) {
|
|
1043 rcmail_ui.show_attachmentmenu(this, e);
|
|
1044 return false;
|
|
1045 }
|
|
1046 }));
|
|
1047 });
|
|
1048 }
|
|
1049 else if (rcmail.env.task == 'addressbook') {
|
|
1050 rcmail.addEventListener('afterupload-photo', function(){ rcmail_ui.show_popup('uploadform', false); })
|
|
1051 .gui_object('dragmenu', 'dragmenu');
|
|
1052 }
|
|
1053 else if (rcmail.env.task == 'settings') {
|
|
1054 if (rcmail.env.action == 'folders') {
|
|
1055 rcmail_ui.folder_search_init($('#folder-manager'));
|
|
1056 }
|
|
1057 }
|
|
1058 });
|
|
1059 }
|