0
|
1 /**
|
|
2 * Roundcube functions for default skin interface
|
|
3 *
|
|
4 * Copyright (c) 2013, The Roundcube Dev Team
|
|
5 *
|
|
6 * The contents are subject to the Creative Commons Attribution-ShareAlike
|
|
7 * License. It is allowed to copy, distribute, transmit and to adapt the work
|
|
8 * by keeping credits to the original autors in the README file.
|
|
9 * See http://creativecommons.org/licenses/by-sa/3.0/ for details.
|
|
10 *
|
|
11 * @license magnet:?xt=urn:btih:90dc5c0be029de84e523b9b3922520e79e0e6f08&dn=cc0.txt CC0-1.0
|
|
12 */
|
|
13
|
|
14 function rcube_mail_ui()
|
|
15 {
|
|
16 var env = {};
|
|
17 var popups = {};
|
|
18 var popupconfig = {
|
|
19 forwardmenu: { editable:1 },
|
|
20 searchmenu: { editable:1, callback:searchmenu },
|
|
21 attachmentmenu: { },
|
|
22 listoptions: { editable:1 },
|
|
23 groupmenu: { above:1 },
|
|
24 mailboxmenu: { above:1 },
|
|
25 spellmenu: { callback: spellmenu },
|
|
26 'folder-selector': { iconized:1 }
|
|
27 };
|
|
28
|
|
29 var me = this;
|
|
30 var mailviewsplit;
|
8
|
31 var mailviewsplit2;
|
0
|
32 var compose_headers = {};
|
|
33 var prefs;
|
|
34
|
|
35 // export public methods
|
|
36 this.set = setenv;
|
|
37 this.init = init;
|
|
38 this.init_tabs = init_tabs;
|
|
39 this.show_about = show_about;
|
|
40 this.show_popup = show_popup;
|
|
41 this.toggle_popup = toggle_popup;
|
|
42 this.add_popup = add_popup;
|
|
43 this.set_searchmod = set_searchmod;
|
|
44 this.set_searchscope = set_searchscope;
|
|
45 this.show_uploadform = show_uploadform;
|
|
46 this.show_header_row = show_header_row;
|
|
47 this.hide_header_row = hide_header_row;
|
|
48 this.update_quota = update_quota;
|
|
49 this.get_pref = get_pref;
|
|
50 this.save_pref = save_pref;
|
|
51 this.folder_search_init = folder_search_init;
|
|
52
|
|
53
|
|
54 // set minimal mode on small screens (don't wait for document.ready)
|
|
55 if (window.$ && document.body) {
|
|
56 var minmode = get_pref('minimalmode');
|
|
57 if (parseInt(minmode) || (minmode === null && $(window).height() < 850)) {
|
|
58 $(document.body).addClass('minimal');
|
|
59 }
|
|
60
|
|
61 if (bw.tablet) {
|
|
62 $('#viewport').attr('content', "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0");
|
|
63 }
|
8
|
64
|
|
65 $(document).ready(function() { me.init(); });
|
0
|
66 }
|
|
67
|
|
68
|
|
69 /**
|
|
70 *
|
|
71 */
|
|
72 function setenv(key, val)
|
|
73 {
|
|
74 env[key] = val;
|
|
75 }
|
|
76
|
|
77 /**
|
|
78 * Get preference stored in browser
|
|
79 */
|
|
80 function get_pref(key)
|
|
81 {
|
|
82 if (!prefs) {
|
|
83 prefs = rcmail.local_storage_get_item('prefs.larry', {});
|
|
84 }
|
|
85
|
|
86 // fall-back to cookies
|
|
87 if (prefs[key] == null) {
|
|
88 var cookie = rcmail.get_cookie(key);
|
|
89 if (cookie != null) {
|
|
90 prefs[key] = cookie;
|
|
91
|
|
92 // copy value to local storage and remove cookie (if localStorage is supported)
|
|
93 if (rcmail.local_storage_set_item('prefs.larry', prefs)) {
|
|
94 rcmail.set_cookie(key, cookie, new Date()); // expire cookie
|
|
95 }
|
|
96 }
|
|
97 }
|
|
98
|
|
99 return prefs[key];
|
|
100 }
|
|
101
|
|
102 /**
|
|
103 * Saves preference value to browser storage
|
|
104 */
|
|
105 function save_pref(key, val)
|
|
106 {
|
|
107 prefs[key] = val;
|
|
108
|
|
109 // write prefs to local storage (if supported)
|
|
110 if (!rcmail.local_storage_set_item('prefs.larry', prefs)) {
|
|
111 // store value in cookie
|
|
112 var exp = new Date();
|
|
113 exp.setYear(exp.getFullYear() + 1);
|
|
114 rcmail.set_cookie(key, val, exp);
|
|
115 }
|
|
116 }
|
|
117
|
|
118 /**
|
|
119 * Initialize UI
|
|
120 * Called on document.ready
|
|
121 */
|
|
122 function init()
|
|
123 {
|
|
124 rcmail.addEventListener('message', message_displayed);
|
|
125
|
|
126 /*** prepare minmode functions ***/
|
|
127 $('#taskbar a').each(function(i,elem){
|
|
128 $(elem).append('<span class="tooltip">' + $('.button-inner', this).html() + '</span>')
|
|
129 });
|
|
130
|
|
131 $('#taskbar .minmodetoggle').click(function(e){
|
|
132 var ismin = $(document.body).toggleClass('minimal').hasClass('minimal');
|
|
133 save_pref('minimalmode', ismin?1:0);
|
|
134 $(window).resize();
|
|
135 });
|
|
136
|
|
137 /*** mail task ***/
|
|
138 if (rcmail.env.task == 'mail') {
|
|
139 rcmail.addEventListener('menu-open', menu_toggle)
|
|
140 .addEventListener('menu-close', menu_toggle)
|
|
141 .addEventListener('menu-save', save_listoptions)
|
8
|
142 .addEventListener('enable-command', enable_command)
|
0
|
143 .addEventListener('responseafterlist', function(e){ switch_view_mode(rcmail.env.threading ? 'thread' : 'list', true) })
|
|
144 .addEventListener('responseaftersearch', function(e){ switch_view_mode(rcmail.env.threading ? 'thread' : 'list', true) });
|
|
145
|
|
146 var dragmenu = $('#dragmessagemenu');
|
|
147 if (dragmenu.length) {
|
|
148 rcmail.gui_object('dragmenu', 'dragmessagemenu');
|
|
149 popups.dragmenu = dragmenu;
|
|
150 }
|
|
151
|
|
152 if (rcmail.env.action == 'show' || rcmail.env.action == 'preview') {
|
8
|
153 rcmail.addEventListener('aftershow-headers', function() { layout_messageview(); })
|
0
|
154 .addEventListener('afterhide-headers', function() { layout_messageview(); });
|
8
|
155
|
0
|
156 $('#previewheaderstoggle').click(function(e) {
|
|
157 toggle_preview_headers();
|
|
158 if (this.blur && !rcube_event.is_keyboard(e))
|
|
159 this.blur();
|
|
160 return false;
|
|
161 });
|
|
162
|
|
163 // add menu link for each attachment
|
|
164 $('#attachment-list > li').each(function() {
|
8
|
165 attachmentmenu_append(this);
|
0
|
166 });
|
|
167
|
|
168 if (get_pref('previewheaders') == '1') {
|
|
169 toggle_preview_headers();
|
|
170 }
|
8
|
171
|
|
172 if (rcmail.env.action == 'show') {
|
|
173 $('#messagecontent').focus();
|
|
174 }
|
0
|
175 }
|
|
176 else if (rcmail.env.action == 'compose') {
|
|
177 rcmail.addEventListener('aftersend-attachment', show_uploadform)
|
8
|
178 .addEventListener('fileappended', function(e) { if (e.attachment.complete) attachmentmenu_append(e.item); })
|
|
179 .addEventListener('aftertoggle-editor', function(e) {
|
|
180 window.setTimeout(function() { layout_composeview() }, 200);
|
0
|
181 if (e && e.mode)
|
|
182 $("select[name='editorSelector']").val(e.mode);
|
8
|
183 })
|
|
184 .addEventListener('compose-encrypted', function(e) {
|
|
185 $("select[name='editorSelector']").prop('disabled', e.active);
|
|
186 $('a.button.attach, a.button.responses')[(e.active?'addClass':'removeClass')]('disabled');
|
|
187 $('#responseslist a.insertresponse')[(e.active?'removeClass':'addClass')]('active');
|
0
|
188 });
|
|
189
|
|
190 // Show input elements with non-empty value
|
|
191 var f, v, field, fields = ['cc', 'bcc', 'replyto', 'followupto'];
|
|
192 for (f=0; f < fields.length; f++) {
|
|
193 v = fields[f]; field = $('#_'+v);
|
|
194 if (field.length) {
|
|
195 field.on('change', {v: v}, function(e) { if (this.value) show_header_row(e.data.v, true); });
|
|
196 if (field.val() != '')
|
|
197 show_header_row(v, true);
|
|
198 }
|
|
199 }
|
|
200
|
|
201 $('#composeoptionstoggle').click(function(e){
|
|
202 var expanded = $('#composeoptions').toggle().is(':visible');
|
|
203 $('#composeoptionstoggle').toggleClass('remove').attr('aria-expanded', expanded ? 'true' : 'false');
|
|
204 layout_composeview();
|
|
205 save_pref('composeoptions', expanded ? '1' : '0');
|
|
206 if (!rcube_event.is_keyboard(e))
|
|
207 this.blur();
|
|
208 return false;
|
|
209 }).css('cursor', 'pointer');
|
|
210
|
|
211 if (get_pref('composeoptions') !== '0') {
|
|
212 $('#composeoptionstoggle').click();
|
|
213 }
|
|
214
|
|
215 // adjust hight when textarea starts to scroll
|
|
216 $("textarea[name='_to'], textarea[name='_cc'], textarea[name='_bcc']").change(function(e){ adjust_compose_editfields(this); }).change();
|
|
217 rcmail.addEventListener('autocomplete_insert', function(p){ adjust_compose_editfields(p.field); });
|
|
218
|
|
219 // toggle compose options if opened in new window and they were visible before
|
|
220 var opener_rc = rcmail.opener();
|
|
221 if (opener_rc && opener_rc.env.action == 'compose' && $('#composeoptionstoggle', opener.document).hasClass('remove'))
|
|
222 $('#composeoptionstoggle').click();
|
|
223
|
|
224 new rcube_splitter({ id:'composesplitterv', p1:'#composeview-left', p2:'#composeview-right',
|
|
225 orientation:'v', relative:true, start:206, min:170, size:12, render:layout_composeview }).init();
|
8
|
226
|
|
227 // add menu link for each attachment
|
|
228 $('#attachment-list > li').each(function() {
|
|
229 attachmentmenu_append(this);
|
|
230 });
|
0
|
231 }
|
|
232 else if (rcmail.env.action == 'list' || !rcmail.env.action) {
|
8
|
233 mail_layout();
|
0
|
234
|
|
235 $('#maillistmode').addClass(rcmail.env.threading ? '' : 'selected').click(function(e) { switch_view_mode('list'); return false; });
|
|
236 $('#mailthreadmode').addClass(rcmail.env.threading ? 'selected' : '').click(function(e) { switch_view_mode('thread'); return false; });
|
|
237
|
8
|
238 rcmail.init_pagejumper('#pagejumper');
|
0
|
239
|
|
240 rcmail.addEventListener('setquota', update_quota)
|
8
|
241 .addEventListener('layout-change', mail_layout)
|
0
|
242 .addEventListener('afterimport-messages', show_uploadform);
|
|
243 }
|
|
244 else if (rcmail.env.action == 'get') {
|
|
245 new rcube_splitter({ id:'mailpartsplitterv', p1:'#messagepartheader', p2:'#messagepartcontainer',
|
|
246 orientation:'v', relative:true, start:226, min:150, size:12}).init();
|
|
247 }
|
|
248
|
|
249 if ($('#mailview-left').length) {
|
|
250 new rcube_splitter({ id:'mailviewsplitterv', p1:'#mailview-left', p2:'#mailview-right',
|
|
251 orientation:'v', relative:true, start:206, min:150, size:12, callback:render_mailboxlist, render:resize_leftcol }).init();
|
|
252 }
|
|
253 }
|
|
254 /*** settings task ***/
|
|
255 else if (rcmail.env.task == 'settings') {
|
|
256 rcmail.addEventListener('init', function(){
|
|
257 var tab = '#settingstabpreferences';
|
|
258 if (rcmail.env.action)
|
|
259 tab = '#settingstab' + (rcmail.env.action.indexOf('identity')>0 ? 'identities' : rcmail.env.action.replace(/\./g, ''));
|
|
260
|
|
261 $(tab).addClass('selected')
|
|
262 .children().first().removeAttr('onclick').click(function() { return false; });
|
|
263 });
|
|
264
|
|
265 if (rcmail.env.action == 'folders') {
|
|
266 new rcube_splitter({ id:'folderviewsplitter', p1:'#folderslist', p2:'#folder-details',
|
|
267 orientation:'v', relative:true, start:266, min:180, size:12 }).init();
|
|
268
|
|
269 rcmail.addEventListener('setquota', update_quota);
|
|
270
|
|
271 folder_search_init($('#folderslist'));
|
|
272 }
|
|
273 else if (rcmail.env.action == 'identities') {
|
|
274 new rcube_splitter({ id:'identviewsplitter', p1:'#identitieslist', p2:'#identity-details',
|
|
275 orientation:'v', relative:true, start:266, min:180, size:12 }).init();
|
|
276 }
|
|
277 else if (rcmail.env.action == 'responses') {
|
|
278 new rcube_splitter({ id:'responseviewsplitter', p1:'#identitieslist', p2:'#identity-details',
|
|
279 orientation:'v', relative:true, start:266, min:180, size:12 }).init();
|
|
280 }
|
|
281 else if (rcmail.env.action == 'preferences' || !rcmail.env.action) {
|
|
282 new rcube_splitter({ id:'prefviewsplitter', p1:'#sectionslist', p2:'#preferences-box',
|
|
283 orientation:'v', relative:true, start:266, min:180, size:12 }).init();
|
|
284 }
|
|
285 else if (rcmail.env.action == 'edit-prefs') {
|
|
286 var legend = $('#preferences-details fieldset.advanced legend'),
|
|
287 toggle = $('<a href="#toggle"></a>')
|
8
|
288 .text(rcmail.gettext('toggleadvancedoptions'))
|
|
289 .attr('title', rcmail.gettext('toggleadvancedoptions'))
|
0
|
290 .addClass('advanced-toggle');
|
|
291
|
|
292 legend.click(function(e) {
|
|
293 toggle.html($(this).hasClass('collapsed') ? '▲' : '▼');
|
|
294
|
|
295 $(this).toggleClass('collapsed')
|
|
296 .closest('fieldset').children('.propform').toggle()
|
|
297 }).append(toggle).addClass('collapsed')
|
|
298
|
|
299 // this magically fixes incorrect position of toggle link created above in Firefox 3.6
|
|
300 if (bw.mz)
|
|
301 legend.parents('form').css('display', 'inline');
|
|
302 }
|
|
303 }
|
|
304 /*** addressbook task ***/
|
|
305 else if (rcmail.env.task == 'addressbook') {
|
|
306 rcmail.addEventListener('afterupload-photo', show_uploadform)
|
|
307 .addEventListener('beforepushgroup', push_contactgroup)
|
8
|
308 .addEventListener('beforepopgroup', pop_contactgroup)
|
|
309 .addEventListener('menu-open', menu_toggle)
|
|
310 .addEventListener('menu-close', menu_toggle);
|
0
|
311
|
|
312 if (rcmail.env.action == '') {
|
|
313 new rcube_splitter({ id:'addressviewsplitterd', p1:'#addressview-left', p2:'#addressview-right',
|
|
314 orientation:'v', relative:true, start:206, min:150, size:12, render:resize_leftcol }).init();
|
|
315 new rcube_splitter({ id:'addressviewsplitter', p1:'#addresslist', p2:'#contacts-box',
|
|
316 orientation:'v', relative:true, start:266, min:260, size:12 }).init();
|
|
317 }
|
|
318
|
|
319 var dragmenu = $('#dragcontactmenu');
|
|
320 if (dragmenu.length) {
|
|
321 rcmail.gui_object('dragmenu', 'dragcontactmenu');
|
|
322 popups.dragmenu = dragmenu;
|
|
323 }
|
|
324 }
|
|
325
|
|
326 // turn a group of fieldsets into tabs
|
|
327 $('.tabbed').each(function(idx, elem){ init_tabs(elem); })
|
|
328
|
|
329 // decorate select elements
|
|
330 $('select.decorated').each(function(){
|
|
331 if (bw.opera) {
|
|
332 $(this).removeClass('decorated');
|
|
333 return;
|
|
334 }
|
|
335
|
|
336 var select = $(this),
|
|
337 parent = select.parent(),
|
|
338 height = Math.max(select.height(), 26) - 2,
|
|
339 width = select.width() - 22,
|
|
340 title = $('option', this).first().text();
|
|
341
|
|
342 if ($('option:selected', this).val() != '')
|
|
343 title = $('option:selected', this).text();
|
|
344
|
|
345 var overlay = $('<a class="menuselector" tabindex="-1"><span class="handle">' + title + '</span></a>')
|
|
346 .css('position', 'absolute')
|
|
347 .offset(select.position())
|
|
348 .insertAfter(select);
|
|
349
|
|
350 overlay.children().width(width).height(height).css('line-height', (height - 1) + 'px');
|
|
351
|
|
352 if (parent.css('position') != 'absolute')
|
|
353 parent.css('position', 'relative');
|
|
354
|
|
355 // re-set original select width to fix click action and options width in some browsers
|
|
356 select.width(overlay.width())
|
|
357 .on(bw.mz ? 'change keyup' : 'change', function() {
|
|
358 var val = $('option:selected', this).text();
|
|
359 $(this).next().children().text(val);
|
|
360 });
|
|
361
|
|
362 select
|
|
363 .on('focus', function(e){ overlay.addClass('focus'); })
|
|
364 .on('blur', function(e){ overlay.removeClass('focus'); });
|
|
365 });
|
|
366
|
|
367 // set min-width to show all toolbar buttons
|
|
368 var screen = $('body.minwidth');
|
|
369 if (screen.length) {
|
|
370 screen.css('min-width', $('.toolbar').width() + $('#quicksearchbar').width() + $('#searchfilter').width() + 30);
|
|
371 }
|
|
372
|
|
373 // don't use $(window).resize() due to some unwanted side-effects
|
|
374 window.onresize = resize;
|
|
375 resize();
|
|
376 }
|
|
377
|
|
378 /**
|
|
379 * Update UI on window resize
|
|
380 */
|
|
381 function resize(e)
|
|
382 {
|
|
383 // resize in intervals to prevent lags and double onresize calls in Chrome (#1489005)
|
|
384 var interval = e ? 10 : 0;
|
|
385
|
|
386 if (rcmail.resize_timeout)
|
|
387 window.clearTimeout(rcmail.resize_timeout);
|
|
388
|
|
389 rcmail.resize_timeout = window.setTimeout(function() {
|
|
390 if (rcmail.env.task == 'mail') {
|
|
391 if (rcmail.env.action == 'show' || rcmail.env.action == 'preview')
|
|
392 layout_messageview();
|
|
393 else if (rcmail.env.action == 'compose')
|
|
394 layout_composeview();
|
|
395 }
|
|
396
|
|
397 // make iframe footer buttons float if scrolling is active
|
|
398 $('body.iframe .footerleft').each(function(){
|
|
399 var footer = $(this),
|
|
400 body = $(document.body),
|
|
401 floating = footer.hasClass('floating'),
|
|
402 overflow = body.outerHeight(true) > $(window).height();
|
|
403
|
|
404 if (overflow != floating) {
|
|
405 var action = overflow ? 'addClass' : 'removeClass';
|
|
406 footer[action]('floating');
|
|
407 body[action]('floatingbuttons');
|
|
408 }
|
|
409 });
|
|
410 }, interval);
|
|
411 }
|
|
412
|
|
413 /**
|
|
414 * Triggered when a new user message is displayed
|
|
415 */
|
|
416 function message_displayed(p)
|
|
417 {
|
|
418 var siblings = $(p.object).siblings('div');
|
|
419 if (siblings.length)
|
|
420 $(p.object).insertBefore(siblings.first());
|
|
421
|
|
422 // show a popup dialog on errors
|
|
423 if (p.type == 'error' && rcmail.env.task != 'login') {
|
|
424 // hide original message object, we don't want both
|
|
425 rcmail.hide_message(p.object);
|
|
426
|
|
427 if (me.message_timer) {
|
|
428 window.clearTimeout(me.message_timer);
|
|
429 }
|
|
430
|
|
431 if (!me.messagedialog) {
|
|
432 me.messagedialog = $('<div>').addClass('popupdialog').hide();
|
|
433 }
|
|
434
|
|
435 var msg = p.message,
|
|
436 dialog_close = function() {
|
|
437 // check if dialog is still displayed, to prevent from js error
|
|
438 me.messagedialog.is(':visible') && me.messagedialog.dialog('destroy').hide();
|
|
439 };
|
|
440
|
|
441 if (me.messagedialog.is(':visible') && me.messagedialog.text() != msg)
|
|
442 msg = me.messagedialog.html() + '<p>' + p.message + '</p>';
|
|
443
|
|
444 me.messagedialog.html(msg)
|
|
445 .dialog({
|
|
446 resizable: false,
|
|
447 closeOnEscape: true,
|
8
|
448 dialogClass: p.type,
|
|
449 title: rcmail.gettext('errortitle'),
|
0
|
450 close: dialog_close,
|
|
451 hide: {effect: 'fadeOut'},
|
|
452 width: 420,
|
|
453 minHeight: 90
|
|
454 }).show();
|
|
455
|
|
456 me.messagedialog.closest('div[role=dialog]').attr('role', 'alertdialog');
|
|
457
|
|
458 if (p.timeout > 0)
|
|
459 me.message_timer = window.setTimeout(dialog_close, p.timeout);
|
|
460 }
|
|
461 }
|
|
462
|
8
|
463 // Mail view layout initialization and change handler
|
|
464 function mail_layout(p)
|
|
465 {
|
|
466 var layout = p ? p.new_layout : rcmail.env.layout,
|
|
467 top = $('#mailview-top'),
|
|
468 bottom = $('#mailview-bottom');
|
|
469
|
|
470 if (p)
|
|
471 $('#mainscreencontent').removeClass().addClass(layout);
|
|
472
|
|
473 $('#mailviewsplitter')[layout == 'desktop' ? 'show' : 'hide']();
|
|
474 $('#mailviewsplitter2')[layout == 'widescreen' ? 'show' : 'hide']();
|
|
475 $('#mailpreviewframe')[layout != 'list' ? 'show' : 'hide']();
|
|
476 rcmail.env.contentframe = layout == 'list' ? null : 'messagecontframe';
|
|
477
|
|
478 if (layout == 'widescreen') {
|
|
479 $('#countcontrols').detach().appendTo($('#messagelistheader'));
|
|
480 top.css({height: 'auto', width: 394});
|
|
481 bottom.css({top: 0, left: 406, height: 'auto'}).show();
|
|
482 if (!mailviewsplit2) {
|
|
483 mailviewsplit2 = new rcube_splitter({ id:'mailviewsplitter2', p1:'#mailview-top', p2:'#mailview-bottom',
|
|
484 orientation:'v', relative:true, start:416, min:400, size:12});
|
|
485 mailviewsplit2.init();
|
|
486 }
|
|
487 else
|
|
488 mailviewsplit2.resize();
|
|
489 }
|
|
490 else if (layout == 'desktop') {
|
|
491 top.css({height: 270, width: 'auto'});
|
|
492 bottom.css({left: 0, top: 284, height: 'auto'}).show();
|
|
493 if (!mailviewsplit) {
|
|
494 mailviewsplit = new rcube_splitter({ id:'mailviewsplitter', p1:'#mailview-top', p2:'#mailview-bottom',
|
|
495 orientation:'h', relative:true, start:276, min:150, size:12, offset:4 });
|
|
496 mailviewsplit.init();
|
|
497 }
|
|
498 else
|
|
499 mailviewsplit.resize();
|
|
500 }
|
|
501 else { // layout == 'list'
|
|
502 top.css({height: 'auto', width: 'auto'});
|
|
503 bottom.hide();
|
|
504 }
|
|
505
|
|
506 if (p && p.old_layout == 'widescreen') {
|
|
507 $('#countcontrols').detach().appendTo($('#messagelistfooter'));
|
|
508 }
|
|
509 }
|
0
|
510
|
|
511 /**
|
|
512 * Adjust UI objects of the mail view screen
|
|
513 */
|
|
514 function layout_messageview()
|
|
515 {
|
|
516 $('#messagecontent').css('top', ($('#messageheader').outerHeight() + 1) + 'px');
|
|
517 $('#message-objects div a').addClass('button');
|
|
518
|
|
519 if (!$('#attachment-list li').length) {
|
|
520 $('div.rightcol').hide().attr('aria-hidden', 'true');
|
|
521 $('div.leftcol').css('margin-right', '0');
|
|
522 }
|
8
|
523
|
|
524 var mvlpe = $('#messagebody.mailvelope, #messagebody > .mailvelope');
|
|
525 if (mvlpe.length) {
|
|
526 var h = $('#messagecontent').length ?
|
|
527 $('#messagecontent').height() - 16 :
|
|
528 $(window).height() - mvlpe.offset().top - 2;
|
|
529 mvlpe.height(h);
|
|
530 }
|
0
|
531 }
|
|
532
|
|
533
|
|
534 function render_mailboxlist(splitter)
|
|
535 {
|
|
536 // TODO: implement smart shortening of long folder names
|
|
537 }
|
|
538
|
|
539
|
|
540 function resize_leftcol(splitter)
|
|
541 {
|
|
542 // STUB
|
|
543 }
|
|
544
|
|
545 function adjust_compose_editfields(elem)
|
|
546 {
|
|
547 if (elem.nodeName == 'TEXTAREA') {
|
|
548 var $elem = $(elem), line_height = 14, // hard-coded because some browsers only provide the outer height in elem.clientHeight
|
|
549 content_height = elem.scrollHeight,
|
|
550 rows = elem.value.length > 80 && content_height > line_height*1.5 ? 2 : 1;
|
|
551 $elem.css('height', (line_height*rows) + 'px');
|
|
552 layout_composeview();
|
|
553 }
|
|
554 }
|
|
555
|
|
556 function layout_composeview()
|
|
557 {
|
|
558 var body = $('#composebody'),
|
|
559 form = $('#compose-content'),
|
|
560 bottom = $('#composeview-bottom'),
|
|
561 w, h, bh, ovflw, btns = 0,
|
|
562 minheight = 300,
|
|
563
|
|
564 bh = form.height() - bottom.position().top;
|
|
565 ovflw = minheight - bh;
|
|
566 btns = ovflw > -100 ? 0 : 40;
|
|
567 bottom.height(Math.max(minheight, bh));
|
|
568 form.css('overflow', ovflw > 0 ? 'auto' : 'hidden');
|
|
569
|
|
570 w = body.parent().width() - 5;
|
|
571 h = body.parent().height() - 8;
|
|
572 body.width(w).height(h);
|
|
573
|
|
574 $('#composebodycontainer > div').width(w+8);
|
|
575 $('#composebody_ifr').height(h + 4 - $('div.mce-toolbar').height());
|
|
576 $('#googie_edit_layer').width(w).height(h);
|
|
577 // $('#composebodycontainer')[(btns ? 'addClass' : 'removeClass')]('buttons');
|
|
578 // $('#composeformbuttons')[(btns ? 'show' : 'hide')]();
|
|
579
|
|
580 var abooks = $('#directorylist');
|
|
581 if (abooks.length)
|
|
582 $('#compose-contacts .scroller').css('top', abooks.position().top + abooks.outerHeight());
|
|
583 }
|
|
584
|
|
585
|
|
586 function update_quota(p)
|
|
587 {
|
|
588 var element = $('#quotadisplay'), menu = $('#quotamenu'),
|
|
589 step = 24, step_count = 20,
|
|
590 y = p.total ? Math.ceil(p.percent / 100 * step_count) * step : 0;
|
|
591
|
|
592 // never show full-circle if quota is close to 100% but below.
|
|
593 if (p.total && y == step * step_count && p.percent < 100)
|
|
594 y -= step;
|
|
595
|
|
596 element.css('background-position', '0 -' + y + 'px');
|
8
|
597 element.attr('class', 'countdisplay p' + (Math.round(p.percent / 10) * 10));
|
0
|
598
|
|
599 if (p.table) {
|
|
600 if (!menu.length)
|
|
601 menu = $('<div id="quotamenu" class="popupmenu">').appendTo($('body'));
|
|
602
|
|
603 menu.html(p.table);
|
|
604 element.css('cursor', 'pointer').off('click').on('click', function(e) {
|
|
605 return rcmail.command('menu-open', 'quotamenu', e.target, e);
|
|
606 });
|
|
607 }
|
|
608 }
|
|
609
|
|
610 function folder_search_init(container)
|
|
611 {
|
|
612 // animation to unfold list search box
|
|
613 $('.boxtitle a.search', container).click(function(e) {
|
|
614 var title = $('.boxtitle', container),
|
|
615 box = $('.listsearchbox', container),
|
|
616 dir = box.is(':visible') ? -1 : 1,
|
|
617 height = 34 + ($('select', box).length ? 22 : 0);
|
|
618
|
|
619 box.slideToggle({
|
|
620 duration: 160,
|
|
621 progress: function(animation, progress) {
|
|
622 if (dir < 0) progress = 1 - progress;
|
|
623 $('.scroller', container).css('top', (title.outerHeight() + height * progress) + 'px');
|
|
624 },
|
|
625 complete: function() {
|
|
626 box.toggleClass('expanded');
|
|
627 if (box.is(':visible')) {
|
|
628 box.find('input[type=text]').focus();
|
|
629 height = 34 + ($('select', box).length ? $('select', box).outerHeight() + 4 : 0);
|
|
630 $('.scroller', container).css('top', (title.outerHeight() + height) + 'px');
|
|
631 }
|
|
632 else {
|
|
633 $('a.reset', box).click();
|
|
634 }
|
|
635 // TODO: save state in localStorage
|
|
636 }
|
|
637 });
|
|
638
|
|
639 return false;
|
|
640 });
|
|
641 }
|
|
642
|
|
643 function enable_command(p)
|
|
644 {
|
|
645 if (p.command == 'reply-list' && rcmail.env.reply_all_mode == 1) {
|
|
646 var label = rcmail.gettext(p.status ? 'replylist' : 'replyall');
|
|
647 if (rcmail.env.action == 'preview')
|
|
648 $('a.button.replyall').attr('title', label);
|
|
649 else
|
|
650 $('a.button.reply-all').text(label).attr('title', label);
|
|
651 }
|
8
|
652 else if (p.command == 'compose-encrypted') {
|
|
653 // show the toolbar button for Mailvelope
|
|
654 $('a.button.encrypt').show();
|
|
655 }
|
0
|
656 }
|
|
657
|
|
658
|
|
659 /**
|
|
660 * Register a popup menu
|
|
661 */
|
|
662 function add_popup(popup, config)
|
|
663 {
|
|
664 var obj = popups[popup] = $('#'+popup);
|
|
665 obj.appendTo(document.body); // move it to top for proper absolute positioning
|
|
666
|
|
667 if (obj.length)
|
|
668 popupconfig[popup] = $.extend(popupconfig[popup] || {}, config || {});
|
|
669 }
|
|
670
|
|
671 /**
|
|
672 * Trigger for popup menus
|
|
673 */
|
|
674 function toggle_popup(popup, e, config)
|
|
675 {
|
|
676 // auto-register menu object
|
|
677 if (config || !popupconfig[popup])
|
|
678 add_popup(popup, config);
|
|
679
|
|
680 return rcmail.command('menu-open', popup, e.target, e);
|
|
681 }
|
|
682
|
|
683 /**
|
|
684 * (Deprecated) trigger for popup menus
|
|
685 */
|
|
686 function show_popup(popup, show, config)
|
|
687 {
|
|
688 // auto-register menu object
|
|
689 if (config || !popupconfig[popup])
|
|
690 add_popup(popup, config);
|
|
691
|
|
692 config = popupconfig[popup] || {};
|
|
693 var ref = $(config.link ? config.link : '#'+popup+'link'),
|
|
694 pos = ref.offset();
|
|
695 if (ref.has('.inner'))
|
|
696 ref = ref.children('.inner');
|
|
697
|
|
698 // fire command with simulated mouse click event
|
|
699 return rcmail.command('menu-open',
|
|
700 { menu:popup, show:show },
|
|
701 ref.get(0),
|
|
702 $.Event('click', { target:ref.get(0), pageX:pos.left, pageY:pos.top, clientX:pos.left, clientY:pos.top }));
|
|
703 }
|
|
704
|
|
705 /**
|
|
706 * Switch between short and full headers display in message preview
|
|
707 */
|
|
708 function toggle_preview_headers()
|
|
709 {
|
|
710 $('#preview-shortheaders').toggle();
|
|
711 var full = $('#preview-allheaders').toggle(),
|
|
712 button = $('a#previewheaderstoggle');
|
|
713
|
|
714 // add toggle button to full headers table
|
|
715 if (full.is(':visible'))
|
|
716 button.attr('href', '#hide').removeClass('add').addClass('remove').attr('aria-expanded', 'true');
|
|
717 else
|
|
718 button.attr('href', '#details').removeClass('remove').addClass('add').attr('aria-expanded', 'false');
|
|
719
|
|
720 save_pref('previewheaders', full.is(':visible') ? '1' : '0');
|
|
721 }
|
|
722
|
|
723
|
|
724 /**
|
|
725 *
|
|
726 */
|
|
727 function switch_view_mode(mode, force)
|
|
728 {
|
|
729 if (force || !$('#mail'+mode+'mode').hasClass('disabled')) {
|
|
730 $('#maillistmode, #mailthreadmode').removeClass('selected').attr('tabindex', '0').attr('aria-disabled', 'false');
|
|
731 $('#mail'+mode+'mode').addClass('selected').attr('tabindex', '-1').attr('aria-disabled', 'true');
|
|
732 }
|
|
733 }
|
|
734
|
|
735
|
|
736 /**** popup menu callbacks ****/
|
|
737
|
|
738 /**
|
|
739 * Handler for menu-open and menu-close events
|
|
740 */
|
|
741 function menu_toggle(p)
|
|
742 {
|
|
743 if (p && p.name == 'messagelistmenu') {
|
|
744 show_listoptions(p);
|
|
745 }
|
|
746 else if (p) {
|
|
747 // adjust menu position according to config
|
|
748 var config = popupconfig[p.name] || {},
|
|
749 ref = $(config.link || '#'+p.name+'link'),
|
|
750 visible = p.obj && p.obj.is(':visible'),
|
|
751 above = config.above;
|
|
752
|
|
753 // fix position according to config
|
|
754 if (p.obj && visible && ref.length) {
|
|
755 var parent = ref.parent(),
|
|
756 win = $(window), pos;
|
|
757
|
|
758 if (parent.hasClass('dropbutton'))
|
|
759 ref = parent;
|
|
760
|
|
761 if (config.above || ref.hasClass('dropbutton')) {
|
|
762 pos = ref.offset();
|
|
763 p.obj.css({ left:pos.left+'px', top:(pos.top + (config.above ? -p.obj.height() : ref.outerHeight()))+'px' });
|
|
764 }
|
|
765 }
|
|
766
|
|
767 // add the right classes
|
|
768 if (p.obj && config.iconized) {
|
|
769 p.obj.children('ul').addClass('iconized');
|
|
770 }
|
|
771
|
|
772 // apply some data-attributes from menu config
|
|
773 if (p.obj && config.editable)
|
|
774 p.obj.attr('data-editable', 'true');
|
|
775
|
|
776 // trigger callback function
|
|
777 if (typeof config.callback == 'function') {
|
|
778 config.callback(visible, p);
|
|
779 }
|
|
780 }
|
|
781 }
|
|
782
|
|
783 function searchmenu(show)
|
|
784 {
|
|
785 if (show && rcmail.env.search_mods) {
|
|
786 var n, all,
|
|
787 obj = popups['searchmenu'],
|
|
788 list = $('input:checkbox[name="s_mods[]"]', obj),
|
|
789 mbox = rcmail.env.mailbox,
|
|
790 mods = rcmail.env.search_mods,
|
|
791 scope = rcmail.env.search_scope || 'base';
|
|
792
|
|
793 if (rcmail.env.task == 'mail') {
|
|
794 if (scope == 'all')
|
|
795 mbox = '*';
|
|
796 mods = mods[mbox] ? mods[mbox] : mods['*'];
|
|
797 all = 'text';
|
|
798 $('input:radio[name="s_scope"]').prop('checked', false).filter('#s_scope_'+scope).prop('checked', true);
|
|
799 }
|
|
800 else {
|
|
801 all = '*';
|
|
802 }
|
|
803
|
|
804 if (mods[all])
|
|
805 list.map(function() {
|
|
806 this.checked = true;
|
|
807 this.disabled = this.value != all;
|
|
808 });
|
|
809 else {
|
|
810 list.prop('disabled', false).prop('checked', false);
|
|
811 for (n in mods)
|
|
812 $('#s_mod_' + n).prop('checked', true);
|
|
813 }
|
|
814 }
|
|
815 }
|
|
816
|
|
817 function attachmentmenu(elem, event)
|
|
818 {
|
|
819 var id = elem.parentNode.id.replace(/^attach/, '');
|
|
820
|
8
|
821 $.each(['open', 'download', 'rename'], function() {
|
|
822 var action = this;
|
|
823 $('#attachmenu' + action).off('click').attr('onclick', '').click(function(e) {
|
|
824 return rcmail.command(action + '-attachment', id, this);
|
|
825 });
|
0
|
826 });
|
|
827
|
|
828 popupconfig.attachmentmenu.link = elem;
|
|
829 rcmail.command('menu-open', {menu: 'attachmentmenu', id: id}, elem, event);
|
|
830 }
|
|
831
|
|
832 function spellmenu(show, p)
|
|
833 {
|
|
834 var k, link, li,
|
|
835 lang = rcmail.spellcheck_lang(),
|
|
836 ul = $('ul', p.obj);
|
|
837
|
|
838 if (!ul.length) {
|
|
839 ul = $('<ul class="toolbarmenu selectable" role="menu">');
|
|
840
|
|
841 for (k in rcmail.env.spell_langs) {
|
|
842 li = $('<li role="menuitem">');
|
|
843 link = $('<a href="#'+k+'" tabindex="0"></a>').text(rcmail.env.spell_langs[k])
|
|
844 .addClass('active').data('lang', k)
|
8
|
845 .on('click keypress', function(e) {
|
0
|
846 if (e.type != 'keypress' || rcube_event.get_keycode(e) == 13) {
|
|
847 rcmail.spellcheck_lang_set($(this).data('lang'));
|
|
848 rcmail.hide_menu('spellmenu', e);
|
|
849 return false;
|
|
850 }
|
|
851 });
|
|
852
|
|
853 link.appendTo(li);
|
|
854 li.appendTo(ul);
|
|
855 }
|
|
856
|
|
857 ul.appendTo(p.obj);
|
|
858 }
|
|
859
|
|
860 // select current language
|
|
861 $('li', ul).each(function() {
|
|
862 var el = $('a', this);
|
|
863 if (el.data('lang') == lang)
|
|
864 el.addClass('selected').attr('aria-selected', 'true');
|
|
865 else if (el.hasClass('selected'))
|
|
866 el.removeClass('selected').removeAttr('aria-selected');
|
|
867 });
|
|
868 }
|
|
869
|
8
|
870 // append drop-icon to attachments list item (to invoke attachment menu)
|
|
871 function attachmentmenu_append(item)
|
|
872 {
|
|
873 item = $(item);
|
|
874
|
|
875 if (!item.children('.drop').length)
|
|
876 item.append($('<a class="drop skip-content" tabindex="0" aria-haspopup="true">Show options</a>')
|
|
877 .on('click keypress', function(e) {
|
|
878 if (e.type != 'keypress' || rcube_event.get_keycode(e) == 13) {
|
|
879 attachmentmenu(this, e);
|
|
880 return false;
|
|
881 }
|
|
882 }));
|
|
883 }
|
0
|
884
|
|
885 /**
|
|
886 *
|
|
887 */
|
|
888 function show_listoptions(p)
|
|
889 {
|
|
890 var $dialog = $('#listoptions');
|
|
891
|
|
892 // close the dialog
|
|
893 if ($dialog.is(':visible')) {
|
|
894 $dialog.dialog('close', p.originalEvent);
|
|
895 return;
|
|
896 }
|
|
897
|
|
898 // set form values
|
|
899 $('input[name="sort_col"][value="'+rcmail.env.sort_col+'"]').prop('checked', true);
|
|
900 $('input[name="sort_ord"][value="DESC"]').prop('checked', rcmail.env.sort_order == 'DESC');
|
|
901 $('input[name="sort_ord"][value="ASC"]').prop('checked', rcmail.env.sort_order != 'DESC');
|
|
902
|
8
|
903 $.each(['widescreen', 'desktop', 'list'], function() {
|
|
904 $('input[name="layout"][value="' + this + '"]').prop('checked', rcmail.env.layout == this);
|
|
905 });
|
|
906 $('#listoptions-columns', $dialog)[rcmail.env.layout == 'widescreen' ? 'hide' : 'show']();
|
|
907
|
0
|
908 // set checkboxes
|
|
909 $('input[name="list_col[]"]').each(function() {
|
|
910 $(this).prop('checked', $.inArray(this.value, rcmail.env.listcols) != -1);
|
|
911 });
|
|
912
|
|
913 $dialog.dialog({
|
|
914 modal: true,
|
|
915 resizable: false,
|
|
916 closeOnEscape: true,
|
|
917 title: null,
|
|
918 open: function(e) {
|
|
919 setTimeout(function(){ $dialog.find('a, input:not(:disabled)').not('[aria-disabled=true]').first().focus(); }, 100);
|
|
920 },
|
|
921 close: function(e) {
|
|
922 $dialog.dialog('destroy').hide();
|
|
923 if (e.originalEvent && rcube_event.is_keyboard(e.originalEvent))
|
|
924 $('#listmenulink').focus();
|
|
925 },
|
|
926 minWidth: 500,
|
|
927 width: $dialog.width()+25
|
|
928 }).show();
|
|
929 }
|
|
930
|
|
931
|
|
932 /**
|
|
933 *
|
|
934 */
|
|
935 function save_listoptions(p)
|
|
936 {
|
|
937 $('#listoptions').dialog('close');
|
|
938
|
|
939 if (rcube_event.is_keyboard(p.originalEvent))
|
|
940 $('#listmenulink').focus();
|
|
941
|
|
942 var sort = $('input[name="sort_col"]:checked').val(),
|
|
943 ord = $('input[name="sort_ord"]:checked').val(),
|
8
|
944 layout = $('input[name="layout"]:checked').val(),
|
0
|
945 cols = $('input[name="list_col[]"]:checked')
|
|
946 .map(function(){ return this.value; }).get();
|
|
947
|
8
|
948 rcmail.set_list_options(cols, sort, ord, rcmail.env.threading, layout);
|
0
|
949 }
|
|
950
|
|
951
|
|
952 /**
|
|
953 *
|
|
954 */
|
|
955 function set_searchmod(elem)
|
|
956 {
|
|
957 var all, m, task = rcmail.env.task,
|
|
958 mods = rcmail.env.search_mods,
|
|
959 mbox = rcmail.env.mailbox,
|
|
960 scope = $('input[name="s_scope"]:checked').val();
|
|
961
|
|
962 if (scope == 'all')
|
|
963 mbox = '*';
|
|
964
|
|
965 if (!mods)
|
|
966 mods = {};
|
|
967
|
|
968 if (task == 'mail') {
|
|
969 if (!mods[mbox])
|
|
970 mods[mbox] = rcube_clone_object(mods['*']);
|
|
971 m = mods[mbox];
|
|
972 all = 'text';
|
|
973 }
|
|
974 else { //addressbook
|
|
975 m = mods;
|
|
976 all = '*';
|
|
977 }
|
|
978
|
|
979 if (!elem.checked)
|
|
980 delete(m[elem.value]);
|
|
981 else
|
|
982 m[elem.value] = 1;
|
|
983
|
|
984 // mark all fields
|
|
985 if (elem.value == all) {
|
|
986 $('input:checkbox[name="s_mods[]"]').map(function() {
|
|
987 if (this == elem)
|
|
988 return;
|
|
989
|
|
990 this.checked = true;
|
|
991 if (elem.checked) {
|
|
992 this.disabled = true;
|
|
993 delete m[this.value];
|
|
994 }
|
|
995 else {
|
|
996 this.disabled = false;
|
|
997 m[this.value] = 1;
|
|
998 }
|
|
999 });
|
|
1000 }
|
|
1001
|
|
1002 rcmail.set_searchmods(m);
|
|
1003 }
|
|
1004
|
|
1005 function set_searchscope(elem)
|
|
1006 {
|
|
1007 rcmail.set_searchscope(elem.value);
|
|
1008 }
|
|
1009
|
|
1010 function push_contactgroup(p)
|
|
1011 {
|
|
1012 // lets the contacts list swipe to the left, nice!
|
|
1013 var table = $('#contacts-table'),
|
|
1014 scroller = table.parent().css('overflow', 'hidden');
|
|
1015
|
|
1016 table.clone()
|
|
1017 .css({ position:'absolute', top:'0', left:'0', width:table.width()+'px', 'z-index':10 })
|
|
1018 .appendTo(scroller)
|
|
1019 .animate({ left: -(table.width()+5) + 'px' }, 300, 'swing', function(){
|
|
1020 $(this).remove();
|
|
1021 scroller.css('overflow', 'auto')
|
|
1022 });
|
|
1023 }
|
|
1024
|
|
1025 function pop_contactgroup(p)
|
|
1026 {
|
|
1027 // lets the contacts list swipe to the left, nice!
|
|
1028 var table = $('#contacts-table'),
|
|
1029 scroller = table.parent().css('overflow', 'hidden'),
|
|
1030 clone = table.clone().appendTo(scroller);
|
|
1031
|
|
1032 table.css({ position:'absolute', top:'0', left:-(table.width()+5) + 'px', width:table.width()+'px', height:table.height()+'px', 'z-index':10 })
|
|
1033 .animate({ left:'0' }, 300, 'linear', function(){
|
|
1034 clone.remove();
|
|
1035 $(this).css({ position:'relative', left:'0', width:'100%', height:'auto', 'z-index':1 });
|
|
1036 scroller.css('overflow', 'auto')
|
|
1037 });
|
|
1038 }
|
|
1039
|
|
1040 function show_uploadform(e)
|
|
1041 {
|
|
1042 var $dialog = $('#upload-dialog');
|
|
1043
|
|
1044 // close the dialog
|
|
1045 if ($dialog.is(':visible')) {
|
|
1046 $dialog.dialog('close');
|
|
1047 return;
|
|
1048 }
|
|
1049
|
8
|
1050 // do nothing if mailvelope editor is active
|
|
1051 if (rcmail.mailvelope_editor)
|
|
1052 return;
|
|
1053
|
0
|
1054 // add icons to clone file input field
|
|
1055 if (rcmail.env.action == 'compose' && !$dialog.data('extended')) {
|
|
1056 $('<a>')
|
|
1057 .addClass('iconlink add')
|
|
1058 .attr('href', '#add')
|
|
1059 .html('Add')
|
|
1060 .appendTo($('input[type="file"]', $dialog).parent())
|
|
1061 .click(add_uploadfile);
|
|
1062 $dialog.data('extended', true);
|
|
1063 }
|
|
1064
|
|
1065 $dialog.dialog({
|
|
1066 modal: true,
|
|
1067 resizable: false,
|
|
1068 closeOnEscape: true,
|
|
1069 title: $dialog.attr('title'),
|
|
1070 open: function(e) {
|
|
1071 if (!document.all)
|
|
1072 $('input[type=file]', $dialog).first().click();
|
|
1073 },
|
|
1074 close: function() {
|
|
1075 try { $('#upload-dialog form').get(0).reset(); }
|
|
1076 catch(e){ } // ignore errors
|
|
1077
|
|
1078 $dialog.dialog('destroy').hide();
|
|
1079 $('div.addline', $dialog).remove();
|
|
1080 },
|
|
1081 width: 480
|
|
1082 }).show();
|
|
1083 }
|
|
1084
|
|
1085 function add_uploadfile(e)
|
|
1086 {
|
|
1087 var div = $(this).parent();
|
|
1088 var clone = div.clone().addClass('addline').insertAfter(div);
|
|
1089 clone.children('.iconlink').click(add_uploadfile);
|
|
1090 clone.children('input').val('');
|
|
1091
|
|
1092 if (!document.all)
|
|
1093 $('input[type=file]', clone).click();
|
|
1094 }
|
|
1095
|
|
1096
|
|
1097 /**
|
|
1098 *
|
|
1099 */
|
|
1100 function show_header_row(which, updated)
|
|
1101 {
|
|
1102 var row = $('#compose-' + which);
|
|
1103 if (row.is(':visible'))
|
|
1104 return; // nothing to be done here
|
|
1105
|
|
1106 if (compose_headers[which] && !updated)
|
|
1107 $('#_' + which).val(compose_headers[which]);
|
|
1108
|
|
1109 row.show();
|
|
1110 $('#' + which + '-link').hide();
|
|
1111
|
|
1112 layout_composeview();
|
|
1113 $('input,textarea', row).focus();
|
|
1114
|
|
1115 return false;
|
|
1116 }
|
|
1117
|
|
1118 /**
|
|
1119 *
|
|
1120 */
|
|
1121 function hide_header_row(which)
|
|
1122 {
|
|
1123 // copy and clear field value
|
|
1124 var field = $('#_' + which);
|
|
1125 compose_headers[which] = field.val();
|
|
1126 field.val('');
|
|
1127
|
|
1128 $('#compose-' + which).hide();
|
|
1129 $('#' + which + '-link').show();
|
|
1130 layout_composeview();
|
|
1131 return false;
|
|
1132 }
|
|
1133
|
|
1134
|
|
1135 /**
|
|
1136 * Fieldsets-to-tabs converter
|
|
1137 */
|
|
1138 function init_tabs(elem, current)
|
|
1139 {
|
|
1140 var content = $(elem),
|
|
1141 id = content.get(0).id,
|
|
1142 fs = content.children('fieldset');
|
|
1143
|
|
1144 if (!fs.length)
|
|
1145 return;
|
|
1146
|
|
1147 if (!id) {
|
|
1148 id = 'rcmtabcontainer';
|
|
1149 content.attr('id', id);
|
|
1150 }
|
|
1151
|
|
1152 // create tabs container
|
|
1153 var tabs = $('<ul>').addClass('tabsbar').prependTo(content);
|
|
1154
|
|
1155 // convert fildsets into tabs
|
|
1156 fs.each(function(idx) {
|
|
1157 var tab, a, elm = $(this),
|
|
1158 legend = elm.children('legend'),
|
|
1159 tid = id + '-t' + idx;
|
|
1160
|
|
1161 // create a tab
|
|
1162 a = $('<a>').text(legend.text()).attr('href', '#' + tid);
|
|
1163 tab = $('<li>').addClass('tablink');
|
|
1164
|
|
1165 // remove legend
|
|
1166 legend.remove();
|
|
1167
|
|
1168 // link fieldset with tab item
|
|
1169 elm.attr('id', tid);
|
|
1170
|
|
1171 // add the tab to container
|
|
1172 tab.append(a).appendTo(tabs);
|
|
1173 });
|
|
1174
|
|
1175 // use jquery UI tabs widget to do the interaction and styling
|
|
1176 content.tabs({
|
|
1177 active: current || 0,
|
|
1178 heightStyle: 'content',
|
|
1179 activate: function(e, ui) {resize(); }
|
|
1180 });
|
|
1181 }
|
|
1182
|
|
1183 /**
|
|
1184 * Show about page as jquery UI dialog
|
|
1185 */
|
|
1186 function show_about(elem)
|
|
1187 {
|
|
1188 var frame = $('<iframe>').attr({id: 'aboutframe', src: rcmail.url('settings/about'), frameborder: '0'});
|
|
1189 h = Math.floor($(window).height() * 0.75),
|
|
1190 buttons = {},
|
|
1191 supportln = $('#supportlink');
|
|
1192
|
|
1193 if (supportln.length && (env.supporturl = supportln.attr('href')))
|
|
1194 buttons[supportln.html()] = function(e){ env.supporturl.indexOf('mailto:') < 0 ? window.open(env.supporturl) : location.href = env.supporturl };
|
|
1195
|
|
1196 frame.dialog({
|
|
1197 modal: true,
|
|
1198 resizable: false,
|
|
1199 closeOnEscape: true,
|
|
1200 title: elem ? elem.title || elem.innerHTML : null,
|
|
1201 close: function() {
|
|
1202 frame.dialog('destroy').remove();
|
|
1203 },
|
|
1204 buttons: buttons,
|
|
1205 width: 640,
|
|
1206 height: h
|
|
1207 }).width(640);
|
|
1208 }
|
|
1209 }
|
|
1210
|
|
1211
|
|
1212 /**
|
|
1213 * Roundcube Scroller class
|
|
1214 *
|
|
1215 * @deprecated Use treelist widget
|
|
1216 */
|
|
1217 function rcube_scroller(list, top, bottom)
|
|
1218 {
|
|
1219 var ref = this;
|
|
1220
|
|
1221 this.list = $(list);
|
|
1222 this.top = $(top);
|
|
1223 this.bottom = $(bottom);
|
|
1224 this.step_size = 6;
|
|
1225 this.step_time = 20;
|
|
1226 this.delay = 500;
|
|
1227
|
|
1228 this.top
|
|
1229 .mouseenter(function() { if (rcmail.drag_active) ref.ts = window.setTimeout(function() { ref.scroll('down'); }, ref.delay); })
|
|
1230 .mouseout(function() { if (ref.ts) window.clearTimeout(ref.ts); });
|
|
1231
|
|
1232 this.bottom
|
|
1233 .mouseenter(function() { if (rcmail.drag_active) ref.ts = window.setTimeout(function() { ref.scroll('up'); }, ref.delay); })
|
|
1234 .mouseout(function() { if (ref.ts) window.clearTimeout(ref.ts); });
|
|
1235
|
|
1236 this.scroll = function(dir)
|
|
1237 {
|
|
1238 var ref = this, size = this.step_size;
|
|
1239
|
|
1240 if (!rcmail.drag_active)
|
|
1241 return;
|
|
1242
|
|
1243 if (dir == 'down')
|
|
1244 size *= -1;
|
|
1245
|
|
1246 this.list.get(0).scrollTop += size;
|
|
1247 this.ts = window.setTimeout(function() { ref.scroll(dir); }, this.step_time);
|
|
1248 };
|
|
1249 };
|
|
1250
|
|
1251
|
|
1252 /**
|
|
1253 * Roundcube UI splitter class
|
|
1254 *
|
|
1255 * @constructor
|
|
1256 */
|
|
1257 function rcube_splitter(p)
|
|
1258 {
|
|
1259 this.p = p;
|
|
1260 this.id = p.id;
|
|
1261 this.horizontal = (p.orientation == 'horizontal' || p.orientation == 'h');
|
|
1262 this.halfsize = (p.size !== undefined ? p.size : 10) / 2;
|
|
1263 this.pos = p.start || 0;
|
|
1264 this.min = p.min || 20;
|
|
1265 this.offset = p.offset || 0;
|
|
1266 this.relative = p.relative ? true : false;
|
|
1267 this.drag_active = false;
|
|
1268 this.render = p.render;
|
|
1269 this.callback = p.callback;
|
|
1270
|
|
1271 var me = this;
|
|
1272 rcube_splitter._instances[this.id] = me;
|
|
1273
|
|
1274 this.init = function()
|
|
1275 {
|
|
1276 this.p1 = $(this.p.p1);
|
|
1277 this.p2 = $(this.p.p2);
|
|
1278 this.parent = this.p1.parent();
|
|
1279
|
|
1280 // check if referenced elements exist, otherwise abort
|
|
1281 if (!this.p1.length || !this.p2.length)
|
|
1282 return;
|
|
1283
|
|
1284 // create and position the handle for this splitter
|
|
1285 this.p1pos = this.relative ? this.p1.position() : this.p1.offset();
|
|
1286 this.p2pos = this.relative ? this.p2.position() : this.p2.offset();
|
|
1287 this.handle = $('<div>')
|
|
1288 .attr('id', this.id)
|
|
1289 .attr('unselectable', 'on')
|
|
1290 .attr('role', 'presentation')
|
|
1291 .addClass('splitter ' + (this.horizontal ? 'splitter-h' : 'splitter-v'))
|
|
1292 .appendTo(this.parent)
|
8
|
1293 .mousedown(onDragStart);
|
0
|
1294
|
|
1295 if (this.horizontal) {
|
|
1296 var top = this.p1pos.top + this.p1.outerHeight();
|
|
1297 this.handle.css({ left:'0px', top:top+'px' });
|
|
1298 }
|
|
1299 else {
|
|
1300 var left = this.p1pos.left + this.p1.outerWidth();
|
|
1301 this.handle.css({ left:left+'px', top:'0px' });
|
|
1302 }
|
|
1303
|
|
1304 // listen to window resize on IE
|
|
1305 if (bw.ie)
|
|
1306 $(window).resize(onResize);
|
|
1307
|
|
1308 // read saved position from cookie
|
|
1309 var cookie = this.get_cookie();
|
|
1310 if (cookie && !isNaN(cookie)) {
|
|
1311 this.pos = parseFloat(cookie);
|
|
1312 this.resize();
|
|
1313 }
|
|
1314 else if (this.pos) {
|
|
1315 this.resize();
|
|
1316 this.set_cookie();
|
|
1317 }
|
|
1318 };
|
|
1319
|
|
1320 /**
|
|
1321 * Set size and position of all DOM objects
|
|
1322 * according to the saved splitter position
|
|
1323 */
|
|
1324 this.resize = function()
|
|
1325 {
|
|
1326 if (this.horizontal) {
|
|
1327 this.p1.css('height', Math.floor(this.pos - this.p1pos.top - Math.floor(this.halfsize)) + 'px');
|
|
1328 this.p2.css('top', Math.ceil(this.pos + Math.ceil(this.halfsize) + 2) + 'px');
|
|
1329 this.handle.css('top', Math.round(this.pos - this.halfsize + this.offset)+'px');
|
|
1330 if (bw.ie) {
|
8
|
1331 var new_height = parseInt(this.parent.outerHeight(), 10) - parseInt(this.p2.css('top'), 10);
|
0
|
1332 this.p2.css('height', (new_height > 0 ? new_height : 0) + 'px');
|
|
1333 }
|
|
1334 }
|
|
1335 else {
|
|
1336 this.p1.css('width', Math.floor(this.pos - this.p1pos.left - Math.floor(this.halfsize)) + 'px');
|
|
1337 this.p2.css('left', Math.ceil(this.pos + Math.ceil(this.halfsize)) + 'px');
|
|
1338 this.handle.css('left', Math.round(this.pos - this.halfsize + this.offset + 3)+'px');
|
|
1339 if (bw.ie) {
|
|
1340 var new_width = parseInt(this.parent.outerWidth(), 10) - parseInt(this.p2.css('left'), 10) ;
|
|
1341 this.p2.css('width', (new_width > 0 ? new_width : 0) + 'px');
|
|
1342 }
|
|
1343 }
|
|
1344
|
|
1345 this.p2.resize();
|
|
1346 this.p1.resize();
|
|
1347
|
|
1348 // also resize iframe covers
|
|
1349 if (this.drag_active) {
|
|
1350 $('iframe').each(function(i, elem) {
|
|
1351 var pos = $(this).offset();
|
|
1352 $('#iframe-splitter-fix-'+i).css({ top: pos.top+'px', left: pos.left+'px', width:elem.offsetWidth+'px', height: elem.offsetHeight+'px' });
|
|
1353 });
|
|
1354 }
|
|
1355
|
|
1356 if (typeof this.render == 'function')
|
|
1357 this.render(this);
|
|
1358 };
|
|
1359
|
|
1360 /**
|
|
1361 * Handler for mousedown events
|
|
1362 */
|
|
1363 function onDragStart(e)
|
|
1364 {
|
|
1365 // disable text selection while dragging the splitter
|
|
1366 if (bw.konq || bw.chrome || bw.safari)
|
|
1367 document.body.style.webkitUserSelect = 'none';
|
|
1368
|
|
1369 me.p1pos = me.relative ? me.p1.position() : me.p1.offset();
|
|
1370 me.p2pos = me.relative ? me.p2.position() : me.p2.offset();
|
|
1371 me.drag_active = true;
|
|
1372
|
|
1373 // start listening to mousemove events
|
8
|
1374 $(document).on('mousemove.' + this.id, onDrag).on('mouseup.' + this.id, onDragStop);
|
|
1375
|
|
1376 // hack messages list so it will propagate the mouseup event over the list
|
|
1377 if (rcmail.message_list)
|
|
1378 rcmail.message_list.drag_active = true;
|
0
|
1379
|
|
1380 // enable dragging above iframes
|
|
1381 $('iframe').each(function(i, elem) {
|
|
1382 $('<div>')
|
|
1383 .attr('id', 'iframe-splitter-fix-'+i)
|
|
1384 .addClass('iframe-splitter-fix')
|
|
1385 .css({ background: '#fff',
|
|
1386 width: elem.offsetWidth+'px', height: elem.offsetHeight+'px',
|
|
1387 position: 'absolute', opacity: '0.001', zIndex: 1000
|
|
1388 })
|
|
1389 .css($(this).offset())
|
|
1390 .appendTo('body');
|
|
1391 });
|
|
1392 };
|
|
1393
|
|
1394 /**
|
|
1395 * Handler for mousemove events
|
|
1396 */
|
|
1397 function onDrag(e)
|
|
1398 {
|
|
1399 if (!me.drag_active)
|
|
1400 return false;
|
|
1401
|
|
1402 // with timing events dragging action is more responsive
|
|
1403 window.clearTimeout(me.ts);
|
|
1404 me.ts = window.setTimeout(function() { onDragAction(e); }, 1);
|
|
1405
|
|
1406 return false;
|
|
1407 };
|
|
1408
|
|
1409 /**
|
|
1410 * Dragging action (see onDrag())
|
|
1411 */
|
|
1412 function onDragAction(e)
|
|
1413 {
|
|
1414 var pos = rcube_event.get_mouse_pos(e);
|
|
1415
|
|
1416 if (me.relative) {
|
|
1417 var parent = me.parent.offset();
|
|
1418 pos.x -= parent.left;
|
|
1419 pos.y -= parent.top;
|
|
1420 }
|
|
1421
|
|
1422 if (me.horizontal) {
|
|
1423 if (((pos.y - me.halfsize) > me.p1pos.top) && ((pos.y + me.halfsize) < (me.p2pos.top + me.p2.outerHeight()))) {
|
|
1424 me.pos = Math.max(me.min, pos.y - Math.max(0, me.offset));
|
|
1425 if (me.pos > me.min)
|
|
1426 me.pos = Math.min(me.pos, me.parent.height() - me.min);
|
|
1427
|
|
1428 me.resize();
|
|
1429 }
|
|
1430 }
|
|
1431 else {
|
|
1432 if (((pos.x - me.halfsize) > me.p1pos.left) && ((pos.x + me.halfsize) < (me.p2pos.left + me.p2.outerWidth()))) {
|
|
1433 me.pos = Math.max(me.min, pos.x - Math.max(0, me.offset));
|
|
1434 if (me.pos > me.min)
|
|
1435 me.pos = Math.min(me.pos, me.parent.width() - me.min);
|
|
1436
|
|
1437 me.resize();
|
|
1438 }
|
|
1439 }
|
|
1440
|
|
1441 me.p1pos = me.relative ? me.p1.position() : me.p1.offset();
|
|
1442 me.p2pos = me.relative ? me.p2.position() : me.p2.offset();
|
|
1443 };
|
|
1444
|
|
1445 /**
|
|
1446 * Handler for mouseup events
|
|
1447 */
|
|
1448 function onDragStop(e)
|
|
1449 {
|
|
1450 // resume the ability to highlight text
|
|
1451 if (bw.konq || bw.chrome || bw.safari)
|
|
1452 document.body.style.webkitUserSelect = 'auto';
|
|
1453
|
|
1454 // cancel the listening for drag events
|
8
|
1455 $(document).off('.' + me.id);
|
0
|
1456 me.drag_active = false;
|
|
1457
|
8
|
1458 if (rcmail.message_list)
|
|
1459 rcmail.message_list.drag_active = false;
|
|
1460
|
0
|
1461 // remove temp divs
|
|
1462 $('div.iframe-splitter-fix').remove();
|
|
1463
|
|
1464 me.set_cookie();
|
|
1465
|
|
1466 if (typeof me.callback == 'function')
|
|
1467 me.callback(me);
|
|
1468
|
|
1469 return bw.safari ? true : rcube_event.cancel(e);
|
|
1470 };
|
|
1471
|
|
1472 /**
|
|
1473 * Handler for window resize events
|
|
1474 */
|
|
1475 function onResize(e)
|
|
1476 {
|
|
1477 if (me.horizontal) {
|
8
|
1478 var new_height = parseInt(me.parent.outerHeight(), 10) - parseInt(me.p2[0].style.top, 10);
|
0
|
1479 me.p2.css('height', (new_height > 0 ? new_height : 0) +'px');
|
|
1480 }
|
|
1481 else {
|
|
1482 var new_width = parseInt(me.parent.outerWidth(), 10) - parseInt(me.p2[0].style.left, 10);
|
|
1483 me.p2.css('width', (new_width > 0 ? new_width : 0) + 'px');
|
|
1484 }
|
|
1485 };
|
|
1486
|
|
1487 /**
|
|
1488 * Get saved splitter position from cookie
|
|
1489 */
|
|
1490 this.get_cookie = function()
|
|
1491 {
|
|
1492 return window.UI ? UI.get_pref(this.id) : null;
|
|
1493 };
|
|
1494
|
|
1495 /**
|
|
1496 * Saves splitter position in cookie
|
|
1497 */
|
|
1498 this.set_cookie = function()
|
|
1499 {
|
|
1500 if (window.UI)
|
|
1501 UI.save_pref(this.id, this.pos);
|
|
1502 };
|
|
1503
|
|
1504 } // end class rcube_splitter
|
|
1505
|
|
1506
|
|
1507 // static getter for splitter instances
|
|
1508 rcube_splitter._instances = {};
|
|
1509
|
|
1510 rcube_splitter.get_instance = function(id)
|
|
1511 {
|
|
1512 return rcube_splitter._instances[id];
|
|
1513 };
|
|
1514
|
|
1515 // @license-end
|