From b512200aef602afba340321a2ae89fa9293dde73 Mon Sep 17 00:00:00 2001 From: Caio Carrara Date: Tue, 29 Mar 2016 18:09:03 -0300 Subject: Issue #622 - hide reply buttons It changes the trigger of event which show the reply container to after the iframe received the message with email body. --- web-ui/app/js/mixins/with_mail_sandbox.js | 78 +++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 web-ui/app/js/mixins/with_mail_sandbox.js (limited to 'web-ui/app/js/mixins') diff --git a/web-ui/app/js/mixins/with_mail_sandbox.js b/web-ui/app/js/mixins/with_mail_sandbox.js new file mode 100644 index 00000000..a156e691 --- /dev/null +++ b/web-ui/app/js/mixins/with_mail_sandbox.js @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2014 ThoughtWorks, Inc. + * + * Pixelated is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Pixelated is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Pixelated. If not, see . + */ +define( + ['helpers/view_helper', 'page/events'], + function(viewHelpers, events) { + 'use strict'; + + function withMailSandbox() { + this.showMailOnSandbox = function(mail) { + var that = this; + var $iframe = $("#read-sandbox"); + var iframe = $iframe[0]; + var content = viewHelpers.formatMailBody(mail); + + window.addEventListener('message', function(e) { + if (e.origin === 'null' && e.source === iframe.contentWindow) { + that.trigger(document, events.ui.replyBox.showReplyContainer); + that.trigger(document, events.search.highlightResults, {where: '.mail-read-view__header'}); + } + }); + + iframe.onload = function() { + // use iframe-resizer to dynamically adapt iframe size to its content + var config = { + resizedCallback: scaleToFit, + checkOrigin: false + }; + $iframe.iFrameResize(config); + + // transform scale iframe to fit container width + // necessary if iframe is wider than container + function scaleToFit() { + var parentWidth = $iframe.parent().width(); + var w = $iframe.width(); + var scale = 'none'; + + // only scale html mails + if (mail && mail.htmlBody && (w > parentWidth)) { + scale = parentWidth / w; + scale = 'scale(' + scale + ',' + scale + ')'; + } + + $iframe.css({ + '-webkit-transform-origin': '0 0', + '-moz-transform-origin': '0 0', + '-ms-transform-origin': '0 0', + 'transform-origin': '0 0', + '-webkit-transform': scale, + '-moz-transform': scale, + '-ms-transform': scale, + 'transform': scale + }); + } + + iframe.contentWindow.postMessage({ + html: content + }, '*'); + }; + }; + }; + + return withMailSandbox; + } +); -- cgit v1.2.3 From d739b867e6bb62a002882efc8c6e80aa37f30237 Mon Sep 17 00:00:00 2001 From: Felix Hammerl Date: Wed, 30 Mar 2016 17:41:15 +0200 Subject: Fix linter error --- web-ui/app/js/mixins/with_mail_sandbox.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web-ui/app/js/mixins') diff --git a/web-ui/app/js/mixins/with_mail_sandbox.js b/web-ui/app/js/mixins/with_mail_sandbox.js index a156e691..c292cb70 100644 --- a/web-ui/app/js/mixins/with_mail_sandbox.js +++ b/web-ui/app/js/mixins/with_mail_sandbox.js @@ -71,7 +71,7 @@ define( }, '*'); }; }; - }; + } return withMailSandbox; } -- cgit v1.2.3 From f41cea02299dc41dcc1f934d57430b564cf708ef Mon Sep 17 00:00:00 2001 From: Felix Hammerl Date: Fri, 1 Apr 2016 14:51:27 +0200 Subject: Run event test async with source passed to iframe via Blob URI --- web-ui/app/js/mixins/with_mail_sandbox.js | 58 ++++++++++++++++--------------- 1 file changed, 30 insertions(+), 28 deletions(-) (limited to 'web-ui/app/js/mixins') diff --git a/web-ui/app/js/mixins/with_mail_sandbox.js b/web-ui/app/js/mixins/with_mail_sandbox.js index c292cb70..1a51840d 100644 --- a/web-ui/app/js/mixins/with_mail_sandbox.js +++ b/web-ui/app/js/mixins/with_mail_sandbox.js @@ -34,41 +34,43 @@ define( }); iframe.onload = function() { - // use iframe-resizer to dynamically adapt iframe size to its content - var config = { - resizedCallback: scaleToFit, - checkOrigin: false - }; - $iframe.iFrameResize(config); + if ($iframe.iFrameResize) { + // use iframe-resizer to dynamically adapt iframe size to its content + var config = { + resizedCallback: scaleToFit, + checkOrigin: false + }; + $iframe.iFrameResize(config); + } + + iframe.contentWindow.postMessage({ + html: content + }, '*'); // transform scale iframe to fit container width // necessary if iframe is wider than container function scaleToFit() { - var parentWidth = $iframe.parent().width(); - var w = $iframe.width(); - var scale = 'none'; + var parentWidth = $iframe.parent().width(); + var w = $iframe.width(); + var scale = 'none'; - // only scale html mails - if (mail && mail.htmlBody && (w > parentWidth)) { - scale = parentWidth / w; - scale = 'scale(' + scale + ',' + scale + ')'; - } + // only scale html mails + if (mail && mail.htmlBody && (w > parentWidth)) { + scale = parentWidth / w; + scale = 'scale(' + scale + ',' + scale + ')'; + } - $iframe.css({ - '-webkit-transform-origin': '0 0', - '-moz-transform-origin': '0 0', - '-ms-transform-origin': '0 0', - 'transform-origin': '0 0', - '-webkit-transform': scale, - '-moz-transform': scale, - '-ms-transform': scale, - 'transform': scale - }); + $iframe.css({ + '-webkit-transform-origin': '0 0', + '-moz-transform-origin': '0 0', + '-ms-transform-origin': '0 0', + 'transform-origin': '0 0', + '-webkit-transform': scale, + '-moz-transform': scale, + '-ms-transform': scale, + 'transform': scale + }); } - - iframe.contentWindow.postMessage({ - html: content - }, '*'); }; }; } -- cgit v1.2.3