diff options
Diffstat (limited to 'skins/larry/ui.js')
-rw-r--r-- | skins/larry/ui.js | 184 |
1 files changed, 142 insertions, 42 deletions
diff --git a/skins/larry/ui.js b/skins/larry/ui.js index d558f16a2..44fc727f6 100644 --- a/skins/larry/ui.js +++ b/skins/larry/ui.js @@ -31,6 +31,7 @@ function rcube_mail_ui() var me = this; var mailviewsplit; var compose_headers = {}; + var prefs; // export public methods this.set = setenv; @@ -44,11 +45,13 @@ function rcube_mail_ui() this.show_header_row = show_header_row; this.hide_header_row = hide_header_row; this.update_quota = update_quota; + this.get_pref = get_pref; + this.save_pref = save_pref; // set minimal mode on small screens (don't wait for document.ready) if (window.$ && document.body) { - var minmode = rcmail.get_cookie('minimalmode'); + var minmode = get_pref('minimalmode'); if (parseInt(minmode) || (minmode === null && $(window).height() < 850)) { $(document.body).addClass('minimal'); } @@ -68,6 +71,51 @@ function rcube_mail_ui() } /** + * Get preference stored in browser + */ + function get_pref(key) + { + if (!prefs) { + prefs = window.localStorage ? rcmail.local_storage_get_item('prefs.larry', {}) : {}; + } + + // fall-back to cookies + if (prefs[key] == null) { + var cookie = rcmail.get_cookie(key); + if (cookie != null) { + prefs[key] = cookie; + + // copy value to local storage and remove cookie + if (window.localStorage) { + rcmail.local_storage_set_item('prefs.larry', prefs); + rcmail.set_cookie(key, cookie, new Date()); // expire cookie + } + } + } + + return prefs[key]; + } + + /** + * Saves preference value to browser storage + */ + function save_pref(key, val) + { + prefs[key] = val; + + // write prefs to local storage + if (window.localStorage) { + rcmail.local_storage_set_item('prefs.larry', prefs); + } + else { + // store value in cookie + var exp = new Date(); + exp.setYear(exp.getFullYear() + 1); + rcmail.set_cookie(key, val, exp); + } + } + + /** * Initialize UI * Called on document.ready */ @@ -82,15 +130,15 @@ function rcube_mail_ui() $('#taskbar .minmodetoggle').click(function(e){ var ismin = $(document.body).toggleClass('minimal').hasClass('minimal'); - rcmail.set_cookie('minimalmode', ismin?1:0); + save_pref('minimalmode', ismin?1:0); $(window).resize(); }); /*** mail task ***/ if (rcmail.env.task == 'mail') { - rcmail.addEventListener('menu-open', menu_open); - rcmail.addEventListener('menu-save', menu_save); - rcmail.addEventListener('responseafterlist', function(e){ switch_view_mode(rcmail.env.threading ? 'thread' : 'list') }); + rcmail.addEventListener('menu-open', menu_open) + .addEventListener('menu-save', menu_save) + .addEventListener('responseafterlist', function(e){ switch_view_mode(rcmail.env.threading ? 'thread' : 'list') }); var dragmenu = $('#dragmessagemenu'); if (dragmenu.length) { @@ -99,21 +147,28 @@ function rcube_mail_ui() } if (rcmail.env.action == 'show' || rcmail.env.action == 'preview') { - rcmail.addEventListener('enable-command', enable_command); - rcmail.addEventListener('aftershow-headers', function() { layout_messageview(); }); - rcmail.addEventListener('afterhide-headers', function() { layout_messageview(); }); + rcmail.addEventListener('enable-command', enable_command) + .addEventListener('aftershow-headers', function() { layout_messageview(); }) + .addEventListener('afterhide-headers', function() { layout_messageview(); }); $('#previewheaderstoggle').click(function(e){ toggle_preview_headers(); return false }); // add menu link for each attachment $('#attachment-list > li').each(function() { - $(this).append($('<a class="drop">').click(function() { attachmentmenu(this); })); + $(this).append($('<a class="drop"></a>').click(function() { attachmentmenu(this); })); }); + + if (get_pref('previewheaders') == '1') { + toggle_preview_headers(); + } } 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(); + rcmail.addEventListener('aftersend-attachment', show_uploadform) + .addEventListener('add-recipient', function(p){ show_header_row(p.field, true); }) + .addEventListener('aftertoggle-editor', function(e){ + window.setTimeout(function(){ layout_composeview() }, 200); + if (e && e.mode) + $("select[name='editorSelector']").val(e.mode); + }); // Show input elements with non-empty value var f, v, field, fields = ['cc', 'bcc', 'replyto', 'followupto']; @@ -130,9 +185,18 @@ function rcube_mail_ui() $('#composeoptionstoggle').toggleClass('remove'); $('#composeoptions').toggle(); layout_composeview(); + save_pref('composeoptions', $('#composeoptions').is(':visible') ? '1' : '0'); return false; }).css('cursor', 'pointer'); + if (get_pref('composeoptions') !== '0') { + $('#composeoptionstoggle').click(); + } + + // adjust hight when textarea starts to scroll + $("textarea[name='_to'], textarea[name='_cc'], textarea[name='_bcc']").change(function(e){ adjust_compose_editfields(this); }).change(); + rcmail.addEventListener('autocomplete_insert', function(p){ adjust_compose_editfields(p.field); }); + // toggle compose options if opened in new window and they were visible before var opener_rc = rcmail.opener(); if (opener_rc && opener_rc.env.action == 'compose' && $('#composeoptionstoggle', opener.document).hasClass('remove')) @@ -152,11 +216,9 @@ function rcube_mail_ui() if (previewframe) mailviewsplit.init(); - new rcube_scroller('#folderlist-content', '#folderlist-header', '#folderlist-footer'); - - rcmail.addEventListener('setquota', update_quota); - rcmail.addEventListener('enable-command', enable_command); - rcmail.addEventListener('afterimport-messages', show_uploadform); + rcmail.addEventListener('setquota', update_quota) + .addEventListener('enable-command', enable_command) + .addEventListener('afterimport-messages', show_uploadform); } else if (rcmail.env.action == 'get') { new rcube_splitter({ id:'mailpartsplitterv', p1:'#messagepartheader', p2:'#messagepartcontainer', @@ -211,17 +273,15 @@ function rcube_mail_ui() } /*** addressbook task ***/ else if (rcmail.env.task == 'addressbook') { - rcmail.addEventListener('afterupload-photo', show_uploadform); - rcmail.addEventListener('beforepushgroup', push_contactgroup); - rcmail.addEventListener('beforepopgroup', pop_contactgroup); + rcmail.addEventListener('afterupload-photo', show_uploadform) + .addEventListener('beforepushgroup', push_contactgroup) + .addEventListener('beforepopgroup', pop_contactgroup); 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'); } var dragmenu = $('#dragcontactmenu'); @@ -309,8 +369,10 @@ function rcube_mail_ui() 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]; @@ -319,9 +381,10 @@ function rcube_mail_ui() && !config.toggle && (!config.editable || !target_overlaps(target, obj.get(0))) && (!config.sticky || !rcube_mouse_is_over(e, obj.get(0))) + && !$(target).is('.folder-selector-link') ) { var myid = id+''; - window.setTimeout(function(){ show_popupmenu(myid, false) }, 10); + window.setTimeout(function() { show_popupmenu(myid, false); }, 10); } } } @@ -366,8 +429,15 @@ function rcube_mail_ui() */ function message_displayed(p) { + var siblings = $(p.object).siblings('div'); + if (siblings.length) + $(p.object).insertBefore(siblings.first()); + // show a popup dialog on errors if (p.type == 'error' && rcmail.env.task != 'login') { + // hide original message object, we don't want both + rcmail.hide_message(p.object); + if (me.message_timer) { window.clearTimeout(me.message_timer); } @@ -376,8 +446,10 @@ function rcube_mail_ui() } var msg = p.message, - pos = $(p.object).offset(); - pos.top -= (rcmail.env.task == 'login' ? 20 : 160); + dialog_close = function() { + // check if dialog is still displayed, to prevent from js error + me.messagedialog.is(':visible') && me.messagedialog.dialog('destroy').hide(); + }; if (me.messagedialog.is(':visible')) msg = me.messagedialog.html() + '<p>' + p.message + '</p>'; @@ -388,16 +460,14 @@ function rcube_mail_ui() closeOnEscape: true, dialogClass: 'popupmessage ' + p.type, title: env.errortitle, - close: function() { - me.messagedialog.dialog('destroy').hide(); - }, - position: ['center', pos.top], - hide: { effect:'drop', direction:'down' }, + close: dialog_close, + position: ['center', 'center'], + hide: {effect: 'fadeOut'}, width: 420, minHeight: 90 }).show(); - me.message_timer = window.setTimeout(function(){ me.messagedialog.dialog('close'); }, Math.max(2000, p.timeout / 2)); + me.message_timer = window.setTimeout(dialog_close, p.timeout); } } @@ -428,6 +498,16 @@ function rcube_mail_ui() // STUB } + function adjust_compose_editfields(elem) + { + if (elem.nodeName == 'TEXTAREA') { + var $elem = $(elem), line_height = 14, // hard-coded because some browsers only provide the outer height in elem.clientHeight + content_height = elem.scrollHeight, + rows = elem.value.length > 80 && content_height > line_height*1.5 ? 2 : 1; + $elem.css('height', (line_height*rows) + 'px'); + layout_composeview(); + } + } function layout_composeview() { @@ -473,7 +553,7 @@ function rcube_mail_ui() function enable_command(p) { - if (p.command == 'reply-list') { + if (p.command == 'reply-list' && rcmail.env.reply_all_mode == 1) { var label = rcmail.gettext(p.status ? 'replylist' : 'replyall'); if (rcmail.env.action == 'preview') $('a.button.replyall').attr('title', label); @@ -584,7 +664,7 @@ function rcube_mail_ui() var button = $(e.target), frame = $('#mailpreviewframe'), visible = !frame.is(':visible'), - splitter = mailviewsplit.pos || parseInt(rcmail.get_cookie('mailviewsplitter') || 320), + splitter = mailviewsplit.pos || parseInt(get_pref('mailviewsplitter') || 320), topstyles, bottomstyles, uid; frame.toggle(); @@ -592,7 +672,7 @@ function rcube_mail_ui() if (visible) { $('#mailview-top').removeClass('fullheight').css({ bottom:'auto' }); - $('#mailview-bottom').css({ height:'auto' }); + $('#mailview-bottom').css({ height:'auto' }).show(); rcmail.env.contentframe = 'messagecontframe'; if (uid = rcmail.message_list.get_single_selection()) @@ -610,8 +690,8 @@ function rcube_mail_ui() rcmail.env.contentframe = null; rcmail.show_contentframe(false); - $('#mailview-top').addClass('fullheight').css({ height:'auto', bottom:'28px' }); - $('#mailview-bottom').css({ top:'auto', height:'26px' }); + $('#mailview-top').addClass('fullheight').css({ height:'auto', bottom:'0px' }); + $('#mailview-bottom').css({ top:'auto', height:'0px' }).hide(); if (mailviewsplit.handle) mailviewsplit.handle.hide(); @@ -641,6 +721,8 @@ function rcube_mail_ui() button.attr('href', '#hide').removeClass('add').addClass('remove') else button.attr('href', '#details').removeClass('remove').addClass('add') + + save_pref('previewheaders', full.is(':visible') ? '1' : '0'); } @@ -1157,7 +1239,7 @@ function rcube_splitter(p) $(window).resize(onResize); // read saved position from cookie - var cookie = rcmail.get_cookie(this.id); + var cookie = this.get_cookie(); if (cookie && !isNaN(cookie)) { this.pos = parseFloat(cookie); this.resize(); @@ -1246,6 +1328,18 @@ function rcube_splitter(p) if (!me.drag_active) return false; + // with timing events dragging action is more responsive + window.clearTimeout(me.ts); + me.ts = window.setTimeout(function() { onDragAction(e); }, 1); + + return false; + }; + + /** + * Dragging action (see onDrag()) + */ + function onDragAction(e) + { var pos = rcube_event.get_mouse_pos(e); if (me.relative) { @@ -1269,7 +1363,6 @@ function rcube_splitter(p) me.p1pos = me.relative ? me.p1.position() : me.p1.offset(); me.p2pos = me.relative ? me.p2.position() : me.p2.offset(); - return false; }; /** @@ -1312,13 +1405,20 @@ function rcube_splitter(p) }; /** + * Get saved splitter position from cookie + */ + this.get_cookie = function() + { + return window.UI ? UI.get_pref(this.id) : null; + }; + + /** * Saves splitter position in cookie */ this.set_cookie = function() { - var exp = new Date(); - exp.setYear(exp.getFullYear() + 1); - rcmail.set_cookie(this.id, this.pos, exp); + if (window.UI) + UI.save_pref(this.id, this.pos); }; } // end class rcube_splitter |