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