From 82fcd4e7574e55326474e5edc5c9d6da56677331 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak <alec@alec.pl> Date: Tue, 22 Dec 2015 07:14:00 -0500 Subject: [PATCH] Fix so drag-n-drop of text (e.g. recipient addresses) on compose page actually works (#1490619) --- program/js/app.js | 90 ++++++++++++++++++++++++++------------------ 1 files changed, 53 insertions(+), 37 deletions(-) diff --git a/program/js/app.js b/program/js/app.js index 70a4850..ba7b711 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -141,8 +141,8 @@ var n, p = this; this.task = this.env.task; - // check browser - if (this.env.server_error != 409 && (!bw.dom || !bw.xmlhttp_test() || (bw.mz && bw.vendver < 1.9))) { + // check browser capabilities (never use version checks here) + if (this.env.server_error != 409 && (!bw.dom || !bw.xmlhttp_test())) { this.goto_url('error', '_code=0x199'); return; } @@ -983,12 +983,9 @@ url = {}; if (this.task == 'mail') { - url._mbox = this.env.mailbox; + url = {_mbox: this.env.mailbox, _search: this.env.search_request}; if (props) url._to = props; - // also send search request so we can go back to search result after message is sent - if (this.env.search_request) - url._search = this.env.search_request; } // modify url if we're in addressbook else if (this.task == 'addressbook') { @@ -1089,9 +1086,9 @@ case 'reply-list': case 'reply': if (uid = this.get_single_uid()) { - url = {_reply_uid: uid, _mbox: this.env.mailbox}; + url = {_reply_uid: uid, _mbox: this.env.mailbox, _search: this.env.search_request}; + // do reply-list, when list is detected and popup menu wasn't used if (command == 'reply-all') - // do reply-list, when list is detected and popup menu wasn't used url._all = (!props && this.env.reply_all_mode == 1 && this.commands['reply-list'] ? 'list' : 'all'); else if (command == 'reply-list') url._all = 'list'; @@ -1811,7 +1808,7 @@ // attach events $.each(fn, function(i, f) { row[i].onclick = function(e) { f(e); return rcube_event.cancel(e); }; - if (bw.touch) { + if (bw.touch && row[i].addEventListener) { row[i].addEventListener('touchend', function(e) { if (e.changedTouches.length == 1) { f(e); @@ -3669,14 +3666,13 @@ this.set_draft_id = function(id) { - var rc; - if (id && id != this.env.draft_id) { - if (rc = this.opener()) { - // refresh the drafts folder in opener window - if (rc.env.task == 'mail' && rc.env.action == '' && rc.env.mailbox == this.env.drafts_mailbox) - rc.command('checkmail'); - } + var filter = {task: 'mail', action: ''}, + rc = this.opener(false, filter) || this.opener(true, filter); + + // refresh the drafts folder in the opener window + if (rc && rc.env.mailbox == this.env.drafts_mailbox) + rc.command('checkmail'); this.env.draft_id = id; $("input[name='_draft_saveid']").val(id); @@ -7252,8 +7248,8 @@ // html5 file-drop API this.document_drag_hover = function(e, over) { - e.preventDefault(); - $(ref.gui_objects.filedrop)[(over?'addClass':'removeClass')]('active'); + // don't e.preventDefault() here to not block text dragging on the page (#1490619) + $(this.gui_objects.filedrop)[(over?'addClass':'removeClass')]('active'); }; this.file_drag_hover = function(e, over) @@ -7285,7 +7281,8 @@ var submit_data = function() { var multiple = files.length > 1, ts = new Date().getTime(), - content = '<span>' + (multiple ? ref.get_label('uploadingmany') : files[0].name) + '</span>'; + // jQuery way to escape filename (#1490530) + content = $('<span>').text(multiple ? ref.get_label('uploadingmany') : files[0].name).html(); // add to attachments list if (!ref.add2attachment_list(ts, { name:'', html:content, classname:'uploading', complete:false })) @@ -7457,12 +7454,24 @@ }; // get window.opener.rcmail if available - this.opener = function() + this.opener = function(deep, filter) { + var i, win = window.opener; + // catch Error: Permission denied to access property rcmail try { - if (window.opener && !opener.closed && opener.rcmail) - return opener.rcmail; + if (win && !win.closed) { + // try parent of the opener window, e.g. preview frame + if (deep && (!win.rcmail || win.rcmail.env.framed) && win.parent && win.parent.rcmail) + win = win.parent; + + if (win.rcmail && filter) + for (i in filter) + if (win.rcmail.env[i] != filter[i]) + return; + + return win.rcmail; + } } catch (e) {} }; @@ -7637,14 +7646,10 @@ 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.flash === undefined) - this.env.browser_capabilities.flash = this.flash_support_check(); - - if (this.env.browser_capabilities.tif === undefined) - this.tif_support_check(); + $.each(['pdf', 'flash', 'tif'], function() { + if (ref.env.browser_capabilities[this] === undefined) + ref.env.browser_capabilities[this] = ref[this + '_support_check'](); + }); }; // Returns browser capabilities string @@ -7663,16 +7668,19 @@ this.tif_support_check = function() { - var img = new Image(); + window.setTimeout(function() { + var img = new Image(); + img.onload = function() { ref.env.browser_capabilities.tif = 1; }; + img.onerror = function() { ref.env.browser_capabilities.tif = 0; }; + img.src = 'program/resources/blank.tif'; + }, 10); - img.onload = function() { rcmail.env.browser_capabilities.tif = 1; }; - img.onerror = function() { rcmail.env.browser_capabilities.tif = 0; }; - img.src = 'program/resources/blank.tif'; + return 0; }; this.pdf_support_check = function() { - var plugin = navigator.mimeTypes ? navigator.mimeTypes["application/pdf"] : {}, + var i, plugin = navigator.mimeTypes ? navigator.mimeTypes["application/pdf"] : {}, plugins = navigator.plugins, len = plugins.length, regex = /Adobe Reader|PDF|Acrobat/i; @@ -7680,7 +7688,7 @@ if (plugin && plugin.enabledPlugin) return 1; - if (window.ActiveXObject) { + if ('ActiveXObject' in window) { try { if (axObj = new ActiveXObject("AcroPDF.PDF")) return 1; @@ -7703,6 +7711,14 @@ return 1; } + window.setTimeout(function() { + $('<object>').css({position: 'absolute', left: '-10000px'}) + .attr({data: 'program/resources/dummy.pdf', width: 1, height: 1, type: 'application/pdf'}) + .load(function() { ref.env.browser_capabilities.pdf = 1; }) + .error(function() { ref.env.browser_capabilities.pdf = 0; }) + .appendTo($('body')); + }, 10); + return 0; }; @@ -7713,7 +7729,7 @@ if (plugin && plugin.enabledPlugin) return 1; - if (window.ActiveXObject) { + if ('ActiveXObject' in window) { try { if (axObj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) return 1; -- Gitblit v1.9.1