1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-26 10:52:17 -05:00

[WO-409] show images only on user request

This commit is contained in:
Felix Hammerl 2014-06-25 17:20:55 +02:00
parent 7a896a66d1
commit 0d0b767b36
4 changed files with 60 additions and 7 deletions

View File

@ -338,14 +338,40 @@ define(function(require) {
ngModule.directive('frameLoad', function($sce, $timeout) {
return function(scope, elm, attrs) {
scope.$watch(attrs.frameLoad, function(value) {
var html = value;
scope.html = undefined;
if (value) {
$timeout(function() {
scope.html = true;
var iframe = elm[0];
iframe.contentWindow.postMessage(value, '*');
});
var iframe = elm[0];
if (!html) {
return;
}
// if there are image tags in the html?
var hasImages = /<img[^>]+\bsrc=['"][^'">]+['"]/ig.test(html);
scope.showImageButton = hasImages;
// inital loading
$timeout(function() {
scope.html = true;
iframe.contentWindow.postMessage({
html: html,
removeImages: hasImages // avoids doing unnecessary work on the html
}, '*');
});
// no need to add a scope function to reload the html if there are no images
if (!hasImages) {
return;
}
// reload WITH images
scope.displayImages = function() {
scope.showImageButton = false;
iframe.contentWindow.postMessage({
html: html,
removeImages: false
}, '*');
};
});
};
});

View File

@ -3,6 +3,18 @@
// set listener for event from main window
window.addEventListener('message', function(e) {
document.body.innerHTML = e.data.replace(/<a /g, '<a target="_blank" ');
var html = e.data.html;
// make links open in a new window
html = html.replace(/<a /g, '<a target="_blank" ');
// remove sources where necessary
if (e.data.removeImages) {
html = html.replace(/(<img[^>]+\b)src=['"][^'">]+['"]/ig, function(match, prefix) {
return prefix;
});
}
document.body.innerHTML = html;
}, false);
})();

View File

@ -114,6 +114,17 @@
}
}
.showImages {
flex-shrink: 0;
padding: 1em;
text-align: center;
a {
text-decoration: none;
color: $color-blue;
}
}
iframe {
flex-grow: 1;
margin-top: 1.75em;

View File

@ -53,6 +53,10 @@
</div><!--/.working-->
</div><!--/.working-wrapper-->
<div class="showImages" ng-show="html && showImageButton">
<a href='#' ng-click="displayImages(); $event.preventDefault()">Display images</a>
</div>
<!-- Render html body in sandboxed iframe -->
<iframe ng-show="html" sandbox="allow-popups allow-scripts" src="sandbox.html"
frame-load="state.mailList.selected.html">