Thomas Bruederli
2014-04-30 e8bcf08c72a18b3bf396e6448d6658227ecb46f2
skins/larry/ui.js
@@ -1,3 +1,5 @@
// @license http://creativecommons.org/publicdomain/zero/1.0/legalcode CC0
/**
 * Roundcube functions for default skin interface
 *
@@ -8,7 +10,6 @@
 * by keeping credits to the original autors in the README file.
 * See http://creativecommons.org/licenses/by-sa/3.0/ for details.
 */
function rcube_mail_ui()
{
@@ -32,6 +33,8 @@
  var mailviewsplit;
  var compose_headers = {};
  var prefs;
  var focused_popup;
  var popup_keyboard_active = false;
  // export public methods
  this.set = setenv;
@@ -39,8 +42,10 @@
  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;
@@ -138,7 +143,8 @@
    if (rcmail.env.task == 'mail') {
      rcmail.addEventListener('menu-open', menu_open)
        .addEventListener('menu-save', menu_save)
        .addEventListener('responseafterlist', function(e){ switch_view_mode(rcmail.env.threading ? 'thread' : 'list') });
        .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) {
@@ -253,6 +259,10 @@
        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();
@@ -326,6 +336,10 @@
          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
@@ -336,14 +350,7 @@
    $(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
@@ -378,6 +385,7 @@
      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)))
@@ -578,13 +586,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);
@@ -593,7 +609,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],
@@ -630,16 +646,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']();
    // 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('[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;
  }
  /**
@@ -729,13 +803,12 @@
  /**
   *
   */
  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');
    }
  }
@@ -761,11 +834,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 = '*';
@@ -856,7 +933,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({
@@ -896,7 +973,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 = {};
@@ -918,23 +999,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)
@@ -1438,3 +1525,5 @@
{
  return rcube_splitter._instances[id];
};
// @license-end