From 8ed954838bc342f7add41fdb0e47e8fed52a5f2f Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Sat, 23 Jul 2016 08:35:37 +0200 Subject: [PATCH] Fix javascript errors in IE on page with iframe that points to another domain --- CHANGELOG | 1 + program/js/app.js | 27 ++++++++++++++++++++------- skins/classic/functions.js | 17 +---------------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 3db6289d2..2242c674f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -28,6 +28,7 @@ CHANGELOG Roundcube Webmail - Fix handling of 'mailto' and 'error' arguments in message_before_send hook (#5347) - Fix missing localization of HTML editor when assets_dir != INSTALL_PATH - Fix handling of blockquote tags with mixed case on html2text conversion (#5363) +- Fix javascript errors in IE on page with iframe that points to another domain RELEASE 1.2.0 ------------- diff --git a/program/js/app.js b/program/js/app.js index 71246d12b..aab0cc38c 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -612,16 +612,12 @@ function rcube_webmail() } // catch document (and iframe) mouse clicks - var body_mouseup = function(e){ return ref.doc_mouse_up(e); }; + var body_mouseup = function(e) { return ref.doc_mouse_up(e); }; $(document.body) .mouseup(body_mouseup) - .keydown(function(e){ return ref.doc_keypress(e); }); + .keydown(function(e) { return ref.doc_keypress(e); }); - $('iframe').on('load', function(e) { - try { $(this.contentDocument || this.contentWindow).on('mouseup', body_mouseup); } - catch (e) {/* catch possible "Permission denied" error in IE */ } - }) - .contents().on('mouseup', body_mouseup); + rcube_webmail.set_iframe_events({mouseup: body_mouseup}); // trigger init event hook this.triggerEvent('init', { task:this.task, action:this.env.action }); @@ -8981,6 +8977,23 @@ rcube_webmail.subject_text = function(elem) return t.text(); }; +// set event handlers on all iframe elements (and their contents) +rcube_webmail.set_iframe_events = function(events) +{ + $('iframe').each(function() { + var frame = $(this); + $.each(events, function(event_name, event_handler) { + frame.on('load', function(e) { + try { $(this).contents().on(event_name, event_handler); } + catch (e) {/* catch possible permission error in IE */ } + }); + + try { frame.contents().on(event_name, event_handler); } + catch (e) {/* catch possible permission error in IE */ } + }); + }); +}; + rcube_webmail.prototype.get_cookie = getCookie; // copy event engine prototype diff --git a/skins/classic/functions.js b/skins/classic/functions.js index 5a55c9510..afe46c938 100644 --- a/skins/classic/functions.js +++ b/skins/classic/functions.js @@ -827,20 +827,6 @@ function rcmail_scroller(list, top, bottom) }; }; - -// Events handling in iframes (eg. preview pane) -function iframe_events() -{ - // this==iframe - try { - var doc = this.contentDocument ? this.contentDocument : this.contentWindow ? this.contentWindow.document : null; - $(doc).mouseup(function(e) { rcmail_ui.body_mouseup(e); }); - } - catch (e) { - // catch possible "Permission denied" error in IE - }; -}; - // Abbreviate mailbox names to fit width of the container function rcube_render_mailboxlist() { @@ -1015,8 +1001,7 @@ function rcube_init_mail_ui() update_quota(rcmail.env.quota_content); rcmail.addEventListener('setquota', update_quota); - $('iframe').on('load', iframe_events) - .contents().mouseup(function(e) { rcmail_ui.body_mouseup(e); }); + rcube_webmail.set_iframe_events({mouseup: function(e) { return rcmail_ui.body_mouseup(e); }}); if (rcmail.env.task == 'mail') { rcmail.addEventListener('enable-command', 'enable_command', rcmail_ui)