From b2992dd2283c3d0ac95f3293497dfaed0493f607 Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Wed, 07 May 2014 11:34:28 -0400
Subject: [PATCH] Further accessibility improvements regarding keyboard navigation and document structure

---
 skins/larry/ui.js |  491 ++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 367 insertions(+), 124 deletions(-)

diff --git a/skins/larry/ui.js b/skins/larry/ui.js
index ccc9cef..922bb21 100644
--- a/skins/larry/ui.js
+++ b/skins/larry/ui.js
@@ -1,3 +1,5 @@
+// @license http://creativecommons.org/publicdomain/zero/1.0/legalcode CC0
+
 /**
  * Roundcube functions for default skin interface
  *
@@ -9,7 +11,6 @@
  * See http://creativecommons.org/licenses/by-sa/3.0/ for details.
  */
 
-
 function rcube_mail_ui()
 {
   var env = {};
@@ -19,7 +20,7 @@
     searchmenu:         { editable:1, callback:searchmenu },
     attachmentmenu:     { },
     listoptions:        { editable:1 },
-    dragmessagemenu:    { sticky:1 },
+    dragmenu:           { sticky:1 },
     groupmenu:          { above:1 },
     mailboxmenu:        { above:1 },
     spellmenu:          { callback: spellmenu },
@@ -31,6 +32,9 @@
   var me = this;
   var mailviewsplit;
   var compose_headers = {};
+  var prefs;
+  var focused_popup;
+  var popup_keyboard_active = false;
 
   // export public methods
   this.set = setenv;
@@ -38,19 +42,27 @@
   this.init_tabs = init_tabs;
   this.show_about = show_about;
   this.show_popup = show_popup;
+  this.toggle_popup = toggle_popup;
   this.add_popup = add_popup;
   this.set_searchmod = set_searchmod;
+  this.set_searchscope = set_searchscope;
   this.show_uploadform = show_uploadform;
   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');
+    }
+
+    if (bw.tablet) {
+      $('#viewport').attr('content', "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0");
     }
   }
 
@@ -61,6 +73,51 @@
   function setenv(key, val)
   {
     env[key] = val;
+  }
+
+  /**
+   * 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);
+    }
   }
 
   /**
@@ -78,38 +135,54 @@
 
     $('#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_toggle)
+        .addEventListener('menu-close', menu_toggle)
+        .addEventListener('menu-save', save_listoptions)
+        .addEventListener('responseafterlist', function(e){ switch_view_mode(rcmail.env.threading ? 'thread' : 'list', true) })
+        .addEventListener('responseaftersearch', function(e){ switch_view_mode(rcmail.env.threading ? 'thread' : 'list', true) });
 
       var dragmenu = $('#dragmessagemenu');
       if (dragmenu.length) {
-        rcmail.gui_object('message_dragmenu', 'dragmessagemenu');
-        popups.dragmessagemenu = dragmenu;
+        rcmail.gui_object('dragmenu', 'dragmessagemenu');
+        popups.dragmenu = dragmenu;
       }
 
       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" tabindex="0" aria-haspopup="true">Show options</a>')
+              .bind('click keypress', function(e) {
+                  if (e.type != 'keypress' || rcube_event.get_keycode(e) == 13) {
+                      attachmentmenu(this, e);
+                      return false;
+                  }
+              })
+          );
         });
+
+        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'];
@@ -126,8 +199,17 @@
           $('#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();
@@ -148,11 +230,13 @@
         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',
+          orientation:'v', relative:true, start:226, min:150, size:12}).init();
       }
 
       if ($('#mailview-left').length) {
@@ -183,31 +267,46 @@
         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 == 'responses') {
+        new rcube_splitter({ id:'responseviewsplitter', 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();
       }
+      else if (rcmail.env.action == 'edit-prefs') {
+        $('<a href="#toggle">&#9660;</a>')
+            .addClass('advanced-toggle')
+            .appendTo('#preferences-details fieldset.advanced legend');
+
+          $('#preferences-details fieldset.advanced legend').click(function(e){
+            var collapsed = $(this).hasClass('collapsed'),
+              toggle = $('.advanced-toggle', this).html(collapsed ? '&#9650;' : '&#9660;');
+            $(this)
+              .toggleClass('collapsed')
+              .closest('fieldset').children('.propform').toggle()
+          }).addClass('collapsed')
+      }
     }
     /***  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');
       }
-    }
 
-    // set min-width to show all toolbar buttons
-    var screen = $('.minwidth');
-    if (screen.length) {
-      screen.css('min-width', $('.toolbar').width() + $('#quicksearchbar').parent().width() + 20);
+      var dragmenu = $('#dragcontactmenu');
+      if (dragmenu.length) {
+        rcmail.gui_object('dragmenu', 'dragcontactmenu');
+        popups.dragmenu = dragmenu;
+      }
     }
 
     // turn a group of fieldsets into tabs
@@ -245,18 +344,21 @@
           var val = $('option:selected', this).text();
           $(this).next().children().text(val);
         });
+
+      select
+        .on('focus', function(e){ overlay.addClass('focus'); })
+        .on('blur', function(e){ overlay.removeClass('focus'); });
     });
+
+    // set min-width to show all toolbar buttons
+    var screen = $('body.minwidth');
+    if (screen.length) {
+      screen.css('min-width', $('.toolbar').width() + $('#quicksearchbar').width() + $('#searchfilter').width() + 30);
+    }
 
     $(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);
-          }
-        }
-      });
+      .bind('keydown', popup_keypress);
 
     $('iframe').load(function(e){
       // this = iframe
@@ -282,19 +384,23 @@
   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'
+        && target != obj.get(0)  // check if scroll bar was clicked (#1489832)
         && !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);
       }
     }
   }
@@ -339,8 +445,15 @@
    */
   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);
       }
@@ -349,8 +462,10 @@
       }
 
       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>';
@@ -361,16 +476,16 @@
           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.messagedialog.closest('div[role=dialog]').attr('role', 'alertdialog');
+
+      me.message_timer = window.setTimeout(dialog_close, p.timeout);
     }
   }
 
@@ -384,7 +499,7 @@
     $('#message-objects div a').addClass('button');
 
     if (!$('#attachment-list li').length) {
-      $('div.rightcol').hide();
+      $('div.rightcol').hide().attr('aria-hidden', 'true');
       $('div.leftcol').css('margin-right', '0');
     }
   }
@@ -401,6 +516,16 @@
     // 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()
   {
@@ -446,7 +571,7 @@
 
   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);
@@ -471,13 +596,21 @@
   /**
    * Trigger for popup menus
    */
-  function show_popup(popup, show, config)
+  function toggle_popup(popup, e, config)
+  {
+    show_popup(popup, undefined, config, rcube_event.is_keyboard(e));
+  }
+
+  /**
+   * (Deprecated) trigger for popup menus
+   */
+  function show_popup(popup, show, config, keyboard)
   {
     // auto-register menu object
     if (config || !popupconfig[popup])
       add_popup(popup, config);
 
-    var visible = show_popupmenu(popup, show),
+    var visible = show_popupmenu(popup, show, keyboard),
       config = popupconfig[popup];
     if (typeof config.callback == 'function')
       config.callback(visible);
@@ -486,7 +619,7 @@
   /**
    * Show/hide a specific popup menu
    */
-  function show_popupmenu(popup, show)
+  function show_popupmenu(popup, show, keyboard)
   {
     var obj = popups[popup],
       config = popupconfig[popup],
@@ -523,16 +656,74 @@
 
       obj.css({ left:pos.left, top:(pos.top + (above ? -obj.height() : ref.offsetHeight)) });
     }
+    else if (!show && keyboard && ref.length) {
+      ref.focus();
+    }
 
-    obj[show?'show':'hide']();
+    obj[show?'show':'hide']().attr('aria-hidden', show?'false':'true');
 
-    // hide drop-down elements on buggy browsers
-    if (bw.ie6 && config.overlap) {
-      $('select').css('visibility', show?'hidden':'inherit');
-      $('select', obj).css('visibility', 'inherit');
+    popup_keyboard_active = show && keyboard;
+    if (popup_keyboard_active) {
+      focused_popup = popup;
+      obj.find('a,input:not(:disabled)').not('[aria-disabled=true]').first().focus();
+    }
+    else {
+      focused_popup = null;
     }
 
     return show;
+  }
+
+  /** 
+   * Handler for keyboard events on active popups
+   */
+  function popup_keypress(e)
+  {
+    var target = e.target || {},
+      keyCode = rcube_event.get_keycode(e);
+
+    if (e.keyCode != 27 && (!popup_keyboard_active || target.nodeName == 'TEXTAREA' || target.nodeName == 'SELECT'))
+      return true;
+
+    switch (keyCode) {
+      case 38:
+      case 40:
+      case 63232: // "up", in safari keypress
+      case 63233: // "down", in safari keypress
+        popup_focus_item(mod = keyCode == 38 || keyCode == 63232 ? -1 : 1);
+        break;
+
+      case 9:   // tab
+        if (focused_popup) {
+          var mod = rcube_event.get_modifier(e);
+          if (!popup_focus_item(mod == SHIFT_KEY ? -1 : 1)) {
+            show_popup(focused_popup, false, undefined, true);
+          }
+        }
+        return rcube_event.cancel(e);
+
+      case 27:  // esc
+        for (var id in popups) {
+          if (popups[id].is(':visible'))
+            show_popup(id, false, undefined, true);
+        }
+        break;
+    }
+
+    return true;
+  }
+
+  /**
+   * Helper method to move focus to the next/prev popup menu item
+   */
+  function popup_focus_item(dir)
+  {
+    var obj, mod = dir < 0 ? 'prevAll' : 'nextAll', limit = dir < 0 ? 'last' : 'first';
+    if (focused_popup && (obj = popups[focused_popup])) {
+      return obj.find(':focus').closest('li')[mod](':has(:not([aria-disabled=true]))').find('a,input')[limit]().focus().length;
+    }
+
+    return 0;
   }
 
   /**
@@ -557,7 +748,7 @@
     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();
@@ -565,7 +756,7 @@
 
     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())
@@ -583,15 +774,18 @@
       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();
     }
 
-    if (visible && uid && rcmail.message_list)
-      rcmail.message_list.scrollto(uid);
+    if (rcmail.message_list) {
+      if (visible && uid)
+          rcmail.message_list.scrollto(uid);
+      rcmail.message_list.resize();
+    }
 
     rcmail.command('save-pref', { name:'preview_pane', value:(visible?1:0) });
   }
@@ -611,35 +805,31 @@
       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');
   }
 
 
   /**
    *
    */
-  function switch_view_mode(mode)
+  function switch_view_mode(mode, force)
   {
-    if (rcmail.env.threading != (mode == 'thread'))
-      rcmail.set_list_options(null, undefined, undefined, mode == 'thread' ? 1 : 0);
-
-    $('#maillistmode, #mailthreadmode').removeClass('selected');
-    $('#mail'+mode+'mode').addClass('selected');
+    if (force || !$('#mail'+mode+'mode').hasClass('disabled')) {
+      $('#maillistmode, #mailthreadmode').removeClass('selected').attr('tabindex', '0').attr('aria-disabled', 'false');
+      $('#mail'+mode+'mode').addClass('selected').attr('tabindex', '-1').attr('aria-disabled', 'true');
+    }
   }
 
 
   /**** popup callbacks ****/
 
-  function menu_open(p)
+  function menu_toggle(p)
   {
     if (p && p.props && p.props.menu == 'attachmentmenu')
-      show_popupmenu('attachmentmenu');
+      show_popupmenu('attachmentmenu', undefined, rcube_event.is_keyboard(p.originalEvent));
     else
-      show_listoptions();
-  }
-
-  function menu_save(prop)
-  {
-    save_listoptions();
+      show_listoptions(p);
   }
 
   function searchmenu(show)
@@ -649,11 +839,15 @@
         obj = popups['searchmenu'],
         list = $('input:checkbox[name="s_mods[]"]', obj),
         mbox = rcmail.env.mailbox,
-        mods = rcmail.env.search_mods;
+        mods = rcmail.env.search_mods,
+        scope = rcmail.env.search_scope || 'base';
 
       if (rcmail.env.task == 'mail') {
+        if (scope == 'all')
+          mbox = '*';
         mods = mods[mbox] ? mods[mbox] : mods['*'];
         all = 'text';
+        $('input:radio[name="s_scope"]').prop('checked', false).filter('#s_scope_'+scope).prop('checked', true);
       }
       else {
         all = '*';
@@ -672,7 +866,7 @@
     }
   }
 
-  function attachmentmenu(elem)
+  function attachmentmenu(elem, event)
   {
     var id = elem.parentNode.id.replace(/^attach/, '');
 
@@ -685,25 +879,29 @@
     });
 
     popupconfig.attachmentmenu.link = elem;
-    rcmail.command('menu-open', {menu: 'attachmentmenu', id: id});
+    rcmail.command('menu-open', {menu: 'attachmentmenu', id: id}, elem, event);
   }
 
   function spellmenu(show)
   {
-    var link, li,
+    var k, link, li,
       lang = rcmail.spellcheck_lang(),
       menu = popups.spellmenu,
       ul = $('ul', menu);
 
     if (!ul.length) {
-      ul = $('<ul class="toolbarmenu selectable">');
+      ul = $('<ul class="toolbarmenu selectable" role="menu">');
 
-      for (i in rcmail.env.spell_langs) {
-        li = $('<li>');
-        link = $('<a href="#"></a>').text(rcmail.env.spell_langs[i])
-          .addClass('active').data('lang', i)
-          .click(function() {
-            rcmail.spellcheck_lang_set($(this).data('lang'));
+      for (k in rcmail.env.spell_langs) {
+        li = $('<li role="menuitem">');
+        link = $('<a href="#'+k+'" tabindex="0"></a>').text(rcmail.env.spell_langs[k])
+          .addClass('active').data('lang', k)
+          .bind('click keypress', function(e) {
+              if (e.type != 'keypress' || rcube_event.get_keycode(e) == 13) {
+                  rcmail.spellcheck_lang_set($(this).data('lang'));
+                  show_popupmenu('spellmenu', false, rcube_event.is_keyboard(e))
+                  return false;
+              }
           });
 
         link.appendTo(li);
@@ -717,9 +915,9 @@
     $('li', ul).each(function() {
       var el = $('a', this);
       if (el.data('lang') == lang)
-        el.addClass('selected');
+        el.addClass('selected').attr('aria-selected', 'true');
       else if (el.hasClass('selected'))
-        el.removeClass('selected');
+        el.removeClass('selected').removeAttr('aria-selected');
     });
   }
 
@@ -727,13 +925,13 @@
   /**
    *
    */
-  function show_listoptions()
+  function show_listoptions(p)
   {
     var $dialog = $('#listoptions');
 
     // close the dialog
     if ($dialog.is(':visible')) {
-      $dialog.dialog('close');
+      $dialog.dialog('close', p.originalEvent);
       return;
     }
 
@@ -744,7 +942,7 @@
 
     // set checkboxes
     $('input[name="list_col[]"]').each(function() {
-      $(this).prop('checked', $.inArray(this.value, rcmail.env.coltypes) != -1);
+      $(this).prop('checked', $.inArray(this.value, rcmail.env.listcols) != -1);
     });
 
     $dialog.dialog({
@@ -752,8 +950,13 @@
       resizable: false,
       closeOnEscape: true,
       title: null,
-      close: function() {
+      open: function(e) {
+        setTimeout(function(){ $dialog.find('a, input:not(:disabled)').not('[aria-disabled=true]').first().focus(); }, 100);
+      },
+      close: function(e) {
         $dialog.dialog('destroy').hide();
+        if (e.originalEvent && rcube_event.is_keyboard(e.originalEvent))
+          $('#listmenulink').focus();
       },
       minWidth: 500,
       width: $dialog.width()+25
@@ -764,9 +967,12 @@
   /**
    *
    */
-  function save_listoptions()
+  function save_listoptions(p)
   {
     $('#listoptions').dialog('close');
+
+    if (rcube_event.is_keyboard(p.originalEvent))
+      $('#listmenulink').focus();
 
     var sort = $('input[name="sort_col"]:checked').val(),
       ord = $('input[name="sort_ord"]:checked').val(),
@@ -784,7 +990,11 @@
   {
     var all, m, task = rcmail.env.task,
       mods = rcmail.env.search_mods,
-      mbox = rcmail.env.mailbox;
+      mbox = rcmail.env.mailbox,
+      scope = $('input[name="s_scope"]:checked').val();
+
+    if (scope == 'all')
+      mbox = '*';
 
     if (!mods)
       mods = {};
@@ -806,23 +1016,29 @@
       m[elem.value] = 1;
 
     // mark all fields
-    if (elem.value != all)
-      return;
+    if (elem.value == all) {
+      $('input:checkbox[name="s_mods[]"]').map(function() {
+        if (this == elem)
+          return;
 
-    $('input:checkbox[name="s_mods[]"]').map(function() {
-      if (this == elem)
-        return;
+        this.checked = true;
+        if (elem.checked) {
+          this.disabled = true;
+          delete m[this.value];
+        }
+        else {
+          this.disabled = false;
+          m[this.value] = 1;
+        }
+      });
+    }
 
-      this.checked = true;
-      if (elem.checked) {
-        this.disabled = true;
-        delete m[this.value];
-      }
-      else {
-        this.disabled = false;
-        m[this.value] = 1;
-      }
-    });
+    rcmail.set_searchmods(m);
+  }
+
+  function set_searchscope(elem)
+  {
+    rcmail.set_searchscope(elem.value);
   }
 
   function push_contactgroup(p)
@@ -1098,6 +1314,7 @@
   {
     this.p1 = $(this.p.p1);
     this.p2 = $(this.p.p2);
+    this.parent = this.p1.parent();
 
     // check if referenced elements exist, otherwise abort
     if (!this.p1.length || !this.p2.length)
@@ -1110,7 +1327,7 @@
       .attr('id', this.id)
       .attr('unselectable', 'on')
       .addClass('splitter ' + (this.horizontal ? 'splitter-h' : 'splitter-v'))
-      .appendTo(this.p1.parent())
+      .appendTo(this.parent)
       .bind('mousedown', onDragStart);
 
     if (this.horizontal) {
@@ -1127,7 +1344,7 @@
       $(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();
@@ -1149,7 +1366,7 @@
       this.p2.css('top', Math.ceil(this.pos + this.halfsize + 2) + 'px');
       this.handle.css('top', Math.round(this.pos - this.halfsize + this.offset)+'px');
       if (bw.ie) {
-        var new_height = parseInt(this.p2.parent().outerHeight(), 10) - parseInt(this.p2.css('top'), 10) - (bw.ie8 ? 2 : 0);
+        var new_height = parseInt(this.parent.outerHeight(), 10) - parseInt(this.p2.css('top'), 10) - (bw.ie8 ? 2 : 0);
         this.p2.css('height', (new_height > 0 ? new_height : 0) + 'px');
       }
     }
@@ -1158,7 +1375,7 @@
       this.p2.css('left', Math.ceil(this.pos + this.halfsize) + 'px');
       this.handle.css('left', Math.round(this.pos - this.halfsize + this.offset + 3)+'px');
       if (bw.ie) {
-        var new_width = parseInt(this.p2.parent().outerWidth(), 10) - parseInt(this.p2.css('left'), 10) ;
+        var new_width = parseInt(this.parent.outerWidth(), 10) - parseInt(this.p2.css('left'), 10) ;
         this.p2.css('width', (new_width > 0 ? new_width : 0) + 'px');
       }
     }
@@ -1216,10 +1433,22 @@
     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) {
-      var parent = me.p1.parent().offset();
+      var parent = me.parent.offset();
       pos.x -= parent.left;
       pos.y -= parent.top;
     }
@@ -1227,19 +1456,24 @@
     if (me.horizontal) {
       if (((pos.y - me.halfsize) > me.p1pos.top) && ((pos.y + me.halfsize) < (me.p2pos.top + me.p2.outerHeight()))) {
         me.pos = Math.max(me.min, pos.y - me.offset);
+        if (me.pos > me.min)
+          me.pos = Math.min(me.pos, me.parent.height() - me.min);
+
         me.resize();
       }
     }
     else {
       if (((pos.x - me.halfsize) > me.p1pos.left) && ((pos.x + me.halfsize) < (me.p2pos.left + me.p2.outerWidth()))) {
         me.pos = Math.max(me.min, pos.x - me.offset);
+        if (me.pos > me.min)
+          me.pos = Math.min(me.pos, me.parent.width() - me.min);
+
         me.resize();
       }
     }
 
     me.p1pos = me.relative ? me.p1.position() : me.p1.offset();
     me.p2pos = me.relative ? me.p2.position() : me.p2.offset();
-    return false;
   };
 
   /**
@@ -1272,13 +1506,21 @@
   function onResize(e)
   {
     if (me.horizontal) {
-      var new_height = parseInt(me.p2.parent().outerHeight(), 10) - parseInt(me.p2[0].style.top, 10) - (bw.ie8 ? 2 : 0);
+      var new_height = parseInt(me.parent.outerHeight(), 10) - parseInt(me.p2[0].style.top, 10) - (bw.ie8 ? 2 : 0);
       me.p2.css('height', (new_height > 0 ? new_height : 0) +'px');
     }
     else {
-      var new_width = parseInt(me.p2.parent().outerWidth(), 10) - parseInt(me.p2[0].style.left, 10);
+      var new_width = parseInt(me.parent.outerWidth(), 10) - parseInt(me.p2[0].style.left, 10);
       me.p2.css('width', (new_width > 0 ? new_width : 0) + 'px');
     }
+  };
+
+  /**
+   * Get saved splitter position from cookie
+   */
+  this.get_cookie = function()
+  {
+    return window.UI ? UI.get_pref(this.id) : null;
   };
 
   /**
@@ -1286,9 +1528,8 @@
    */
   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
@@ -1301,3 +1542,5 @@
 {
   return rcube_splitter._instances[id];
 };
+
+// @license-end
\ No newline at end of file

--
Gitblit v1.9.1