/** * Roundcube functions for default skin interface * * Copyright (c) 2011, The Roundcube Dev Team * * The contents are subject to the Creative Commons Attribution-ShareAlike * License. It is allowed to copy, distribute, transmit and to adapt the work * by keeping credits to the original autors in the README file. * See http://creativecommons.org/licenses/by-sa/3.0/ for details. * * $Id$ */ function rcube_mail_ui() { var env = {}; var popups = {}; var popupconfig = { forwardmenu: { editable:1 }, searchmenu: { editable:1, callback:searchmenu }, listoptions: { editable:1 }, dragmessagemenu: { sticky:1 }, groupmenu: { above:1 }, mailboxmenu: { above:1 }, composeoptionsmenu: { editable:1, overlap:1 }, spellmenu: { callback: spellmenu }, // toggle: #1486823, #1486930 'attachment-form': { editable:1, above:1, toggle:!bw.ie&&!bw.linux }, 'upload-form': { editable:1, toggle:!bw.ie&&!bw.linux } }; var me = this; var mailviewsplit; var compose_headers = {}; // export public methods this.set = setenv; this.init = init; this.init_tabs = init_tabs; this.show_about = show_about; this.show_popup = show_popup; this.set_searchmod = set_searchmod; this.show_uploadform = show_uploadform; this.show_header_row = show_header_row; this.hide_header_row = hide_header_row; /** * */ function setenv(key, val) { env[key] = val; } /** * Initialize UI * Called on document.ready */ function init() { rcmail.addEventListener('message', message_displayed); /*** mail task ***/ if (rcmail.env.task == 'mail') { rcmail.addEventListener('menu-open', show_listoptions); rcmail.addEventListener('menu-save', save_listoptions); rcmail.addEventListener('responseafterlist', function(e){ switch_view_mode(rcmail.env.threading ? 'thread' : 'list') }); var dragmenu = $('#dragmessagemenu'); if (dragmenu.length) { rcmail.gui_object('message_dragmenu', 'dragmessagemenu'); popups.dragmessagemenu = dragmenu; } if (rcmail.env.action == 'show' || rcmail.env.action == 'preview') { layout_messageview(); rcmail.addEventListener('aftershow-headers', function() { layout_messageview(); }); rcmail.addEventListener('afterhide-headers', function() { layout_messageview(); }); $('#previewheaderstoggle').click(function(e){ toggle_preview_headers(this); return false }); } else if (rcmail.env.action == 'compose') { rcmail.addEventListener('aftertoggle-editor', function(){ window.setTimeout(function(){ layout_composeview() }, 200); }); rcmail.addEventListener('aftersend-attachment', show_uploadform); rcmail.addEventListener('add-recipient', function(p){ show_header_row(p.field, true); }); layout_composeview(); // Show input elements with non-empty value var field, fields = ['cc', 'bcc', 'replyto', 'followupto']; for (var f=0; f < fields.length; f++) { if ((field = $('#_'+fields[f])) && field.length && field.val() != '') show_header_row(fields[f], true); } $('#composeoptionstoggle').parent().click(function(){ $('#composeoptionstoggle').toggleClass('enabled'); $('#composeoptions').toggle(); layout_composeview(); return false; }).css('cursor', 'pointer'); new rcube_splitter({ id:'composesplitterv', p1:'#composeview-left', p2:'#composeview-right', orientation:'v', relative:true, start:248, min:170, size:12, render:layout_composeview }).init(); } else if (rcmail.env.action == 'list' || !rcmail.env.action) { var previewframe = $('#mailpreviewframe').is(':visible'); $('#mailpreviewtoggle').addClass(previewframe ? 'enabled' : 'closed').click(function(e){ toggle_preview_pane(e); return false }); $('#maillistmode').addClass(rcmail.env.threading ? '' : 'selected').click(function(e){ switch_view_mode('list'); return false }); $('#mailthreadmode').addClass(rcmail.env.threading ? 'selected' : '').click(function(e){ switch_view_mode('thread'); return false }); mailviewsplit = new rcube_splitter({ id:'mailviewsplitter', p1:'#mailview-top', p2:'#mailview-bottom', orientation:'h', relative:true, start:310, min:150, size:12, offset:4 }); if (previewframe) mailviewsplit.init(); new rcube_scroller('#folderlist-content', '#folderlist-header', '#folderlist-footer'); rcmail.addEventListener('setquota', update_quota); } if ($('#mailview-left').length) { new rcube_splitter({ id:'mailviewsplitterv', p1:'#mailview-left', p2:'#mailview-right', orientation:'v', relative:true, start:226, min:150, size:12, callback:render_mailboxlist, render:resize_leftcol }).init(); } } /*** settings task ***/ else if (rcmail.env.task == 'settings') { rcmail.addEventListener('init', function(){ var tab = '#settingstabpreferences'; if (rcmail.env.action) tab = '#settingstab' + (rcmail.env.action.indexOf('identity')>0 ? 'identities' : rcmail.env.action.replace(/\./g, '')); $(tab).addClass('selected') .children().first().removeAttr('onclick').click(function() { return false; }); }); if (rcmail.env.action == 'folders') { new rcube_splitter({ id:'folderviewsplitter', p1:'#folderslist', p2:'#folder-details', orientation:'v', relative:true, start:266, min:180, size:12 }).init(); new rcube_scroller('#folderslist-content', '#folderslist-header', '#folderslist-footer'); rcmail.addEventListener('setquota', update_quota); } else if (rcmail.env.action == 'identities') { new rcube_splitter({ id:'identviewsplitter', p1:'#identitieslist', p2:'#identity-details', orientation:'v', relative:true, start:266, min:180, size:12 }).init(); } else if (rcmail.env.action == 'preferences' || !rcmail.env.action) { new rcube_splitter({ id:'prefviewsplitter', p1:'#sectionslist', p2:'#preferences-box', orientation:'v', relative:true, start:266, min:180, size:12 }).init(); } } /*** addressbook task ***/ else if (rcmail.env.task == 'addressbook') { rcmail.addEventListener('afterupload-photo', show_uploadform); if (rcmail.env.action == '') { new rcube_splitter({ id:'addressviewsplitterd', p1:'#addressview-left', p2:'#addressview-right', orientation:'v', relative:true, start:226, min:150, size:12, render:resize_leftcol }).init(); new rcube_splitter({ id:'addressviewsplitter', p1:'#addresslist', p2:'#contacts-box', orientation:'v', relative:true, start:286, min:270, size:12 }).init(); new rcube_scroller('#directorylist-content', '#directorylist-header', '#directorylist-footer'); } } // turn a group of fieldsets into tabs $('.tabbed').each(function(idx, elem){ init_tabs(elem); }) // decorate select elements $('select.decorated').each(function(){ if (bw.opera) { $(this).removeClass('decorated'); return; } var select = $(this), height = Math.max(select.height(), 26) - 2, width = select.width() - 22, title = $('option', this).first().text(); if ($('option:selected', this).val() != '') title = $('option:selected', this).text(); var overlay = $('' + title + '') .css('position', 'absolute') .offset(select.position()) .insertAfter(select); overlay.children().width(width).height(height).css('line-height', (height - 1) + 'px'); select.change(function() { var val = $('option:selected', this).text(); $(this).next().children().html(val); }); var parent = select.parent(); if (parent.css('position') != 'absolute') parent.css('position', 'relative'); // re-set original select width to fix click action and options width in some browsers select.width(overlay.width()); }); $(document.body) .bind('mouseup', body_mouseup) .bind('keyup', function(e){ if (e.keyCode == 27) { for (var id in popups) { if (popups[id].is(':visible')) show_popup(id, false); } } }); $('iframe').load(function(e){ // this = iframe var doc = this.contentDocument ? this.contentDocument : this.contentWindow ? this.contentWindow.document : null; $(doc).mouseup(body_mouseup); }) .contents().mouseup(body_mouseup); // don't use $(window).resize() due to some unwanted side-effects window.onresize = resize; resize(); } /** * Handler for mouse-up events on the document body. * This will close all open popup menus */ function body_mouseup(e) { var config, obj, target = e.target; if (target.className == 'inner') target = e.target.parentNode; for (var id in popups) { obj = popups[id]; config = popupconfig[id]; if (obj.is(':visible') && target.id != id+'link' && !config.toggle && (!config.editable || !target_overlaps(target, obj.get(0))) && (!config.sticky || !rcube_mouse_is_over(e, obj.get(0))) ) { var myid = id+''; window.setTimeout(function(){ show_popupmenu(myid, false) }, 10); } } } /** * Update UI on window resize */ function resize() { if (rcmail.env.task == 'mail' && (rcmail.env.action == 'show' || rcmail.env.action == 'preview')) { layout_messageview(); } if (rcmail.env.task == 'mail' && rcmail.env.action == 'compose') { layout_composeview(); } // make iframe footer buttons float if scrolling is active $('body.iframe .footerleft').each(function(){ var footer = $(this), body = $(document.body), floating = footer.hasClass('floating'), overflow = body.outerHeight(true) > $(window).height(); if (overflow != floating) { var action = overflow ? 'addClass' : 'removeClass'; footer[action]('floating'); body[action]('floatingbuttons'); } }) } /** * Triggered when a new user message is displayed */ function message_displayed(p) { // show a popup dialog on errors if (p.type == 'error' && rcmail.env.task != 'login') { if (!me.messagedialog) { me.messagedialog = $('