Roundcube Community Forum

News and Announcements => General Discussion => Topic started by: plp13 on January 10, 2015, 04:28:13 AM

Title: message attachments preview
Post by: plp13 on January 10, 2015, 04:28:13 AM
Hi,

I just did a few changes to the attachments preview feature, and I'm wondering if anyone thinks they're useful.

1. Browser PDF capability detection is broken for recent versions of Firefox. While recent versions of this browser have a built-in PDF viewer, Roundcube does not think so. The same goes for IE11 due to window.ActiveXObject returning 'undefined' (see here (http://msdn.microsoft.com/en-us/library/ie/dn423948%28v=vs.85%29.aspx)). I fixed these issues by modifying this.pdf_support_check in program/app.js:


this.pdf_support_check = function()
  {
    var plugin = navigator.mimeTypes ? navigator.mimeTypes["application/pdf"] : {},
      ff_index,
      ff_version,
      plugins = navigator.plugins,
      len = plugins.length,
      regex = /Adobe Reader|PDF|Acrobat/i;

    // plp: also return true if running Firefox > 30
    ff_index = navigator.userAgent.indexOf('Firefox');
    if (ff_index > 0)
    {
        ff_version = parseFloat(navigator.userAgent.substring(ff_index + 8));
        if (ff_version == NaN)
            ff_version = -1;
        if (ff_version > 30)
            return 1;
    }

    if (plugin && plugin.enabledPlugin)
        return 1;

    // plp: also, remove an if statement here, to make detection compatible with IE 11
    try {
      if (axObj = new ActiveXObject("AcroPDF.PDF"))
        return 1;
    }
    catch (e) {}
    try {
      if (axObj = new ActiveXObject("PDF.PdfCtrl"))
        return 1;
    }
    catch (e) {}

    for (i=0; i<len; i++) {
      plugin = plugins[i];
      if (typeof plugin === 'String') {
        if (regex.test(plugin))
          return 1;
      }
      else if (plugin.name && regex.test(plugin.name))
        return 1;
    }

    return 0;
  };


2. I added a 'close' button to the preview window, by inserting the following at line 19 of skins/classic/templates/messagepart.html:


    <roundcube:if condition="env:extwin" />
        <roundcube:button command="close" type="link" class="button back" classAct="button back" classSel="button backSel" title="close" content=" " />
    <roundcube:else />
        <roundcube:button command="list" type="link" class="button back" classAct="button back" classSel="button backSel" title="backtolist" content=" " />
    <roundcube:endif />