fixing the preview link issue with https

This commit is contained in:
Amine Ben hammou
2018-02-13 09:56:46 +00:00
parent 3721694f4d
commit 9acef55352
2 changed files with 17 additions and 3 deletions

View File

@@ -92,7 +92,8 @@ define(
}, },
saveTemplate: function (response, done) { saveTemplate: function (response, done) {
const iframe = document.createElement('iframe'); const iframe = document.createElement('iframe');
iframe.src = response.meta.preview_url; const protocol = location.href.startsWith('https://') ? 'https' : 'http';
iframe.src = protocol + response.meta.preview_url.replace(/^https?/, '');
iframe.onload = () => { iframe.onload = () => {
html2canvas(iframe.contentDocument.documentElement).then((thumbnail) => { html2canvas(iframe.contentDocument.documentElement).then((thumbnail) => {
document.body.removeChild(iframe); document.body.removeChild(iframe);
@@ -111,9 +112,20 @@ define(
}).then(done).fail(this.showError); }).then(done).fail(this.showError);
}); });
}; };
const onError = () => {
document.body.removeChild(iframe);
MailPoet.Notice.error([MailPoet.I18n.t('errorWhileTakingScreenshot')], { scroll: true });
done();
};
iframe.onerror = onError;
iframe.onError = onError;
// just to hide the iframe // just to hide the iframe
iframe.className ='mailpoet_template_iframe'; iframe.className ='mailpoet_template_iframe';
try {
document.body.appendChild(iframe); document.body.appendChild(iframe);
} catch (err) {
onError();
}
}, },
handleSend: function (e) { handleSend: function (e) {
e.preventDefault(); e.preventDefault();

View File

@@ -270,7 +270,9 @@
'savedTemplates': __('Your saved templates'), 'savedTemplates': __('Your saved templates'),
'blank': _x('Blank', 'Blank newsletters templates category'), 'blank': _x('Blank', 'Blank newsletters templates category'),
'sample': _x('Sample', 'Sample newsletters templates category'), 'sample': _x('Sample', 'Sample newsletters templates category'),
'noTemplates': __('This category does not contain any template yet!') 'noTemplates': __('This category does not contain any template yet!'),
'errorWhileTakingScreenshot': __('An error occured while saving the template on "Recently sent"')
}) %> }) %>
<% endblock %> <% endblock %>