Aleksander Machniak
2013-09-15 7f1218caeacb5c3085047e61b9e3cf8e82198045
program/js/app.js
@@ -178,11 +178,6 @@
      parent.rcmail.env.frame_lock = null;
    }
    // Makes that reference to document.activeElement do not throw
    // "unspecified error" in IE9 (#1489008)
    if (this.env.framed && bw.ie)
      document.documentElement.focus();
    // enable general commands
    this.enable_command('close', 'logout', 'mail', 'addressbook', 'settings', 'save-pref', 'compose', 'undo', 'about', 'switch-task', true);
@@ -317,7 +312,7 @@
        }
        // detect browser capabilities
        if (!this.is_framed())
        if (!this.is_framed() && !this.env.extwin)
          this.browser_capabilities_check();
        break;
@@ -393,7 +388,7 @@
        }
        else if (this.env.action == 'edit-folder' && this.gui_objects.editform) {
          this.enable_command('save', 'folder-size', true);
          parent.rcmail.env.messagecount = this.env.messagecount;
          parent.rcmail.env.exists = this.env.messagecount;
          parent.rcmail.enable_command('purge', this.env.messagecount);
          $("input[type='text']").first().select();
        }
@@ -588,11 +583,11 @@
          var prevstate = this.env.compose_extwin;
          $("input[name='_action']", this.gui_objects.messageform).val('compose');
          this.gui_objects.messageform.action = this.url('mail/compose', { _id: this.env.compose_id, _extwin: 1 });
          this.gui_objects.messageform.target = this.open_window('', 1100, 900);
          this.gui_objects.messageform.target = this.open_window('', 1100);
          this.gui_objects.messageform.submit();
        }
        else {
          this.open_window(this.env.permaurl, 900, 900);
          this.open_window(this.env.permaurl, 900);
        }
        break;
@@ -1557,7 +1552,7 @@
    // start timer for message preview (wait for double click)
    if (selected && this.env.contentframe && !list.multi_selecting && !this.dummy_select)
      this.preview_timer = setTimeout(function(){ ref.msglist_get_preview(); }, 200);
      this.preview_timer = setTimeout(function() { ref.msglist_get_preview(); }, this.dblclick_time);
    else if (this.env.contentframe)
      this.show_contentframe(false);
  };
@@ -1573,12 +1568,13 @@
    var win = this.get_frame_window(this.env.contentframe);
    if (win && win.location.href.indexOf(this.env.blankpage)>=0) {
    if (win && win.location.href.indexOf(this.env.blankpage) >= 0) {
      if (this.preview_timer)
        clearTimeout(this.preview_timer);
      if (this.preview_read_timer)
        clearTimeout(this.preview_read_timer);
      this.preview_timer = setTimeout(function(){ ref.msglist_get_preview(); }, 200);
      this.preview_timer = setTimeout(function() { ref.msglist_get_preview(); }, this.dblclick_time);
    }
  };
@@ -1586,11 +1582,11 @@
  {
    if (this.preview_timer)
      clearTimeout(this.preview_timer);
    if (this.preview_read_timer)
      clearTimeout(this.preview_read_timer);
    var uid = list.get_single_selection();
    if (uid && this.env.mailbox == this.env.drafts_mailbox)
      this.open_compose_step({ _draft_uid: uid, _mbox: this.env.mailbox });
    else if (uid)
@@ -1678,14 +1674,18 @@
    return 0;
  };
  this.open_window = function(url, width, height)
  this.open_window = function(url, width)
  {
    var w = Math.min(width, screen.width - 10),
      h = Math.min(height, screen.height - 100),
      l = (screen.width - w) / 2 + (screen.left || 0),
      t = Math.max(0, (screen.height - h) / 2 + (screen.top || 0) - 20),
    var win = this.is_framed() ? parent.window : window,
      page = $(win),
      page_width = page.width(),
      page_height = bw.mz ? $('body', win).height() : page.height(),
      w = Math.min(width, page_width),
      h = page_height, // always use same height
      l = (win.screenLeft || win.screenX) + 20,
      t = (win.screenTop || win.screenY) + 20,
      wname = 'rcmextwin' + new Date().getTime(),
      extwin = window.open(url + '&_extwin=1', wname,
      extwin = window.open(url + (url.match(/\?/) ? '&' : '?') + '_extwin=1', wname,
        'width='+w+',height='+h+',top='+t+',left='+l+',resizable=yes,toolbar=no,status=no,location=no');
    // write loading... message to empty windows
@@ -1695,8 +1695,6 @@
    // focus window, delayed to bring to front
    window.setTimeout(function() { extwin.focus(); }, 10);
    // position window with setTimeout for Chrome (#1488931)
    window.setTimeout(function() { extwin.moveTo(l,t); }, bw.chrome ? 100 : 10);
    return wname;
  };
@@ -1735,6 +1733,14 @@
    if (!row.depth && row.has_children && (expando = document.getElementById('rcmexpando'+row.uid))) {
      row.expando = expando;
      expando.onmousedown = function(e) { return self.expand_message_row(e, uid); };
      if (bw.touch) {
        expando.addEventListener('touchend', function(e) {
          if (e.changedTouches.length == 1) {
            self.expand_message_row(e, uid);
            return rcube_event.cancel(e);
          }
        }, false);
      }
    }
    this.triggerEvent('insertrow', { uid:uid, row:row });
@@ -1780,7 +1786,6 @@
        + (!flags.seen ? ' unread' : '')
        + (flags.deleted ? ' deleted' : '')
        + (flags.flagged ? ' flagged' : '')
        + (flags.unread_children && flags.seen && !this.env.autoexpand_threads ? ' unroot' : '')
        + (message.selected ? ' selected' : ''),
      // for performance use DOM instead of jQuery here
      row = document.createElement('tr');
@@ -1833,6 +1838,9 @@
        expando = '<div id="rcmexpando' + uid + '" class="' + (message.expanded ? 'expanded' : 'collapsed') + '">&nbsp;&nbsp;</div>';
        row_class += ' thread' + (message.expanded? ' expanded' : '');
      }
      if (flags.unread_children && flags.seen && !message.expanded)
        row_class += ' unroot';
    }
    tree += '<span id="msgicn'+uid+'" class="'+css_class+'">&nbsp;</span>';
@@ -1879,7 +1887,7 @@
        html = expando;
      else if (c == 'subject') {
        if (bw.ie) {
          col.onmouseover = function() { rcube_webmail.long_subject_title_ie(this, message.depth+1); };
          col.onmouseover = function() { rcube_webmail.long_subject_title_ex(this, message.depth+1); };
          if (bw.ie8)
            tree = '<span></span>' + tree; // #1487821
        }
@@ -1894,7 +1902,8 @@
      else
        html = cols[c];
      col.innerHTML = html;
      if (html)
        col.innerHTML = html;
      row.appendChild(col);
    }
@@ -1997,7 +2006,7 @@
    }
    else {
      if (!preview && this.env.message_extwin && !this.env.extwin)
        this.open_window(this.env.comm_path+url, 1000, 1200);
        this.open_window(this.env.comm_path+url, 1000);
      else
        this.location_href(this.env.comm_path+url, target, true);
@@ -3023,11 +3032,12 @@
    // open new compose window
    if (this.env.compose_extwin && !this.env.extwin) {
      this.open_window(url, 1150, 900);
      this.open_window(url, 1150);
    }
    else {
      this.redirect(url);
      window.resizeTo(Math.max(1150, $(window).width()), Math.max(900, $(window).height()));
      if (this.env.extwin)
        window.resizeTo(Math.max(1150, $(window).width()), $(window).height()+24);
    }
  };
@@ -3069,7 +3079,7 @@
      this.set_caret_pos(input_message, this.env.top_posting ? 0 : $(input_message).val().length);
      // add signature according to selected identity
      // if we have HTML editor, signature is added in callback
      if (input_from.prop('type') == 'select-one' && !this.env.opened_extwin) {
      if (input_from.prop('type') == 'select-one') {
        this.change_identity(input_from[0]);
      }
    }
@@ -3135,7 +3145,7 @@
  this.compose_add_recipient = function(field)
  {
    var recipients = [], input = $('#_'+field);
    var recipients = [], input = $('#_'+field), delim = this.env.recipients_delimiter;
    if (this.contact_list && this.contact_list.selection.length) {
      for (var id, n=0; n < this.contact_list.selection.length; n++) {
@@ -3154,8 +3164,10 @@
    }
    if (recipients.length && input.length) {
      var oldval = input.val();
      input.val((oldval ? oldval + this.env.recipients_delimiter : '') + recipients.join(this.env.recipients_delimiter));
      var oldval = input.val(), rx = new RegExp(RegExp.escape(delim) + '\\s*$');
      if (oldval && !rx.test(oldval))
        oldval += delim + ' ';
      input.val(oldval + recipients.join(delim + ' ') + delim + ' ');
      this.triggerEvent('add-recipient', { field:field, recipients:recipients });
    }
  };
@@ -3398,6 +3410,15 @@
    if (!show_sig)
      show_sig = this.env.show_sig;
    // first function execution
    if (!this.env.identities_initialized) {
      this.env.identities_initialized = true;
      if (this.env.show_sig_later)
        this.env.show_sig = true;
      if (this.env.opened_extwin)
        return;
    }
    var cursor_pos, p = -1,
      id = obj.options[obj.selectedIndex].value,
      input_message = $("[name='_message']"),
@@ -3583,7 +3604,12 @@
      att.html = '<a title="'+this.get_label('cancel')+'" onclick="return rcmail.cancel_attachment_upload(\''+name+'\', \''+att.frame+'\');" href="#cancelupload" class="cancelupload">'
        + (this.env.cancelicon ? '<img src="'+this.env.cancelicon+'" alt="" />' : this.get_label('cancel')) + '</a>' + att.html;
    var indicator, li = $('<li>').attr('id', name).addClass(att.classname).html(att.html);
    var indicator, li = $('<li>');
    li.attr('id', name)
      .addClass(att.classname)
      .html(att.html)
      .on('mouseover', function() { rcube_webmail.long_subject_title_ex(this, 0); });
    // replace indicator's li
    if (upload_id && (indicator = document.getElementById(upload_id))) {
@@ -4116,6 +4142,7 @@
    var n, id, sid, ref = this, writable = false,
      source = this.env.source ? this.env.address_sources[this.env.source] : null;
    // we don't have dblclick handler here, so use 200 instead of this.dblclick_time
    if (id = list.get_single_selection())
      this.preview_timer = setTimeout(function(){ ref.load_contact(id, 'show'); }, 200);
    else if (this.env.contentframe)
@@ -4415,7 +4442,8 @@
    for (c in cols) {
      col = document.createElement('td');
      col.className = String(c).toLowerCase();
      col.innerHTML = cols[c];
      if (cols[c])
        col.innerHTML = cols[c];
      row.appendChild(col);
    }
@@ -5861,14 +5889,14 @@
        for (c=0, len=repl.length; c < len; c++) {
          cell = document.createElement('td');
          cell.innerHTML = repl[c].html;
          cell.innerHTML = repl[c].html || '';
          if (repl[c].id) cell.id = repl[c].id;
          if (repl[c].className) cell.className = repl[c].className;
          tr.appendChild(cell);
        }
        th.appendChild(tr);
        thead.parentNode.replaceChild(th, thead);
        thead = th;
        list.thead = thead = th;
      }
      for (n=0, len=this.env.coltypes.length; n<len; n++) {
@@ -6489,9 +6517,10 @@
        url: ref.url(ref.env.filedrop.action||'upload', { _id:ref.env.compose_id||ref.env.cid||'', _uploadid:ts, _remote:1 }),
        contentType: formdata ? false : 'multipart/form-data; boundary=' + boundary,
        processData: false,
        timeout: 0, // disable default timeout set in ajaxSetup()
        data: formdata || multipart,
        headers: {'X-Roundcube-Request': ref.env.request_token},
        beforeSend: function(xhr, s) { if (!formdata && xhr.sendAsBinary) xhr.send = xhr.sendAsBinary; },
        xhr: function() { var xhr = jQuery.ajaxSettings.xhr(); if (!formdata && xhr.sendAsBinary) xhr.send = xhr.sendAsBinary; return xhr; },
        success: function(data){ ref.http_response(data); },
        error: function(o, status, err) { ref.http_error(o, status, err, null, 'attachment'); }
      });
@@ -6531,7 +6560,7 @@
            multipart += '; filename="' + (f.name_bin || file.name) + '"' + crlf;
            multipart += 'Content-Length: ' + file.size + crlf;
            multipart += 'Content-Type: ' + file.type + crlf + crlf;
            multipart += e.target.result + crlf;
            multipart += reader.result + crlf;
            multipart += dashdash + boundary + crlf;
            if (j == last)  // we're done, submit the data
@@ -6852,11 +6881,11 @@
  if (!elem.title) {
    var $elem = $(elem);
    if ($elem.width() + indent * 15 > $elem.parent().width())
      elem.title = $elem.html();
      elem.title = $elem.text();
  }
};
rcube_webmail.long_subject_title_ie = function(elem, indent)
rcube_webmail.long_subject_title_ex = function(elem, indent)
{
  if (!elem.title) {
    var $elem = $(elem),