From e349a8c9ae4adfc1aab48a5461902242930da7bf Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 28 May 2012 14:17:57 +0200 Subject: Added browser capabilities detection, i.e. PDF and TIFF support --- program/js/app.js | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 2 deletions(-) (limited to 'program/js') diff --git a/program/js/app.js b/program/js/app.js index c4bf5ec31..32ab69f2e 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -307,6 +307,10 @@ function rcube_webmail() this.http_post(postact, postdata); } + // detect browser capabilities + if (!this.is_framed()) + this.browser_capabilities_check(); + break; case 'addressbook': @@ -1943,13 +1947,16 @@ function rcube_webmail() if (this.env.search_request) url += '&_search='+this.env.search_request; - if (action == 'preview' && String(target.location.href).indexOf(url) >= 0) + // add browser capabilities, so we can properly handle attachments + url += '&_caps='+urlencode(this.browser_capabilities()); + + if (preview && String(target.location.href).indexOf(url) >= 0) this.show_contentframe(true); else { this.location_href(this.env.comm_path+url, target, true); // mark as read and change mbox unread counter - if (action == 'preview' && this.message_list && this.message_list.rows[id] && this.message_list.rows[id].unread && this.env.preview_pane_mark_read >= 0) { + if (preview && this.message_list && this.message_list.rows[id] && this.message_list.rows[id].unread && this.env.preview_pane_mark_read >= 0) { this.preview_read_timer = setTimeout(function() { ref.set_message(id, 'unread', false); ref.update_thread_root(id, 'read'); @@ -6368,6 +6375,78 @@ function rcube_webmail() $(elem).click(function() { rcmail.register_protocol_handler(name); return false; }); }; + // Checks browser capabilities eg. PDF support, TIF support + this.browser_capabilities_check = function() + { + if (!this.env.browser_capabilities) + this.env.browser_capabilities = {}; + + if (this.env.browser_capabilities.pdf === undefined) + this.env.browser_capabilities.pdf = this.pdf_support_check(); + + if (this.env.browser_capabilities.tif === undefined) + this.tif_support_check(); + }; + + // Returns browser capabilities string + this.browser_capabilities = function() + { + if (!this.env.browser_capabilities) + return ''; + + var n, ret = []; + + for (n in this.env.browser_capabilities) + ret.push(n + '=' + this.env.browser_capabilities[n]); + + return ret.join(); + }; + + this.tif_support_check = function() + { + var img = new Image(); + + img.onload = function() { rcmail.env.browser_capabilities.tif = 1; }; + img.onerror = function() { rcmail.env.browser_capabilities.tif = 0; }; + img.src = 'program/blank.tif'; + }; + + this.pdf_support_check = function() + { + var plugin = navigator.mimeTypes ? navigator.mimeTypes["application/pdf"] : {}, + plugins = navigator.plugins, + len = plugins.length, + regex = /Adobe Reader|PDF|Acrobat/i; + + if (plugin && plugin.enabledPlugin) + return 1; + + if (window.ActiveXObject) { + 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 Date: Mon, 28 May 2012 15:19:43 +0200 Subject: Add Flash support detection --- CHANGELOG | 2 +- program/js/app.js | 21 +++++++++++++++++++++ program/steps/mail/show.inc | 3 +++ 3 files changed, 25 insertions(+), 1 deletion(-) (limited to 'program/js') diff --git a/CHANGELOG b/CHANGELOG index 365667592..b125dbebb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,7 @@ CHANGELOG Roundcube Webmail =========================== -- Don't display PDF and TIFF attachments inline without browser support (#1488452, #1487929) +- Don't display Pdf/Tiff/Flash attachments inline without browser support (#1488452, #1487929) - Fix html2text conversion of strong|b|a|th|h tags when used in upper case - Add listcontrols template container in Larry skin (#1488498) - Fix host autoselection when default_host is an array (#1488495) diff --git a/program/js/app.js b/program/js/app.js index 32ab69f2e..e487a6052 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -6384,6 +6384,9 @@ function rcube_webmail() if (this.env.browser_capabilities.pdf === undefined) this.env.browser_capabilities.pdf = this.pdf_support_check(); + if (this.env.browser_capabilities.flash === undefined) + this.env.browser_capabilities.flash = this.flash_support_check(); + if (this.env.browser_capabilities.tif === undefined) this.tif_support_check(); }; @@ -6447,6 +6450,24 @@ function rcube_webmail() return 0; }; + this.flash_support_check = function() + { + var plugin = navigator.mimeTypes ? navigator.mimeTypes["application/x-shockwave-flash"] : {}; + + if (plugin && plugin.enabledPlugin) + return 1; + + if (window.ActiveXObject) { + try { + if (axObj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) + return 1; + } + catch (e) {} + } + + return 0; + }; + } // end object rcube_webmail diff --git a/program/steps/mail/show.inc b/program/steps/mail/show.inc index bf1757699..7fcfafcaa 100644 --- a/program/steps/mail/show.inc +++ b/program/steps/mail/show.inc @@ -69,6 +69,9 @@ if ($uid = get_input_value('_uid', RCUBE_INPUT_GET)) { if (empty($_SESSION['browser_caps']['pdf']) && ($key = array_search('application/pdf', $mimetypes)) !== false) { unset($mimetypes[$key]); } + if (empty($_SESSION['browser_caps']['flash']) && ($key = array_search('application/x-shockwave-flash', $mimetypes)) !== false) { + unset($mimetypes[$key]); + } // @TODO: we could convert TIFF to JPEG and display it if (empty($_SESSION['browser_caps']['tif']) && ($key = array_search('image/tiff', $mimetypes)) !== false) { unset($mimetypes[$key]); -- cgit v1.2.3 From 528c78a6dae632df624fb74909185dc3858c61d4 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Wed, 30 May 2012 12:51:26 +0200 Subject: Code cleanup, more object-like syntax when building URLs --- program/js/app.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'program/js') diff --git a/program/js/app.js b/program/js/app.js index e487a6052..49d7b5ff8 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -631,7 +631,7 @@ function rcube_webmail() uid = this.get_single_uid(); if (uid && (!this.env.uid || uid != this.env.uid)) { if (this.env.mailbox == this.env.drafts_mailbox) - this.goto_url('compose', '_draft_uid='+uid+'&_mbox='+urlencode(this.env.mailbox), true); + this.goto_url('compose', { _draft_uid: uid, _mbox: this.env.mailbox }, true); else this.show_message(uid); } @@ -653,13 +653,14 @@ function rcube_webmail() break; case 'edit': - if (this.task=='addressbook' && (cid = this.get_single_cid())) + if (this.task == 'addressbook' && (cid = this.get_single_cid())) this.load_contact(cid, 'edit'); - else if (this.task=='settings' && props) + else if (this.task == 'settings' && props) this.load_identity(props, 'edit-identity'); - else if (this.task=='mail' && (cid = this.get_single_uid())) { - url = (this.env.mailbox == this.env.drafts_mailbox) ? '_draft_uid=' : '_uid='; - this.goto_url('compose', url+cid+'&_mbox='+urlencode(this.env.mailbox), true); + else if (this.task == 'mail' && (cid = this.get_single_uid())) { + url = { _mbox: this.env.mailbox }; + url[this.env.mailbox == this.env.drafts_mailbox ? '_draft_uid' : '_uid'] = cid; + this.goto_url('compose', url, true); } break; @@ -984,12 +985,12 @@ function rcube_webmail() case 'reply-list': case 'reply': if (uid = this.get_single_uid()) { - url = '_reply_uid='+uid+'&_mbox='+urlencode(this.env.mailbox); + url = {_reply_uid: uid, _mbox: this.env.mailbox}; if (command == 'reply-all') // do reply-list, when list is detected and popup menu wasn't used - url += '&_all=' + (!props && this.commands['reply-list'] ? 'list' : 'all'); + url._all = (!props && this.commands['reply-list'] ? 'list' : 'all'); else if (command == 'reply-list') - url += '&_all=list'; + url._all = list; this.goto_url('compose', url, true); } @@ -998,9 +999,9 @@ function rcube_webmail() case 'forward-attachment': case 'forward': if (uid = this.get_single_uid()) { - url = '_forward_uid='+uid+'&_mbox='+urlencode(this.env.mailbox); + url = { _forward_uid: uid, _mbox: this.env.mailbox }; if (command == 'forward-attachment' || (!props && this.env.forward_attachment)) - url += '&_attachment=1'; + url._attachment = 1; this.goto_url('compose', url, true); } break; @@ -1026,7 +1027,7 @@ function rcube_webmail() case 'download': if (uid = this.get_single_uid()) - this.goto_url('viewsource', '&_uid='+uid+'&_mbox='+urlencode(this.env.mailbox)+'&_save=1'); + this.goto_url('viewsource', { _uid: uid, _mbox: this.env.mailbox, _save: 1 }); break; // quicksearch @@ -1079,7 +1080,7 @@ function rcube_webmail() case 'export': if (this.contact_list.rowcount > 0) { - this.goto_url('export', { _source:this.env.source, _gid:this.env.group, _search:this.env.search_request }); + this.goto_url('export', { _source: this.env.source, _gid: this.env.group, _search: this.env.search_request }); } break; @@ -1580,7 +1581,7 @@ function rcube_webmail() var uid = list.get_single_selection(); if (uid && this.env.mailbox == this.env.drafts_mailbox) - this.goto_url('compose', '_draft_uid='+uid+'&_mbox='+urlencode(this.env.mailbox), true); + this.goto_url('compose', { _draft_uid: uid, _mbox: this.env.mailbox }, true); else if (uid) this.show_message(uid, false, false); }; @@ -4925,7 +4926,7 @@ function rcube_webmail() // submit request with appended token if (confirm(this.get_label('deleteidentityconfirm'))) - this.goto_url('delete-identity', '_iid='+id+'&_token='+this.env.request_token, true); + this.goto_url('delete-identity', { _iid: id, _token: this.env.request_token }, true); return true; }; -- cgit v1.2.3 From a71039df755e980f8ff1b32ea367250a0e74521a Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Wed, 30 May 2012 13:03:11 +0200 Subject: Fix regression where redundant autocompletion requests were sent in case when new search value contains old one and previous search was not finished or its result was empty --- program/js/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'program/js') diff --git a/program/js/app.js b/program/js/app.js index 49d7b5ff8..9d6f7e808 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -3804,7 +3804,7 @@ function rcube_webmail() return; // ...new search value contains old one and previous search was not finished or its result was empty - if (old_value && old_value.length && q.indexOf(old_value) == 0 && (!ac || !ac.num) && this.env.contacts && !this.env.contacts.length) + if (old_value && old_value.length && q.indexOf(old_value) == 0 && (!ac || ac.num <= 0) && this.env.contacts && !this.env.contacts.length) return; var i, lock, source, xhr, reqid = new Date().getTime(), -- cgit v1.2.3